Skip to content

Commit

Permalink
Merge pull request #463 from povilasv/add-namespace-to-error-metrics
Browse files Browse the repository at this point in the history
add namespace to unseal error metric
  • Loading branch information
Marko Mikulicic authored Oct 26, 2020
2 parents afd6c04 + b85fda3 commit 6377107
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
12 changes: 6 additions & 6 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (c *Controller) unseal(key string) (unsealErr error) {
obj, exists, err := c.informer.GetIndexer().GetByKey(key)
if err != nil {
log.Printf("Error fetching object with key %s from store: %v", key, err)
unsealErrorsTotal.WithLabelValues("fetch").Inc()
unsealErrorsTotal.WithLabelValues("fetch", "").Inc()
return err
}

Expand Down Expand Up @@ -242,7 +242,7 @@ func (c *Controller) unseal(key string) (unsealErr error) {
if err := c.updateSealedSecretStatus(ssecret, unsealErr); err != nil {
// Non-fatal. Log and continue.
log.Printf("Error updating SealedSecret %s status: %v", key, err)
unsealErrorsTotal.WithLabelValues("status").Inc()
unsealErrorsTotal.WithLabelValues("status", ssecret.GetNamespace()).Inc()
} else {
ObserveCondition(ssecret)
}
Expand All @@ -251,7 +251,7 @@ func (c *Controller) unseal(key string) (unsealErr error) {
newSecret, err := c.attemptUnseal(ssecret)
if err != nil {
c.recorder.Eventf(ssecret, corev1.EventTypeWarning, ErrUnsealFailed, "Failed to unseal: %v", err)
unsealErrorsTotal.WithLabelValues("unseal").Inc()
unsealErrorsTotal.WithLabelValues("unseal", ssecret.GetNamespace()).Inc()
return err
}

Expand All @@ -261,14 +261,14 @@ func (c *Controller) unseal(key string) (unsealErr error) {
}
if err != nil {
c.recorder.Event(ssecret, corev1.EventTypeWarning, ErrUpdateFailed, err.Error())
unsealErrorsTotal.WithLabelValues("update").Inc()
unsealErrorsTotal.WithLabelValues("update", ssecret.GetNamespace()).Inc()
return err
}

if !metav1.IsControlledBy(secret, ssecret) && !isAnnotatedToBeManaged(secret) {
msg := fmt.Sprintf("Resource %q already exists and is not managed by SealedSecret", secret.Name)
c.recorder.Event(ssecret, corev1.EventTypeWarning, ErrUpdateFailed, msg)
unsealErrorsTotal.WithLabelValues("unmanaged").Inc()
unsealErrorsTotal.WithLabelValues("unmanaged", ssecret.GetNamespace()).Inc()
return fmt.Errorf("failed update: %s", msg)
}

Expand All @@ -285,7 +285,7 @@ func (c *Controller) unseal(key string) (unsealErr error) {
secret, err = c.sclient.Secrets(ssecret.GetObjectMeta().GetNamespace()).Update(secret)
if err != nil {
c.recorder.Event(ssecret, corev1.EventTypeWarning, ErrUpdateFailed, err.Error())
unsealErrorsTotal.WithLabelValues("update").Inc()
unsealErrorsTotal.WithLabelValues("update", ssecret.GetNamespace()).Inc()
return err
}
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/controller/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
Name: "unseal_errors_total",
Help: "Total number of sealed secret unseal errors by reason",
},
[]string{"reason"},
[]string{"reason", "namespace"},
)

conditionInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Expand All @@ -64,11 +64,6 @@ func init() {
prometheus.MustRegister(unsealRequestsTotal)
prometheus.MustRegister(unsealErrorsTotal)
prometheus.MustRegister(conditionInfo)

// Initialise known label values
for _, val := range []string{"fetch", "status", "unmanaged", "unseal", "update"} {
unsealErrorsTotal.WithLabelValues(val)
}
}

// ObserveCondition sets a `condition_info` Gauge according to a SealedSecret status.
Expand Down

0 comments on commit 6377107

Please sign in to comment.