telemetry(observations): fix the details flag check (#3960)
* telemetry(observations): fix the details flag check * telemetry(observations): fix the test names
This commit is contained in:
1 parent
b000aa3068
commit
4dce290aeb
6 files changed
+20
-8
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) }()
|
||||
|
||||
Reference in new issue
Block a user