in logger/common.go [416:449]
func startTracingLogRouting(containerID string, stop chan bool) {
ticker := time.NewTicker(traceLogRoutingInterval)
debug.SendEventsToLog(containerID, "Starting the ticker...", debug.DEBUG, 0)
for {
select {
case <-ticker.C:
// The ticker is running as a separate goroutine which has read and write operations to
// `bytesReadFromSrc/bytesSentToDst`. And the shim logger process has another write operation to the same
// var. To avoid race conditions between these two, we should use atomic variables.
previousBytesReadFromSrc := atomic.SwapUint64(&bytesReadFromSrc, 0)
previousBytesSentToDst := atomic.SwapUint64(&bytesSentToDst, 0)
previousNumberOfNewLineChars := atomic.SwapUint64(&numberOfNewLineChars, 0)
debug.SendEventsToLog(
containerID,
fmt.Sprintf("Within last minute, reading %d bytes from the source. "+
"And %d bytes are sent to the destination and %d new line characters are ignored.",
previousBytesReadFromSrc, previousBytesSentToDst, previousNumberOfNewLineChars),
debug.DEBUG,
0)
case <-stop:
debug.SendEventsToLog(containerID,
fmt.Sprintf("Reading %d bytes from the source. "+
"And %d bytes are sent to the destination and %d new line characters are ignored.",
atomic.LoadUint64(&bytesReadFromSrc),
atomic.LoadUint64(&bytesSentToDst),
atomic.LoadUint64(&numberOfNewLineChars),
),
debug.DEBUG, 0)
ticker.Stop()
debug.SendEventsToLog(containerID, "Stopped the ticker...", debug.DEBUG, 0)
return
}
}
}