Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion logging/telemetryhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func createAsyncHookLevels(wrappedHook logrus.Hook, channelDepth uint, maxQueueD
if entry != nil {
err := hook.wrappedHook.Fire(entry)
if err != nil {
Base().Warnf("Unable to write event %#v to telemetry : %v", entry, err)
Base().WithFields(Fields{"TelemetryError": true}).Warnf("Unable to write event %#v to telemetry : %v", entry, err)
}
hook.wg.Done()
} else {
Expand Down Expand Up @@ -146,6 +146,9 @@ func (hook *asyncTelemetryHook) waitForEventAndReady() bool {

// Fire is required to implement logrus hook interface
func (hook *asyncTelemetryHook) Fire(entry *logrus.Entry) error {
if _, ok := entry.Data["TelemetryError"]; ok {
return nil
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a better location than telemetryFilteredhook, as to avoid it being added to the async queue in the first place? telemetryFilteredhook would be a better location if that concern isn't true.

hook.wg.Add(1)
select {
case <-hook.quit:
Expand Down
31 changes: 31 additions & 0 deletions logging/telemetryhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,34 @@ func TestAsyncTelemetryHook_QueueDepth(t *testing.T) {
// be one higher then the maxDepth.
require.LessOrEqual(t, hookEntries, maxDepth+1)
}

// Ensure that errors from inside the telemetryhook.go implementation are not reported to telemetry.
func TestAsyncTelemetryHook_SelfReporting(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

const entryCount = 100
const maxDepth = 10

filling := make(chan struct{})

testHook := makeMockTelemetryHook(logrus.DebugLevel)
testHook.cb = func(entry *logrus.Entry) {
<-filling // Block while filling
}

hook := createAsyncHook(&testHook, 100, 10)
hook.ready = true
for i := 0; i < entryCount; i++ {
selfEntry := logrus.Entry{
Level: logrus.ErrorLevel,
Data: logrus.Fields{"TelemetryError": true},
Message: "Unable to write event",
}
hook.Fire(&selfEntry)
}
close(filling)
hook.Close()

require.Len(t, testHook.entries(), 0)
}