Skip to content

Commit

Permalink
Merge pull request #12 from run-ai/metrics-fix
Browse files Browse the repository at this point in the history
bug: switching between namespace and cluster scope metrics
  • Loading branch information
yossig-runai authored Oct 7, 2024
2 parents 6e826d5 + 0052c4a commit 651afd9
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@ type ArgoRolloutConfigKeeperCommon struct {
func (r *ArgoRolloutConfigKeeperCommon) ReconcileConfigMaps(ctx context.Context, namespace string, labelSelector map[string]string, ignoredNamespaces map[string]bool) error {
defer func() {
if namespace != "" {
metrics.ConfigMapClusterScopeReconcileDuration.Observe(time.Since(time.Now()).Seconds())
} else {
metrics.ConfigMapReconcileDuration.Observe(time.Since(time.Now()).Seconds())
} else {
metrics.ConfigMapClusterScopeReconcileDuration.Observe(time.Since(time.Now()).Seconds())
}
}()

if namespace != "" {
metrics.ManagedConfigMapClusterScopeCount.Set(0)
} else {
metrics.ManagedConfigMapCount.Set(0)
} else {
metrics.ManagedConfigMapClusterScopeCount.Set(0)
}

configMaps, err := r.listConfigMaps(ctx, namespace, labelSelector)
if err != nil {
return err
}
if namespace != "" {
metrics.DiscoveredConfigMapClusterScopeCount.Set(float64(len(configMaps.Items)))
} else {
metrics.DiscoveredConfigMapCount.Set(float64(len(configMaps.Items)))
} else {
metrics.DiscoveredConfigMapClusterScopeCount.Set(float64(len(configMaps.Items)))
}

if configMaps.Items != nil {
Expand All @@ -70,9 +70,9 @@ func (r *ArgoRolloutConfigKeeperCommon) ReconcileConfigMaps(ctx context.Context,

if havingManagedFinalizer {
if namespace != "" {
metrics.ManagedConfigMapClusterScopeCount.Inc()
} else {
metrics.ManagedConfigMapCount.Inc()
} else {
metrics.ManagedConfigMapClusterScopeCount.Inc()
}

if err := r.finalizerOperation(ctx, &c, finalizerFullName); err != nil {
Expand Down Expand Up @@ -110,25 +110,25 @@ func (r *ArgoRolloutConfigKeeperCommon) ReconcileConfigMaps(ctx context.Context,
func (r *ArgoRolloutConfigKeeperCommon) ReconcileSecrets(ctx context.Context, namespace string, labelSelector map[string]string, ignoredNamespaces map[string]bool) error {
defer func() {
if namespace != "" {
metrics.SecretClusterScopeReconcileDuration.Observe(time.Since(time.Now()).Seconds())
} else {
metrics.SecretReconcileDuration.Observe(time.Since(time.Now()).Seconds())
} else {
metrics.SecretClusterScopeReconcileDuration.Observe(time.Since(time.Now()).Seconds())
}
}()
if namespace != "" {
metrics.ManagedSecretClusterScopeCount.Set(0)
} else {
metrics.ManagedSecretCount.Set(0)
} else {
metrics.ManagedSecretClusterScopeCount.Set(0)
}

secrets, err := r.listSecrets(ctx, namespace, labelSelector)
if err != nil {
return err
}
if namespace != "" {
metrics.DiscoveredSecretClusterScopeCount.Set(float64(len(secrets.Items)))
} else {
metrics.DiscoveredSecretCount.Set(float64(len(secrets.Items)))
} else {
metrics.DiscoveredSecretClusterScopeCount.Set(float64(len(secrets.Items)))
}

if secrets.Items != nil {
Expand All @@ -144,9 +144,9 @@ func (r *ArgoRolloutConfigKeeperCommon) ReconcileSecrets(ctx context.Context, na

if havingManagedFinalizer {
if namespace != "" {
metrics.ManagedSecretClusterScopeCount.Inc()
} else {
metrics.ManagedSecretCount.Inc()
} else {
metrics.ManagedSecretClusterScopeCount.Inc()
}

if err := r.finalizerOperation(ctx, &s, finalizerFullName); err != nil {
Expand Down

0 comments on commit 651afd9

Please sign in to comment.