Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add managed by metric #1831

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/metrics/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const agentStrategiesMetric = "agent_strategies"
const storageMetric = "storage_types"
const strategiesMetric = "strategies"
const autoprovisioningMetric = "autoprovisioning"
const managedMetric = "managed"
const managedByLabel = "app.kubernetes.io/managed-by"

// This structure contains the labels associated with the instances and a counter of the number of instances
type instancesView struct {
Expand Down Expand Up @@ -134,6 +136,21 @@ func (i *instancesMetric) Setup(ctx context.Context) error {
}
i.observations = append(i.observations, obs)

obs, err = newObservation(batch, managedMetric,
"Instances managed by other tool",
"tool",
func(jaeger v1.Jaeger) string {
managed, hasManagement := jaeger.Labels[managedByLabel]
if !hasManagement {
return "none"
}
return managed
})
if err != nil {
return err
}
i.observations = append(i.observations, obs)

return nil
}

Expand Down
65 changes: 65 additions & 0 deletions pkg/metrics/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,68 @@ func TestAutoProvisioningESObservedMetric(t *testing.T) {
assertLabelAndValues(t, expectedMetric.name, meter.MeasurementBatches, expectedMetric.labels, expectedMetric.value)

}

func TestManagerByMetric(t *testing.T) {
s := scheme.Scheme
s.AddKnownTypes(v1.GroupVersion, &v1.Jaeger{}, &v1.JaegerList{})

managed := v1.Jaeger{
ObjectMeta: metav1.ObjectMeta{
Name: "jaeger-managed",
Namespace: "ns",
Labels: map[string]string{
managedByLabel: "maistra-istio-operator",
},
},
Spec: v1.JaegerSpec{
Strategy: "allInOne",
Storage: v1.JaegerStorageSpec{
Type: v1.JaegerMemoryStorage,
},
},
}

nonManaged := v1.Jaeger{
ObjectMeta: metav1.ObjectMeta{
Name: "jaeger-no-managed",
Namespace: "ns",
},
Spec: v1.JaegerSpec{
Strategy: "allInOne",
Storage: v1.JaegerStorageSpec{
Type: v1.JaegerMemoryStorage,
},
},
}

objs := []runtime.Object{
&managed,
&nonManaged,
}

cl := fake.NewFakeClientWithScheme(s, objs...)
meter, provider := oteltest.NewMeterProvider()
global.SetMeterProvider(provider)

instancesObservedValue := newInstancesMetric(cl)
err := instancesObservedValue.Setup(context.Background())
require.NoError(t, err)
meter.RunAsyncInstruments()

expectedMetric := newExpectedMetric(managedMetric, attribute.String("tool", "maistra-istio-operator"), 1)
assertLabelAndValues(t, expectedMetric.name, meter.MeasurementBatches, expectedMetric.labels, expectedMetric.value)

expectedMetric = newExpectedMetric(managedMetric, attribute.String("tool", "none"), 1)
assertLabelAndValues(t, expectedMetric.name, meter.MeasurementBatches, expectedMetric.labels, expectedMetric.value)

// Test deleting managed
err = cl.Delete(context.Background(), &managed)
require.NoError(t, err)

// Reset measurement batches
meter.MeasurementBatches = []oteltest.Batch{}
meter.RunAsyncInstruments()

expectedMetric = newExpectedMetric(managedMetric, attribute.String("tool", "maistra-istio-operator"), 0)
assertLabelAndValues(t, expectedMetric.name, meter.MeasurementBatches, expectedMetric.labels, expectedMetric.value)
}