From a86ee182c2853913f019c2559f1451d926235707 Mon Sep 17 00:00:00 2001 From: Sepehr <46660996+sepehrfrgh@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:02:50 -0700 Subject: [PATCH] telemetry(observations): fix the details flag check (#3960) (#3964) * telemetry(observations): fix the details flag check * telemetry(observations): fix the test names --- .../auth/ldap/service_authenticate_test.go | 1 + internal/auth/oidc/service_callback_test.go | 2 ++ .../handlers/authmethods/ldap_test.go | 1 + .../handlers/authmethods/password_test.go | 1 + internal/event/context.go | 3 ++- internal/event/context_test.go | 20 ++++++++++++------- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/internal/auth/ldap/service_authenticate_test.go b/internal/auth/ldap/service_authenticate_test.go index 2a9e723c39..9d3a910e99 100644 --- a/internal/auth/ldap/service_authenticate_test.go +++ b/internal/auth/ldap/service_authenticate_test.go @@ -40,6 +40,7 @@ func TestAuthenticate(t *testing.T) { Mutex: testLock, Name: "test", }) + c.EventerConfig.TelemetryEnabled = true require.NoError(t, event.InitSysEventer(testLogger, testLock, "use-Test_Authenticate", event.WithEventerConfig(&c.EventerConfig))) // some standard factories for unit tests authenticatorFn := func() (Authenticator, error) { diff --git a/internal/auth/oidc/service_callback_test.go b/internal/auth/oidc/service_callback_test.go index 2af5d19b99..d3442ab76b 100644 --- a/internal/auth/oidc/service_callback_test.go +++ b/internal/auth/oidc/service_callback_test.go @@ -52,6 +52,7 @@ func Test_Callback(t *testing.T) { Mutex: testLock, Name: "test", }) + c.EventerConfig.TelemetryEnabled = true require.NoError(t, event.InitSysEventer(testLogger, testLock, "use-Test_Callback", event.WithEventerConfig(&c.EventerConfig))) // some standard factories for unit tests which // are used in the Callback(...) call @@ -666,6 +667,7 @@ func Test_ManagedGroupFiltering(t *testing.T) { Mutex: testLock, Name: "test", }) + c.EventerConfig.TelemetryEnabled = true require.NoError(t, event.InitSysEventer(testLogger, testLock, "use-Test_ManagedGroupFiltering", event.WithEventerConfig(&c.EventerConfig))) // some standard factories for unit tests which // are used in the Callback(...) call diff --git a/internal/daemon/controller/handlers/authmethods/ldap_test.go b/internal/daemon/controller/handlers/authmethods/ldap_test.go index e62c1f9711..8129cfd28a 100644 --- a/internal/daemon/controller/handlers/authmethods/ldap_test.go +++ b/internal/daemon/controller/handlers/authmethods/ldap_test.go @@ -889,6 +889,7 @@ func TestAuthenticate_Ldap(t *testing.T) { Mutex: testLock, Name: "test", }) + c.EventerConfig.TelemetryEnabled = true require.NoError(t, event.InitSysEventer(testLogger, testLock, "use-Test_Authenticate", event.WithEventerConfig(&c.EventerConfig))) iamRepoFn := func() (*iam.Repository, error) { return iam.TestRepo(t, testConn, testRootWrapper), nil diff --git a/internal/daemon/controller/handlers/authmethods/password_test.go b/internal/daemon/controller/handlers/authmethods/password_test.go index f9ad7d29a7..40f83fc022 100644 --- a/internal/daemon/controller/handlers/authmethods/password_test.go +++ b/internal/daemon/controller/handlers/authmethods/password_test.go @@ -520,6 +520,7 @@ func TestAuthenticate_Password(t *testing.T) { Mutex: testLock, Name: "test", }) + c.EventerConfig.TelemetryEnabled = true require.NoError(t, event.InitSysEventer(testLogger, testLock, "use-Test_Authenticate", event.WithEventerConfig(&c.EventerConfig))) sinkFileName := c.ObservationEvents.Name() t.Cleanup(func() { diff --git a/internal/event/context.go b/internal/event/context.go index 792d9ebf99..17dc45b9c7 100644 --- a/internal/event/context.go +++ b/internal/event/context.go @@ -110,7 +110,8 @@ func WriteObservation(ctx context.Context, caller Op, opt ...Option) error { "%w", op, ErrInvalidParameter) } // For the case that the telemetry is not enabled, and we have events coming from interceptors. - if !eventer.conf.TelemetryEnabled && (opts.withRequest != nil || opts.withResponse != nil) { + // or the case that incoming call only has withDetails without enabling telemetry. + if !eventer.conf.TelemetryEnabled && (opts.withRequest != nil || opts.withResponse != nil || opts.withDetails != nil) { return nil } // If telemetry is enabled, we add it to the options. diff --git a/internal/event/context_test.go b/internal/event/context_test.go index da0b857ef0..2d4f5f09a9 100644 --- a/internal/event/context_test.go +++ b/internal/event/context_test.go @@ -440,13 +440,18 @@ func Test_WriteObservation(t *testing.T) { cleanup: func() { event.TestResetSystEventer(t) }, }, { - name: "simple", - ctx: testCtx, - telemetryFlag: true, - observationPayload: testPayloads, - header: testWantHeader, - details: testWantDetails, - observationSinkFileName: c.AllEvents.Name(), + name: "simple-header", + ctx: testCtx, + telemetryFlag: true, + observationPayload: testPayloads, + header: testWantHeader, + }, + { + name: "simple-details", + ctx: testCtx, + telemetryFlag: true, + observationPayload: testPayloads, + details: testWantDetails, }, } for _, tt := range tests { @@ -483,6 +488,7 @@ func Test_WriteObservation(t *testing.T) { if !tt.telemetryFlag { require.Nil(event.WriteObservation(tt.ctx, event.Op(tt.name), event.WithRequest(tt.Request), event.WithResponse(tt.Response))) + require.Nil(event.WriteObservation(tt.ctx, event.Op(tt.name), event.WithDetails(tt.details))) } if tt.observationSinkFileName != "" { defer func() { _ = os.WriteFile(tt.observationSinkFileName, nil, 0o666) }()