From e2b2c0e26ea9c64a60d255900627066651aba1a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 00:04:37 +0100 Subject: [PATCH] Bump github.com/machadovilaca/operator-observability (#366) Bumps [github.com/machadovilaca/operator-observability](https://github.com/machadovilaca/operator-observability) from 0.0.20 to 0.0.24. - [Release notes](https://github.com/machadovilaca/operator-observability/releases) - [Commits](https://github.com/machadovilaca/operator-observability/compare/v0.0.20...v0.0.24) --- updated-dependencies: - dependency-name: github.com/machadovilaca/operator-observability dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 3 +- go.sum | 4 +- .../pkg/operatormetrics/collector.go | 16 ++++---- .../pkg/operatormetrics/collector_result.go | 24 ++++++++++++ .../pkg/operatormetrics/counter.go | 2 +- .../pkg/operatormetrics/counter_vec.go | 2 +- .../pkg/operatormetrics/gauge.go | 2 +- .../pkg/operatormetrics/gauge_vec.go | 2 +- .../pkg/operatormetrics/histogram.go | 2 +- .../pkg/operatormetrics/histogram_vec.go | 2 +- .../pkg/operatormetrics/metric.go | 3 +- .../pkg/operatormetrics/summary.go | 2 +- .../pkg/operatormetrics/summary_vec.go | 2 +- .../pkg/operatormetrics/wrapper_registry.go | 19 +++++++++- .../pkg/operatorrules/compatibility.go | 37 +++++++++++++++++++ .../pkg/operatorrules/prometheusrules.go | 18 ++++----- .../pkg/operatorrules/registry.go | 36 ++++++++---------- vendor/modules.txt | 2 +- 18 files changed, 124 insertions(+), 54 deletions(-) create mode 100644 vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector_result.go create mode 100644 vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/compatibility.go diff --git a/go.mod b/go.mod index f3063974..2029889e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module kubevirt.io/hostpath-provisioner go 1.22.0 + toolchain go1.22.5 require ( @@ -9,7 +10,7 @@ require ( github.com/kubernetes-csi/csi-lib-utils v0.16.0 github.com/kubernetes-csi/csi-test/v4 v4.4.0 github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20230710120526-cc1644c90b64 - github.com/machadovilaca/operator-observability v0.0.20 + github.com/machadovilaca/operator-observability v0.0.24 github.com/onsi/gomega v1.31.0 github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.71.2 github.com/prometheus/client_golang v1.19.0 diff --git a/go.sum b/go.sum index 54ba6e6b..ab4ad4ce 100644 --- a/go.sum +++ b/go.sum @@ -196,8 +196,8 @@ github.com/kubernetes-csi/csi-test/v4 v4.4.0 h1:r0mnAwDURI24Vw3a/LyA/ga11yD5ZGuU github.com/kubernetes-csi/csi-test/v4 v4.4.0/go.mod h1:t1RzseMZJKy313nezI/d7TolbbiKpUZM3SXQvXxOX0w= github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20230710120526-cc1644c90b64 h1:WghbbS7pdWAsMSouy7KG8TEP/RIAYDTJdrth1bpXUXk= github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20230710120526-cc1644c90b64/go.mod h1:qGj2agzgwQ27nYhP3xhLs+IBzE5+ALNUg8bDfMcwPqo= -github.com/machadovilaca/operator-observability v0.0.20 h1:I9CLKWcaJU9KtPREhUu4yn/CLAZUpxFqEUz/ZVenkAI= -github.com/machadovilaca/operator-observability v0.0.20/go.mod h1:e4Z3VhOXb9InkmSh00JjqBBijE+iD+YMzynBpKB3+gE= +github.com/machadovilaca/operator-observability v0.0.24 h1:VQuTH7FAYzd/0HC11bHumHCNdOji7zMragQEpgcWRSI= +github.com/machadovilaca/operator-observability v0.0.24/go.mod h1:trC+BjI6zhvZMBcX0q7vHrKKRX3lWZdwJxgVUmRJCfw= github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector.go index 35015f51..6cbbd4a3 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector.go @@ -19,13 +19,6 @@ type Collector struct { CollectCallback func() []CollectorResult } -type CollectorResult struct { - Metric Metric - Labels []string - ConstLabels map[string]string - Value float64 -} - func (c Collector) hash() string { var sb strings.Builder @@ -38,7 +31,7 @@ func (c Collector) hash() string { func (c Collector) Describe(ch chan<- *prometheus.Desc) { for _, cm := range c.Metrics { - cm.getCollector().Describe(ch) + cm.GetCollector().Describe(ch) } } @@ -93,7 +86,12 @@ func collectValue(ch chan<- prometheus.Metric, metric Metric, cr CollectorResult if err != nil { return err } - ch <- cm + + if cr.Timestamp.IsZero() { + ch <- cm + } else { + ch <- prometheus.NewMetricWithTimestamp(cr.Timestamp, cm) + } return nil } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector_result.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector_result.go new file mode 100644 index 00000000..40d0e896 --- /dev/null +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/collector_result.go @@ -0,0 +1,24 @@ +package operatormetrics + +import ( + "errors" + "time" +) + +type CollectorResult struct { + Metric Metric + Labels []string + ConstLabels map[string]string + Value float64 + Timestamp time.Time +} + +func (cr CollectorResult) GetLabelValue(key string) (string, error) { + for i, label := range cr.Metric.GetOpts().labels { + if label == key { + return cr.Labels[i], nil + } + } + + return "", errors.New("label not found") +} diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter.go index ddca79de..4d1e57f0 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter.go @@ -31,6 +31,6 @@ func (c *Counter) GetBaseType() MetricType { return CounterType } -func (c *Counter) getCollector() prometheus.Collector { +func (c *Counter) GetCollector() prometheus.Collector { return c.Counter } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter_vec.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter_vec.go index 568ce6c7..5554513a 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter_vec.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/counter_vec.go @@ -33,6 +33,6 @@ func (c *CounterVec) GetBaseType() MetricType { return CounterType } -func (c *CounterVec) getCollector() prometheus.Collector { +func (c *CounterVec) GetCollector() prometheus.Collector { return c.CounterVec } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge.go index de2699b2..43250ed4 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge.go @@ -31,6 +31,6 @@ func (c *Gauge) GetBaseType() MetricType { return GaugeType } -func (c *Gauge) getCollector() prometheus.Collector { +func (c *Gauge) GetCollector() prometheus.Collector { return c.Gauge } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge_vec.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge_vec.go index c771dece..d9dca423 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge_vec.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/gauge_vec.go @@ -33,6 +33,6 @@ func (c *GaugeVec) GetBaseType() MetricType { return GaugeType } -func (c *GaugeVec) getCollector() prometheus.Collector { +func (c *GaugeVec) GetCollector() prometheus.Collector { return c.GaugeVec } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram.go index b764835e..43f2dc36 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram.go @@ -46,6 +46,6 @@ func (c *Histogram) GetBaseType() MetricType { return HistogramType } -func (c *Histogram) getCollector() prometheus.Collector { +func (c *Histogram) GetCollector() prometheus.Collector { return c.Histogram } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram_vec.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram_vec.go index f272495f..1157be4e 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram_vec.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/histogram_vec.go @@ -37,6 +37,6 @@ func (c *HistogramVec) GetBaseType() MetricType { return HistogramType } -func (c *HistogramVec) getCollector() prometheus.Collector { +func (c *HistogramVec) GetCollector() prometheus.Collector { return c.HistogramVec } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/metric.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/metric.go index 108d86bb..932541ee 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/metric.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/metric.go @@ -15,8 +15,7 @@ type Metric interface { GetOpts() MetricOpts GetType() MetricType GetBaseType() MetricType - - getCollector() prometheus.Collector + GetCollector() prometheus.Collector } type MetricType string diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary.go index 3bf9d37c..de561ef8 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary.go @@ -46,6 +46,6 @@ func (c *Summary) GetBaseType() MetricType { return SummaryType } -func (c *Summary) getCollector() prometheus.Collector { +func (c *Summary) GetCollector() prometheus.Collector { return c.Summary } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary_vec.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary_vec.go index 6ea8bc54..db314b53 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary_vec.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/summary_vec.go @@ -37,6 +37,6 @@ func (c *SummaryVec) GetBaseType() MetricType { return SummaryType } -func (c *SummaryVec) getCollector() prometheus.Collector { +func (c *SummaryVec) GetCollector() prometheus.Collector { return c.SummaryVec } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/wrapper_registry.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/wrapper_registry.go index 8bb2b76e..09977ba9 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/wrapper_registry.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatormetrics/wrapper_registry.go @@ -63,6 +63,21 @@ func RegisterCollector(collectors ...Collector) error { return nil } +// UnregisterMetrics unregisters the metrics from the Prometheus registry. +func UnregisterMetrics(allMetrics ...[]Metric) error { + for _, metricList := range allMetrics { + for _, metric := range metricList { + if metricExists(metric) { + if err := unregisterMetric(metric); err != nil { + return err + } + } + } + } + + return nil +} + // ListMetrics returns a list of all registered metrics. func ListMetrics() []Metric { var result []Metric @@ -107,7 +122,7 @@ func metricExists(metric Metric) bool { } func unregisterMetric(metric Metric) error { - if succeeded := Unregister(metric.getCollector()); succeeded { + if succeeded := Unregister(metric.GetCollector()); succeeded { delete(operatorRegistry.registeredMetrics, metric.GetOpts().Name) return nil } @@ -116,7 +131,7 @@ func unregisterMetric(metric Metric) error { } func registerMetric(metric Metric) error { - err := Register(metric.getCollector()) + err := Register(metric.GetCollector()) if err != nil { return err } diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/compatibility.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/compatibility.go new file mode 100644 index 00000000..a7277fc5 --- /dev/null +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/compatibility.go @@ -0,0 +1,37 @@ +package operatorrules + +import promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + +// Deprecated: operatorRegistry is deprecated. +var operatorRegistry = NewRegistry() + +// Deprecated: RegisterRecordingRules is deprecated. +func RegisterRecordingRules(recordingRules ...[]RecordingRule) error { + return operatorRegistry.RegisterRecordingRules(recordingRules...) +} + +// Deprecated: RegisterAlerts is deprecated. +func RegisterAlerts(alerts ...[]promv1.Rule) error { + return operatorRegistry.RegisterAlerts(alerts...) +} + +// Deprecated: ListRecordingRules is deprecated. +func ListRecordingRules() []RecordingRule { + return operatorRegistry.ListRecordingRules() +} + +// Deprecated: ListAlerts is deprecated. +func ListAlerts() []promv1.Rule { + return operatorRegistry.ListAlerts() +} + +// Deprecated: CleanRegistry is deprecated. +func CleanRegistry() error { + operatorRegistry = NewRegistry() + return nil +} + +// Deprecated: BuildPrometheusRule is deprecated. +func BuildPrometheusRule(name, namespace string, labels map[string]string) (*promv1.PrometheusRule, error) { + return operatorRegistry.BuildPrometheusRule(name, namespace, labels) +} diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/prometheusrules.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/prometheusrules.go index 88000e63..fd3f7e7f 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/prometheusrules.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/prometheusrules.go @@ -11,8 +11,8 @@ import ( ) // BuildPrometheusRule builds a PrometheusRule object from the registered recording rules and alerts. -func BuildPrometheusRule(name, namespace string, labels map[string]string) (*promv1.PrometheusRule, error) { - spec, err := buildPrometheusRuleSpec() +func (r *Registry) BuildPrometheusRule(name, namespace string, labels map[string]string) (*promv1.PrometheusRule, error) { + spec, err := r.buildPrometheusRuleSpec() if err != nil { return nil, err } @@ -31,20 +31,20 @@ func BuildPrometheusRule(name, namespace string, labels map[string]string) (*pro }, nil } -func buildPrometheusRuleSpec() (*promv1.PrometheusRuleSpec, error) { +func (r *Registry) buildPrometheusRuleSpec() (*promv1.PrometheusRuleSpec, error) { var groups []promv1.RuleGroup - if len(operatorRegistry.registeredRecordingRules) != 0 { + if len(r.registeredRecordingRules) != 0 { groups = append(groups, promv1.RuleGroup{ Name: "recordingRules.rules", - Rules: buildRecordingRulesRules(), + Rules: r.buildRecordingRulesRules(), }) } - if len(operatorRegistry.registeredAlerts) != 0 { + if len(r.registeredAlerts) != 0 { groups = append(groups, promv1.RuleGroup{ Name: "alerts.rules", - Rules: ListAlerts(), + Rules: r.ListAlerts(), }) } @@ -55,10 +55,10 @@ func buildPrometheusRuleSpec() (*promv1.PrometheusRuleSpec, error) { return &promv1.PrometheusRuleSpec{Groups: groups}, nil } -func buildRecordingRulesRules() []promv1.Rule { +func (r *Registry) buildRecordingRulesRules() []promv1.Rule { var rules []promv1.Rule - for _, recordingRule := range operatorRegistry.registeredRecordingRules { + for _, recordingRule := range r.registeredRecordingRules { rules = append(rules, promv1.Rule{ Record: recordingRule.MetricsOpts.Name, Expr: recordingRule.Expr, diff --git a/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/registry.go b/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/registry.go index fdef0060..a5e16f65 100644 --- a/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/registry.go +++ b/vendor/github.com/machadovilaca/operator-observability/pkg/operatorrules/registry.go @@ -7,26 +7,24 @@ import ( promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" ) -var operatorRegistry = newRegistry() - -type operatorRegisterer struct { +type Registry struct { registeredRecordingRules map[string]RecordingRule registeredAlerts map[string]promv1.Rule } -func newRegistry() operatorRegisterer { - return operatorRegisterer{ +func NewRegistry() *Registry { + return &Registry{ registeredRecordingRules: map[string]RecordingRule{}, registeredAlerts: map[string]promv1.Rule{}, } } // RegisterRecordingRules registers the given recording rules. -func RegisterRecordingRules(recordingRules ...[]RecordingRule) error { +func (r *Registry) RegisterRecordingRules(recordingRules ...[]RecordingRule) error { for _, recordingRuleList := range recordingRules { for _, recordingRule := range recordingRuleList { key := recordingRule.MetricsOpts.Name + ":" + recordingRule.Expr.String() - operatorRegistry.registeredRecordingRules[key] = recordingRule + r.registeredRecordingRules[key] = recordingRule } } @@ -34,10 +32,11 @@ func RegisterRecordingRules(recordingRules ...[]RecordingRule) error { } // RegisterAlerts registers the given alerts. -func RegisterAlerts(alerts ...[]promv1.Rule) error { +func (r *Registry) RegisterAlerts(alerts ...[]promv1.Rule) error { for _, alertList := range alerts { for _, alert := range alertList { - operatorRegistry.registeredAlerts[alert.Alert] = alert + key := alert.Alert + ":" + alert.Expr.String() + r.registeredAlerts[key] = alert } } @@ -45,9 +44,9 @@ func RegisterAlerts(alerts ...[]promv1.Rule) error { } // ListRecordingRules returns the registered recording rules. -func ListRecordingRules() []RecordingRule { +func (r *Registry) ListRecordingRules() []RecordingRule { var rules []RecordingRule - for _, rule := range operatorRegistry.registeredRecordingRules { + for _, rule := range r.registeredRecordingRules { rules = append(rules, rule) } @@ -62,21 +61,18 @@ func ListRecordingRules() []RecordingRule { } // ListAlerts returns the registered alerts. -func ListAlerts() []promv1.Rule { +func (r *Registry) ListAlerts() []promv1.Rule { var alerts []promv1.Rule - for _, alert := range operatorRegistry.registeredAlerts { + for _, alert := range r.registeredAlerts { alerts = append(alerts, alert) } slices.SortFunc(alerts, func(a, b promv1.Rule) int { - return cmp.Compare(a.Alert, b.Alert) + aKey := a.Alert + ":" + a.Expr.String() + bKey := b.Alert + ":" + b.Expr.String() + + return cmp.Compare(aKey, bKey) }) return alerts } - -// CleanRegistry removes all registered rules and alerts. -func CleanRegistry() error { - operatorRegistry = newRegistry() - return nil -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 21ea8eab..a4457bf4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -90,7 +90,7 @@ github.com/kubernetes-csi/csi-test/v4/utils # github.com/kubevirt/monitoring/pkg/metrics/parser v0.0.0-20230710120526-cc1644c90b64 ## explicit; go 1.20 github.com/kubevirt/monitoring/pkg/metrics/parser -# github.com/machadovilaca/operator-observability v0.0.20 +# github.com/machadovilaca/operator-observability v0.0.24 ## explicit; go 1.21 github.com/machadovilaca/operator-observability/pkg/docs github.com/machadovilaca/operator-observability/pkg/operatormetrics