Skip to content

Commit

Permalink
ROX-20795: probe telemetry configuration (#1455)
Browse files Browse the repository at this point in the history
  • Loading branch information
parametalol authored Nov 14, 2023
1 parent 039b884 commit d1a0d59
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
13 changes: 8 additions & 5 deletions fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@ func (r *CentralReconciler) applyTelemetry(remoteCentral *private.ManagedCentral
if central.Spec.Central == nil {
central.Spec.Central = &v1alpha1.CentralComponentSpec{}
}
// Telemetry will only be enabled if the storage key is set _and_ the central is not an "internal" central created
// from internal clients such as probe service or others.
telemetryEnabled := r.telemetry.StorageKey != "" && !remoteCentral.Metadata.Internal
// 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 || key == "" {
key = "DISABLED"
}
telemetry := &v1alpha1.Telemetry{
Enabled: pointer.Bool(telemetryEnabled),
Enabled: pointer.Bool(true),
Storage: &v1alpha1.TelemetryStorage{
Endpoint: &r.telemetry.StorageEndpoint,
Key: &r.telemetry.StorageKey,
Key: &key,
},
}
central.Spec.Central.Telemetry = telemetry
Expand Down
32 changes: 19 additions & 13 deletions fleetshard/pkg/central/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,11 +1069,15 @@ func TestTelemetryOptionsAreSetInCR(t *testing.T) {
require.NoError(t, err)

require.NotNil(t, central.Spec.Central.Telemetry.Enabled)
assert.Equal(t, tc.enabled, *central.Spec.Central.Telemetry.Enabled)
assert.True(t, *central.Spec.Central.Telemetry.Enabled)
require.NotNil(t, central.Spec.Central.Telemetry.Storage.Endpoint)
assert.Equal(t, tc.telemetry.StorageEndpoint, *central.Spec.Central.Telemetry.Storage.Endpoint)
require.NotNil(t, central.Spec.Central.Telemetry.Storage.Key)
assert.Equal(t, tc.telemetry.StorageKey, *central.Spec.Central.Telemetry.Storage.Key)
if tc.telemetry.StorageKey == "" {
assert.Equal(t, "DISABLED", *central.Spec.Central.Telemetry.Storage.Key)
} else {
assert.Equal(t, tc.telemetry.StorageKey, *central.Spec.Central.Telemetry.Storage.Key)
}
})
}
}
Expand Down Expand Up @@ -1959,23 +1963,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 +1991,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 +2190,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 d1a0d59

Please sign in to comment.