Skip to content

Commit

Permalink
telemetry(observations): fix the details flag check (#3960) (#3964)
Browse files Browse the repository at this point in the history
* telemetry(observations): fix the details flag check

* telemetry(observations): fix the test names
  • Loading branch information
sepehrfrgh authored Oct 31, 2023
1 parent e6583e5 commit a86ee18
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions internal/auth/ldap/service_authenticate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions internal/auth/oidc/service_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion internal/event/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 13 additions & 7 deletions internal/event/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) }()
Expand Down

0 comments on commit a86ee18

Please sign in to comment.