Skip to content

Commit

Permalink
chore: enhance metric labels implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelocyreno committed Oct 23, 2024
1 parent 3bc8225 commit c898ca1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 1 addition & 5 deletions controllers/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,12 @@ 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),
)
r.syncK8sSecretTotal.Add(ctx, 1, opt)
}

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)
}
10 changes: 5 additions & 5 deletions pkg/rotation/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c898ca1

Please sign in to comment.