Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parametalol committed Nov 10, 2023
1 parent d4a2039 commit b881c29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ func (r *CentralReconciler) applyTelemetry(remoteCentral *private.ManagedCentral
central.Spec.Central = &v1alpha1.CentralComponentSpec{}
}
// Telemetry is always enabled, but the key is set to DISABLED for probe and other internal instances.
// Cloud-service specificity: empty key also disables telemetry to prevent reporting to the self-managed bucket.
key := r.telemetry.StorageKey
if remoteCentral.Metadata.Internal {
if remoteCentral.Metadata.Internal || key == "" {
key = "DISABLED"
}
telemetry := &v1alpha1.Telemetry{
Expand Down
24 changes: 13 additions & 11 deletions fleetshard/pkg/central/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1959,23 +1959,25 @@ func Test_getCentralConfig_telemetry(t *testing.T) {
assert func(t *testing.T, c *v1alpha1.Central)
}{
{
name: "should disable telemetry when no storage key is set",
name: "telemetry enabled, but DISABLED when no storage key is set",
args: args{
isInternal: false,
storageKey: "",
},
assert: func(t *testing.T, c *v1alpha1.Central) {
assert.False(t, *c.Spec.Central.Telemetry.Enabled)
assert.True(t, *c.Spec.Central.Telemetry.Enabled)
assert.Equal(t, "DISABLED", *c.Spec.Central.Telemetry.Storage.Key)
},
},
{
name: "should disable telemetry when managed central is internal",
name: "should DISABLE telemetry key when managed central is internal",
args: args{
isInternal: true,
storageKey: "foo",
},
assert: func(t *testing.T, c *v1alpha1.Central) {
assert.False(t, *c.Spec.Central.Telemetry.Enabled)
assert.True(t, *c.Spec.Central.Telemetry.Enabled)
assert.Equal(t, "DISABLED", *c.Spec.Central.Telemetry.Storage.Key)
},
},
{
Expand All @@ -1985,18 +1987,18 @@ func Test_getCentralConfig_telemetry(t *testing.T) {
storageKey: "foo",
},
assert: func(t *testing.T, c *v1alpha1.Central) {
assert.False(t, *c.Spec.Central.Telemetry.Enabled)
assert.True(t, *c.Spec.Central.Telemetry.Enabled)
assert.Equal(t, "foo", *c.Spec.Central.Telemetry.Storage.Key)
},
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
r := &CentralReconciler{}
if tc.args.isInternal {
r.telemetry = config.Telemetry{
r := &CentralReconciler{
telemetry: config.Telemetry{
StorageKey: tc.args.storageKey,
}
},
}
c := &v1alpha1.Central{}
mc := &private.ManagedCentral{
Expand Down Expand Up @@ -2184,10 +2186,10 @@ metadata:
},
},
Telemetry: &v1alpha1.Telemetry{
Enabled: pointer.Bool(false),
Enabled: pointer.Bool(true),
Storage: &v1alpha1.TelemetryStorage{
Endpoint: pointer.String(""),
Key: pointer.String(""),
Key: pointer.String("DISABLED"),
},
},
},
Expand Down

0 comments on commit b881c29

Please sign in to comment.