From 8ef3916c1ded27f86d02612099045342b64ba579 Mon Sep 17 00:00:00 2001 From: Marcelo Cyreno <812725+marcelocyreno@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:11:51 -0300 Subject: [PATCH] chore: enhance metric labels implementation Original work by @Suraiya-Hameed in #1433 Changes: - Minor refinements suggested by project maintainers Co-authored-by: Suraiya Hameed --- controllers/stats_reporter.go | 6 +----- pkg/rotation/reconciler.go | 10 +++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/controllers/stats_reporter.go b/controllers/stats_reporter.go index c5413df3f..00381f842 100644 --- a/controllers/stats_reporter.go +++ b/controllers/stats_reporter.go @@ -65,7 +65,6 @@ func newStatsReporter() (StatsReporter, error) { func (r reporter) ReportSyncSecretCtMetric(ctx context.Context, provider, namespace, spc string) { opt := metric.WithAttributes( attribute.Key(providerKey).String(provider), - attribute.Key(osTypeKey).String(runtimeOS), attribute.Key(namespaceKey).String(namespace), attribute.Key(spcKey).String(spc), ) @@ -73,8 +72,5 @@ func (r reporter) ReportSyncSecretCtMetric(ctx context.Context, provider, namesp } func (r reporter) ReportSyncSecretDuration(ctx context.Context, duration float64) { - opt := metric.WithAttributes( - attribute.Key(osTypeKey).String(runtimeOS), - ) - r.syncK8sSecretDuration.Record(ctx, duration, opt) + r.syncK8sSecretDuration.Record(ctx, duration) } diff --git a/pkg/rotation/reconciler.go b/pkg/rotation/reconciler.go index 8e154a98a..a58446ab2 100644 --- a/pkg/rotation/reconciler.go +++ b/pkg/rotation/reconciler.go @@ -253,14 +253,14 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *secretsstorev1.Secret var providerName string podName := spcps.Status.PodName podNamespace := spcps.Namespace - secretProviderClass := spcps.Status.SecretProviderClassName + secretProviderClassName := spcps.Status.SecretProviderClassName defer func() { if err != nil { - r.reporter.reportRotationErrorCtMetric(ctx, providerName, podName, podNamespace, secretProviderClass, errorReason, requiresUpdate) + r.reporter.reportRotationErrorCtMetric(ctx, providerName, podName, podNamespace, secretProviderClassName, errorReason, requiresUpdate) return } - r.reporter.reportRotationCtMetric(ctx, providerName, podName, podNamespace, secretProviderClass, requiresUpdate) + r.reporter.reportRotationCtMetric(ctx, providerName, podName, podNamespace, secretProviderClassName, requiresUpdate) r.reporter.reportRotationDuration(ctx, time.Since(begin).Seconds()) }() @@ -293,13 +293,13 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *secretsstorev1.Secret ctx, client.ObjectKey{ Namespace: podNamespace, - Name: secretProviderClass, + Name: secretProviderClassName, }, spc, ) if err != nil { errorReason = internalerrors.SecretProviderClassNotFound - return fmt.Errorf("failed to get secret provider class %s/%s, err: %w", podNamespace, secretProviderClass, err) + return fmt.Errorf("failed to get secret provider class %s/%s, err: %w", podNamespace, secretProviderClassName, err) } // determine which pod volume this is associated with