Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions helpers/rollout_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/hashicorp/vault-secrets-operator/api/v1beta1"
"github.com/hashicorp/vault-secrets-operator/consts"
"github.com/hashicorp/vault-secrets-operator/internal/metrics"
)

// AnnotationRestartedAt is updated to trigger a rollout-restart
Expand Down Expand Up @@ -62,9 +63,11 @@ func HandleRolloutRestarts(ctx context.Context, client ctrlclient.Client, obj ct
errs = errors.Join(err)
recorder.Eventf(obj, corev1.EventTypeWarning, consts.ReasonRolloutRestartFailed,
"Rollout restart failed for target %#v: err=%s", target, err)
metrics.RolloutRestartsErrors.WithLabelValues(obj.GetNamespace(), obj.GetName(), target.Name, target.Kind).Inc()
} else {
recorder.Eventf(obj, corev1.EventTypeNormal, consts.ReasonRolloutRestartTriggered,
"Rollout restart triggered for %v", target)
metrics.RolloutRestartsTotal.WithLabelValues(obj.GetNamespace(), obj.GetName(), target.Name, target.Kind).Inc()
}
}

Expand Down
20 changes: 20 additions & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
NameRequestsTotal = "requests_total"
NameRequestsErrorsTotal = "requests_errors_total"
NameTaintedClients = "tainted_clients"
subsystemRolloutRestarts = "rollout_restarts"
)

var ResourceStatus = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Expand All @@ -56,6 +57,25 @@ func MustRegisterResourceStatus() {
)
}

var RolloutRestartsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName(
Namespace, subsystemRolloutRestarts, "total"),
Help: "Number of total rollout restarts.",
}, []string{"namespace", "name", "target_name", "target_kind"})

var RolloutRestartsErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName(
Namespace, subsystemRolloutRestarts, "errors_total"),
Help: "Number of total rollout restarts.",
}, []string{"namespace", "name", "target_name", "target_kind"})

func MustRegisterRolloutRestarts() {
metrics.Registry.MustRegister(
RolloutRestartsTotal,
RolloutRestartsErrors,
)
}

// SetResourceStatus for the given client.Object. If valid is true, then the
// ResourceStatus gauge will be set 1, else 0.
func SetResourceStatus(controller string, o client.Object, valid bool) {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func main() {
)
vclient.MustRegisterClientMetrics(cfc.MetricsRegistry)
metrics.MustRegisterResourceStatus()
metrics.MustRegisterRolloutRestarts()

metric := prometheus.NewGauge(
prometheus.GaugeOpts{
Expand Down