SecretsManager: clear unused metrics and standarize labels(#109515)
This commit is contained in:
@@ -9,20 +9,17 @@ import (
|
||||
const (
|
||||
namespace = "grafana_secrets_manager"
|
||||
subsystem = "service"
|
||||
// labels
|
||||
successLabel = "success"
|
||||
)
|
||||
|
||||
// SecureValueServiceMetrics is a struct that contains all the metrics for SecureValue.
|
||||
type SecureValueServiceMetrics struct {
|
||||
SecureValueCreateDuration *prometheus.HistogramVec
|
||||
SecureValueCreateCount *prometheus.CounterVec
|
||||
SecureValueUpdateDuration *prometheus.HistogramVec
|
||||
SecureValueUpdateCount *prometheus.CounterVec
|
||||
SecureValueReadDuration *prometheus.HistogramVec
|
||||
SecureValueReadCount *prometheus.CounterVec
|
||||
SecureValueListDuration *prometheus.HistogramVec
|
||||
SecureValueListCount *prometheus.CounterVec
|
||||
SecureValueDeleteDuration *prometheus.HistogramVec
|
||||
SecureValueDeleteCount *prometheus.CounterVec
|
||||
}
|
||||
|
||||
func newSecureValueServiceMetrics() *SecureValueServiceMetrics {
|
||||
@@ -33,65 +30,35 @@ func newSecureValueServiceMetrics() *SecureValueServiceMetrics {
|
||||
Name: "secure_value_create_duration_seconds",
|
||||
Help: "Duration of Secure Value create operations",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
}, []string{"success"}),
|
||||
SecureValueCreateCount: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_create_count",
|
||||
Help: "Count of Secure Value create operations",
|
||||
}, []string{"success"}),
|
||||
}, []string{successLabel}),
|
||||
SecureValueReadDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_read_duration_seconds",
|
||||
Help: "Duration of Secure Value read operations",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
}, []string{"success"}),
|
||||
SecureValueReadCount: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_read_count",
|
||||
Help: "Count of Secure Value read operations",
|
||||
}, []string{"success"}),
|
||||
}, []string{successLabel}),
|
||||
SecureValueUpdateDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_update_duration_seconds",
|
||||
Help: "Duration of Secure Value update operations",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
}, []string{"success"}),
|
||||
SecureValueUpdateCount: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_update_count",
|
||||
Help: "Count of Secure Value update operations",
|
||||
}, []string{"success"}),
|
||||
}, []string{successLabel}),
|
||||
SecureValueListDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_list_duration_seconds",
|
||||
Help: "Duration of Secure Value list operations",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
}, []string{"success"}),
|
||||
SecureValueListCount: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_list_count",
|
||||
Help: "Count of Secure Value list operations",
|
||||
}, []string{"success"}),
|
||||
}, []string{successLabel}),
|
||||
SecureValueDeleteDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_delete_duration_seconds",
|
||||
Help: "Duration of Secure Value delete operations",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
}, []string{"success"}),
|
||||
SecureValueDeleteCount: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "secure_value_delete_count",
|
||||
Help: "Count of Secure Value delete operations",
|
||||
}, []string{"success"}),
|
||||
}, []string{successLabel}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,15 +74,10 @@ func NewSecureValueServiceMetrics(reg prometheus.Registerer) *SecureValueService
|
||||
if reg != nil {
|
||||
reg.MustRegister(
|
||||
m.SecureValueCreateDuration,
|
||||
m.SecureValueCreateCount,
|
||||
m.SecureValueReadDuration,
|
||||
m.SecureValueReadCount,
|
||||
m.SecureValueUpdateDuration,
|
||||
m.SecureValueUpdateCount,
|
||||
m.SecureValueListDuration,
|
||||
m.SecureValueListCount,
|
||||
m.SecureValueDeleteDuration,
|
||||
m.SecureValueDeleteCount,
|
||||
)
|
||||
}
|
||||
metricsInstance = m
|
||||
|
||||
@@ -90,7 +90,6 @@ func (s *SecureValueService) Create(ctx context.Context, sv *secretv1beta1.Secur
|
||||
logging.FromContext(ctx).Info("SecureValueService.Create finished", args...)
|
||||
|
||||
s.metrics.SecureValueCreateDuration.WithLabelValues(strconv.FormatBool(success)).Observe(time.Since(start).Seconds())
|
||||
s.metrics.SecureValueCreateCount.WithLabelValues(strconv.FormatBool(success)).Inc()
|
||||
}()
|
||||
|
||||
return s.createNewVersion(ctx, sv, actorUID)
|
||||
@@ -126,7 +125,6 @@ func (s *SecureValueService) Update(ctx context.Context, newSecureValue *secretv
|
||||
logging.FromContext(ctx).Info("SecureValueService.Update finished", args...)
|
||||
|
||||
s.metrics.SecureValueUpdateDuration.WithLabelValues(strconv.FormatBool(success)).Observe(time.Since(start).Seconds())
|
||||
s.metrics.SecureValueUpdateCount.WithLabelValues(strconv.FormatBool(success)).Inc()
|
||||
}()
|
||||
|
||||
if newSecureValue.Spec.Value == nil {
|
||||
@@ -231,7 +229,7 @@ func (s *SecureValueService) Read(ctx context.Context, namespace xkube.Namespace
|
||||
defer func() {
|
||||
args := []any{
|
||||
"name", name,
|
||||
"namespace", namespace,
|
||||
"namespace", namespace.String(),
|
||||
}
|
||||
|
||||
success := readErr == nil
|
||||
@@ -245,7 +243,6 @@ func (s *SecureValueService) Read(ctx context.Context, namespace xkube.Namespace
|
||||
logging.FromContext(ctx).Info("SecureValueService.Read finished", args...)
|
||||
|
||||
s.metrics.SecureValueReadDuration.WithLabelValues(strconv.FormatBool(success)).Observe(time.Since(start).Seconds())
|
||||
s.metrics.SecureValueReadCount.WithLabelValues(strconv.FormatBool(success)).Inc()
|
||||
}()
|
||||
|
||||
defer span.End()
|
||||
@@ -281,7 +278,6 @@ func (s *SecureValueService) List(ctx context.Context, namespace xkube.Namespace
|
||||
logging.FromContext(ctx).Info("SecureValueService.List finished", args...)
|
||||
|
||||
s.metrics.SecureValueListDuration.WithLabelValues(strconv.FormatBool(success)).Observe(time.Since(start).Seconds())
|
||||
s.metrics.SecureValueListCount.WithLabelValues(strconv.FormatBool(success)).Inc()
|
||||
}()
|
||||
|
||||
user, ok := claims.AuthInfoFrom(ctx)
|
||||
@@ -353,7 +349,6 @@ func (s *SecureValueService) Delete(ctx context.Context, namespace xkube.Namespa
|
||||
logging.FromContext(ctx).Info("SecureValueService.Delete finished", args...)
|
||||
|
||||
s.metrics.SecureValueDeleteDuration.WithLabelValues(strconv.FormatBool(success)).Observe(time.Since(start).Seconds())
|
||||
s.metrics.SecureValueDeleteCount.WithLabelValues(strconv.FormatBool(success)).Inc()
|
||||
}()
|
||||
|
||||
// TODO: does this need to be for update?
|
||||
|
||||
Reference in New Issue
Block a user