Skip to content

Commit

Permalink
fix: telemetry recorder.Done() may panic if telemetry is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Nov 7, 2023
1 parent 8bb84c8 commit a1cc0e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/telemetry/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (t *recorder) GenerateTelemetryRecord(object any, objectType, eventType, re
}

func (t *recorder) Done() {
if t.telemetryDisabled {
return
}
t.throttler.close()
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/telemetry/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ import (
type fakeEventRecorder struct{}

func (f *fakeEventRecorder) Event(object runtime.Object, eventtype, reason, message string) {
getLogger().Printf("Event: %+v, %s, %s, %s\n", object, eventtype, reason, message)
}
func (f *fakeEventRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...any) {
getLogger().Printf("Eventf: %+v, %s, %s, %s, %v\n", object, eventtype, reason, messageFmt, args)
}
func (f *fakeEventRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...any) {
getLogger().Printf("AnnotatedEventf: %+v, %+v, %s, %s, %s, %v\n", object, annotations, eventtype, reason, messageFmt, args)
}

var _ = Describe("Telemetry", Label("telemetry"), Ordered, func() {
Expand Down Expand Up @@ -60,7 +63,11 @@ var _ = Describe("Telemetry", Label("telemetry"), Ordered, func() {

It("GetHostMetrics", func() {
metrics := telemetry.GetHostMetrics()
Expect(metrics).ShouldNot(BeNil())
if TelemetryDisabled {
Expect(metrics).Should(BeNil())
} else {
Expect(metrics).ShouldNot(BeNil())
}
})

It("Event", func() {
Expand Down

0 comments on commit a1cc0e2

Please sign in to comment.