Skip to content

Commit

Permalink
use counter
Browse files Browse the repository at this point in the history
Signed-off-by: Will Kutler <wkutler@redhat.com>
  • Loading branch information
willkutler committed Dec 6, 2022
1 parent b658407 commit 34dbc4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func (r *ConfigurationPolicyReconciler) Reconcile(ctx context.Context, request c
_ = compareObjSecondsCounter.DeletePartialMatch(prometheus.Labels{"config_policy_name": request.Name})
_ = policyRelatedObjectGauge.DeletePartialMatch(
prometheus.Labels{"policy": fmt.Sprintf("%s/%s", request.Namespace, request.Name)})
_ = policyUserErrorsGauge.DeletePartialMatch(prometheus.Labels{"template": request.Name})
_ = policySystemErrorsGauge.DeletePartialMatch(prometheus.Labels{"template": request.Name})
_ = policyUserErrorsCounter.DeletePartialMatch(prometheus.Labels{"template": request.Name})
_ = policySystemErrorsCounter.DeletePartialMatch(prometheus.Labels{"template": request.Name})
}

return reconcile.Result{}, nil
Expand Down Expand Up @@ -589,7 +589,7 @@ func (r *ConfigurationPolicyReconciler) handleObjectTemplates(plc policyv1.Confi
if len(plc.OwnerReferences) > 0 {
parent = plc.OwnerReferences[0].Name
}
policyUserErrorsGauge.WithLabelValues(parent, plc.GetName(), "invalid-template").Add(1)
policyUserErrorsCounter.WithLabelValues(parent, plc.GetName(), "invalid-template").Add(1)

return
}
Expand Down Expand Up @@ -1638,7 +1638,7 @@ func (r *ConfigurationPolicyReconciler) getMapping(
if len(policy.OwnerReferences) > 0 {
parent = policy.OwnerReferences[0].Name
}
policyUserErrorsGauge.WithLabelValues(parent, policy.GetName(), "no-object-CRD").Add(1)
policyUserErrorsCounter.WithLabelValues(parent, policy.GetName(), "no-object-CRD").Add(1)
}

errMsg := err.Error()
Expand Down Expand Up @@ -2465,7 +2465,7 @@ func (r *ConfigurationPolicyReconciler) addForUpdate(policy *policyv1.Configurat
if len(policy.OwnerReferences) > 0 {
parent = policy.OwnerReferences[0].Name
}
policySystemErrorsGauge.WithLabelValues(parent, policy.GetName(), "status-update-failed").Add(1)
policySystemErrorsCounter.WithLabelValues(parent, policy.GetName(), "status-update-failed").Add(1)
}
}

Expand Down
12 changes: 6 additions & 6 deletions controllers/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ var (
"policy",
},
)
policyUserErrorsGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
policyUserErrorsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "policy_user_errors",
Help: "The number of user errors encountered while processing policies",
},
Expand All @@ -76,8 +76,8 @@ var (
"type",
},
)
policySystemErrorsGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
policySystemErrorsCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "policy_system_errors",
Help: "The number of system errors encountered while processing policies",
},
Expand All @@ -100,12 +100,12 @@ func init() {
// Error metrics may already be registered by template sync
alreadyReg := &prometheus.AlreadyRegisteredError{}

regErr := metrics.Registry.Register(policySystemErrorsGauge)
regErr := metrics.Registry.Register(policySystemErrorsCounter)
if regErr != nil && !errors.As(regErr, alreadyReg) {
panic(regErr)
}

regErr = metrics.Registry.Register(policyUserErrorsGauge)
regErr = metrics.Registry.Register(policyUserErrorsCounter)
if regErr != nil && !errors.As(regErr, alreadyReg) {
panic(regErr)
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/case26_user_error_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"open-cluster-management.io/config-policy-controller/test/utils"
)

Expand All @@ -33,7 +33,7 @@ var _ = Describe("Test related object metrics", Ordered, func() {
return utils.GetMetrics(
"policy_user_errors",
)
}, defaultTimeoutSeconds, 1).Should(Equal([]string{"policies", "gauge", "1"}))
}, defaultTimeoutSeconds, 1).Should(Equal([]string{"policies", "counter", "1"}))
})

cleanup := func() {
Expand Down

0 comments on commit 34dbc4a

Please sign in to comment.