From 7ec52cf6059636186b3c27d1bc6b832628675b6c Mon Sep 17 00:00:00 2001 From: rickbrouwer Date: Sun, 17 Nov 2024 20:02:41 +0100 Subject: [PATCH 1/3] Remove Prometheus metric deprecations Signed-off-by: rickbrouwer --- CHANGELOG.md | 2 +- pkg/metricscollector/prommetrics.go | 105 ---------------------------- 2 files changed, 1 insertion(+), 106 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbba7b57a05..97106ed93b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,7 +84,7 @@ New deprecation(s): ### Breaking Changes -- TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX)) +*General**: Remove Prometheus metric deprecations ([#5687](https://github.com/kedacore/keda/issues/5687)) ### Other diff --git a/pkg/metricscollector/prommetrics.go b/pkg/metricscollector/prommetrics.go index a5b9bc6c5b8..976be5a2ecd 100644 --- a/pkg/metricscollector/prommetrics.go +++ b/pkg/metricscollector/prommetrics.go @@ -17,7 +17,6 @@ limitations under the License. package metricscollector import ( - "fmt" "runtime" "strconv" "time" @@ -30,10 +29,6 @@ import ( "github.com/kedacore/keda/v2/version" ) -// bestPracticeDeprecatedMsg is a constant string that is used to indicate that a metric is deprecated as -// part of best practice refactoring - https://github.com/kedacore/keda/pull/5174 -const bestPracticeDeprecatedMsg = "DEPRECATED - will be removed in 2.16:" - var log = logf.Log.WithName("prometheus_server") var ( @@ -55,15 +50,6 @@ var ( }, metricLabels, ) - scalerMetricsLatencyDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaler", - Name: "metrics_latency", - Help: fmt.Sprintf("%v use 'keda_scaler_metrics_latency_seconds' instead.", bestPracticeDeprecatedMsg), - }, - metricLabels, - ) scalerMetricsLatency = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -91,24 +77,6 @@ var ( }, []string{"namespace", "scaledObject"}, ) - scalerErrorsDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaler", - Name: "errors", - Help: fmt.Sprintf("%v use 'keda_scaler_detail_errors_total' instead.", bestPracticeDeprecatedMsg), - }, - metricLabels, - ) - scalerErrorsTotalDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaler", - Name: "errors_total", - Help: fmt.Sprintf("%v use use a `sum(keda_scaler_detail_errors_total{scaler!=\"\"})` over all scalers", bestPracticeDeprecatedMsg), - }, - []string{}, - ) scalerErrors = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: DefaultPromMetricsNamespace, @@ -118,15 +86,6 @@ var ( }, metricLabels, ) - scaledObjectErrorsDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaled_object", - Name: "errors", - Help: fmt.Sprintf("%v use 'keda_scaled_object_errors_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"namespace", "scaledObject"}, - ) scaledObjectErrors = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: DefaultPromMetricsNamespace, @@ -136,15 +95,6 @@ var ( }, []string{"namespace", "scaledObject"}, ) - scaledJobErrorsDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaled_job", - Name: "errors", - Help: fmt.Sprintf("%v use 'keda_scaled_job_errors_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"namespace", "scaledJob"}, - ) scaledJobErrors = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: DefaultPromMetricsNamespace, @@ -154,16 +104,6 @@ var ( }, []string{"namespace", "scaledJob"}, ) - - triggerTotalsGaugeVecDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "trigger", - Name: "totals", - Help: fmt.Sprintf("%v use 'keda_trigger_registered_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"type"}, - ) triggerRegistered = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -173,15 +113,6 @@ var ( }, []string{"type"}, ) - crdTotalsGaugeVecDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "resource", - Name: "totals", - Help: fmt.Sprintf("%v use 'keda_resource_registered_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"type", "namespace"}, - ) crdRegistered = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -191,15 +122,6 @@ var ( }, []string{"type", "namespace"}, ) - internalLoopLatencyDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "internal_scale_loop", - Name: "latency", - Help: fmt.Sprintf("%v use 'keda_internal_scale_loop_latency_seconds' instead.", bestPracticeDeprecatedMsg), - }, - []string{"namespace", "type", "resource"}, - ) internalLoopLatency = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -236,25 +158,17 @@ type PromMetrics struct { } func NewPromMetrics() *PromMetrics { - metrics.Registry.MustRegister(scalerErrorsTotalDeprecated) metrics.Registry.MustRegister(scalerMetricsValue) - metrics.Registry.MustRegister(scalerMetricsLatencyDeprecated) metrics.Registry.MustRegister(scalerMetricsLatency) - metrics.Registry.MustRegister(internalLoopLatencyDeprecated) metrics.Registry.MustRegister(internalLoopLatency) metrics.Registry.MustRegister(scalerActive) - metrics.Registry.MustRegister(scalerErrorsDeprecated) metrics.Registry.MustRegister(scalerErrors) - metrics.Registry.MustRegister(scaledObjectErrorsDeprecated) metrics.Registry.MustRegister(scaledObjectErrors) metrics.Registry.MustRegister(scaledObjectPaused) metrics.Registry.MustRegister(triggerRegistered) metrics.Registry.MustRegister(crdRegistered) - metrics.Registry.MustRegister(scaledJobErrorsDeprecated) metrics.Registry.MustRegister(scaledJobErrors) - metrics.Registry.MustRegister(triggerTotalsGaugeVecDeprecated) - metrics.Registry.MustRegister(crdTotalsGaugeVecDeprecated) metrics.Registry.MustRegister(buildInfo) metrics.Registry.MustRegister(cloudeventEmitted) @@ -277,13 +191,11 @@ func (p *PromMetrics) RecordScalerMetric(namespace string, scaledResource string // RecordScalerLatency create a measurement of the latency to external metric func (p *PromMetrics) RecordScalerLatency(namespace string, scaledResource string, scaler string, triggerIndex int, metric string, isScaledObject bool, value time.Duration) { scalerMetricsLatency.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Set(value.Seconds()) - scalerMetricsLatencyDeprecated.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Set(float64(value.Milliseconds())) } // RecordScalableObjectLatency create a measurement of the latency executing scalable object loop func (p *PromMetrics) RecordScalableObjectLatency(namespace string, name string, isScaledObject bool, value time.Duration) { internalLoopLatency.WithLabelValues(namespace, getResourceType(isScaledObject), name).Set(value.Seconds()) - internalLoopLatencyDeprecated.WithLabelValues(namespace, getResourceType(isScaledObject), name).Set(float64(value.Milliseconds())) } // RecordScalerActive create a measurement of the activity of the scaler @@ -312,9 +224,7 @@ func (p *PromMetrics) RecordScaledObjectPaused(namespace string, scaledObject st func (p *PromMetrics) RecordScalerError(namespace string, scaledResource string, scaler string, triggerIndex int, metric string, isScaledObject bool, err error) { if err != nil { scalerErrors.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Inc() - scalerErrorsDeprecated.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Inc() p.RecordScaledObjectError(namespace, scaledResource, err) - scalerErrorsTotalDeprecated.With(prometheus.Labels{}).Inc() return } // initialize metric with 0 if not already set @@ -322,10 +232,6 @@ func (p *PromMetrics) RecordScalerError(namespace string, scaledResource string, if errscaler != nil { log.Error(errscaler, "Unable to record metrics: %v") } - _, errscalerdep := scalerErrorsDeprecated.GetMetricWith(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)) - if errscalerdep != nil { - log.Error(errscaler, "Unable to record (deprecated) metrics: %v") - } } // RecordScaledObjectError counts the number of errors with the scaled object @@ -333,7 +239,6 @@ func (p *PromMetrics) RecordScaledObjectError(namespace string, scaledObject str labels := prometheus.Labels{"namespace": namespace, "scaledObject": scaledObject} if err != nil { scaledObjectErrors.With(labels).Inc() - scaledObjectErrorsDeprecated.With(labels).Inc() return } // initialize metric with 0 if not already set @@ -342,18 +247,12 @@ func (p *PromMetrics) RecordScaledObjectError(namespace string, scaledObject str log.Error(errscaledobject, "Unable to record metrics: %v") return } - _, errscaledobjectdep := scaledObjectErrorsDeprecated.GetMetricWith(labels) - if errscaledobjectdep != nil { - log.Error(errscaledobject, "Unable to record metrics: %v") - return - } } // RecordScaledJobError counts the number of errors with the scaled job func (p *PromMetrics) RecordScaledJobError(namespace string, scaledJob string, err error) { labels := prometheus.Labels{"namespace": namespace, "scaledJob": scaledJob} if err != nil { - scaledJobErrorsDeprecated.With(labels).Inc() scaledJobErrors.With(labels).Inc() return } @@ -379,14 +278,12 @@ func getResourceType(isScaledObject bool) string { func (p *PromMetrics) IncrementTriggerTotal(triggerType string) { if triggerType != "" { triggerRegistered.WithLabelValues(triggerType).Inc() - triggerTotalsGaugeVecDeprecated.WithLabelValues(triggerType).Inc() } } func (p *PromMetrics) DecrementTriggerTotal(triggerType string) { if triggerType != "" { triggerRegistered.WithLabelValues(triggerType).Dec() - triggerTotalsGaugeVecDeprecated.WithLabelValues(triggerType).Dec() } } @@ -396,7 +293,6 @@ func (p *PromMetrics) IncrementCRDTotal(crdType, namespace string) { } crdRegistered.WithLabelValues(crdType, namespace).Inc() - crdTotalsGaugeVecDeprecated.WithLabelValues(crdType, namespace).Inc() } func (p *PromMetrics) DecrementCRDTotal(crdType, namespace string) { @@ -405,7 +301,6 @@ func (p *PromMetrics) DecrementCRDTotal(crdType, namespace string) { } crdRegistered.WithLabelValues(crdType, namespace).Dec() - crdTotalsGaugeVecDeprecated.WithLabelValues(crdType, namespace).Dec() } // RecordCloudEventEmitted counts the number of cloudevent that emitted to user's sink From 3a7c955257b85c99126ad186e379c66fd4772207 Mon Sep 17 00:00:00 2001 From: rickbrouwer Date: Tue, 26 Nov 2024 13:58:14 +0100 Subject: [PATCH 2/3] Fix test accordingly pr 5174 Signed-off-by: rickbrouwer --- .../prometheus_metrics_test.go | 144 +++++------------- 1 file changed, 40 insertions(+), 104 deletions(-) diff --git a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go index 9593d13d5cf..76f166a4a2e 100644 --- a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go +++ b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go @@ -444,7 +444,6 @@ func TestPrometheusMetrics(t *testing.T) { testScaledObjectErrors(t, data) testScaledJobErrors(t, data) testScalerErrors(t, data) - testScalerErrorsTotal(t, data) testOperatorMetrics(t, kc, data) testMetricServerMetrics(t) testWebhookMetrics(t, data) @@ -520,6 +519,8 @@ func testScalerMetricValue(t *testing.T) { } } assert.Equal(t, true, found) + } else { + t.Errorf("metric keda_scaler_metrics_value not available") } } @@ -534,29 +535,21 @@ func testScaledObjectErrors(t *testing.T, data templateData) { time.Sleep(20 * time.Second) family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaled_object_errors"] - assert.True(t, ok, "keda_scaled_object_errors not available") - valTotal, okTotal := family["keda_scaled_object_errors_total"] - assert.True(t, okTotal, "keda_scaled_object_errors_total not available") - if ok && okTotal { + val, ok := family["keda_scaled_object_errors_total"] + assert.True(t, ok, "keda_scaled_object_errors_total not available") + if ok { errCounterVal1 := getErrorMetricsValue(val) - errCounterValTotal1 := getErrorMetricsValue(valTotal) // wait for 2 seconds as pollinginterval is 2 time.Sleep(2 * time.Second) family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaled_object_errors"] - assert.True(t, ok, "keda_scaled_object_errors not available") - valTotal, okTotal := family["keda_scaled_object_errors_total"] - assert.True(t, okTotal, "keda_scaled_object_errors_total not available") - if ok && okTotal { + val, ok := family["keda_scaled_object_errors_total"] + assert.True(t, ok, "keda_scaled_object_errors_total not available") + if ok { errCounterVal2 := getErrorMetricsValue(val) - errCounterValTotal2 := getErrorMetricsValue(valTotal) assert.NotEqual(t, errCounterVal2, float64(0)) - assert.NotEqual(t, errCounterValTotal2, float64(0)) assert.GreaterOrEqual(t, errCounterVal2, errCounterVal1) - assert.GreaterOrEqual(t, errCounterValTotal2, errCounterValTotal1) } } @@ -576,34 +569,26 @@ func testScaledJobErrors(t *testing.T, data templateData) { time.Sleep(20 * time.Second) family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaled_job_errors"] - assert.True(t, ok, "keda_scaled_job_errors not available") - valTotal, okTotal := family["keda_scaled_job_errors_total"] - assert.True(t, okTotal, "keda_scaled_job_errors_total not available") - if ok && okTotal { + val, ok := family["keda_scaled_job_errors_total"] + assert.True(t, ok, "keda_scaled_job_errors_total not available") + if ok { errCounterVal1 := getErrorMetricsValue(val) - errCounterValTotal1 := getErrorMetricsValue(valTotal) // wait for 2 seconds as pollinginterval is 2 time.Sleep(2 * time.Second) family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaled_job_errors"] - assert.True(t, ok, "keda_scaled_job_errors not available") - valTotal, okTotal := family["keda_scaled_job_errors_total"] - assert.True(t, okTotal, "keda_scaled_job_errors_total not available") - if ok && okTotal { + val, ok := family["keda_scaled_job_errors_total"] + assert.True(t, ok, "keda_scaled_job_errors_total not available") + if ok { errCounterVal2 := getErrorMetricsValue(val) - errCounterValTotal2 := getErrorMetricsValue(valTotal) assert.NotEqual(t, errCounterVal2, float64(0)) - assert.NotEqual(t, errCounterValTotal2, float64(0)) assert.GreaterOrEqual(t, errCounterVal2, errCounterVal1) - assert.GreaterOrEqual(t, errCounterValTotal2, errCounterValTotal1) } else { - t.Errorf("metric not available") + t.Errorf("metric keda_scaled_job_errors_total not available") } } else { - t.Errorf("metric not available") + t.Errorf("metric keda_scaled_job_errors_total not available") } KubectlDeleteWithTemplate(t, data, "wrongScaledJobTemplate", wrongScaledJobTemplate) @@ -622,39 +607,6 @@ func testScalerErrors(t *testing.T, data templateData) { time.Sleep(2 * time.Second) KubectlApplyWithTemplate(t, data, "wrongScaledJobTemplate", wrongScaledJobTemplate) - family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaler_errors"] - assert.True(t, ok, "keda_scaler_errors not available") - if ok { - errCounterVal1 := getErrorMetricsValue(val) - - // wait for 20 seconds to correctly fetch metrics. - time.Sleep(20 * time.Second) - - family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaler_errors"] - assert.True(t, ok, "keda_scaler_errors not available") - if ok { - errCounterVal2 := getErrorMetricsValue(val) - assert.NotEqual(t, errCounterVal2, float64(0)) - assert.GreaterOrEqual(t, errCounterVal2, errCounterVal1) - } - } - KubectlDeleteWithTemplate(t, data, "wrongScaledJobTemplate", wrongScaledJobTemplate) - time.Sleep(2 * time.Second) - KubectlApplyWithTemplate(t, data, "scaledJobTemplate", scaledJobTemplate) - - KubectlDeleteWithTemplate(t, data, "wrongScaledObjectTemplate", wrongScaledObjectTemplate) - time.Sleep(2 * time.Second) - KubectlApplyWithTemplate(t, data, "scaledObjectTemplate", scaledObjectTemplate) -} - -func testScalerErrorsTotal(t *testing.T, data templateData) { - t.Log("--- testing scaler errors total ---") - - KubectlDeleteWithTemplate(t, data, "scaledObjectTemplate", scaledObjectTemplate) - KubectlApplyWithTemplate(t, data, "wrongScaledObjectTemplate", wrongScaledObjectTemplate) - family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) val, ok := family["keda_scaler_errors_total"] assert.True(t, ok, "keda_scaler_errors_total not available") @@ -664,8 +616,8 @@ func testScalerErrorsTotal(t *testing.T, data templateData) { errCounterVal1 := getErrorMetricsValue(val) errCounterValDetail1 := getErrorMetricsValue(valDetail) - // wait for 2 seconds as pollinginterval is 2 - time.Sleep(2 * time.Second) + // wait for 20 seconds to correctly fetch metrics. + time.Sleep(20 * time.Second) family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) val, ok := family["keda_scaler_errors_total"] @@ -682,6 +634,10 @@ func testScalerErrorsTotal(t *testing.T, data templateData) { } } + KubectlDeleteWithTemplate(t, data, "wrongScaledJobTemplate", wrongScaledJobTemplate) + time.Sleep(2 * time.Second) + KubectlApplyWithTemplate(t, data, "scaledJobTemplate", scaledJobTemplate) + KubectlDeleteWithTemplate(t, data, "wrongScaledObjectTemplate", wrongScaledObjectTemplate) time.Sleep(2 * time.Second) KubectlApplyWithTemplate(t, data, "scaledObjectTemplate", scaledObjectTemplate) @@ -689,11 +645,6 @@ func testScalerErrorsTotal(t *testing.T, data templateData) { func getErrorMetricsValue(val *prommodel.MetricFamily) float64 { switch val.GetName() { - case "keda_scaler_errors_total": - metrics := val.GetMetric() - for _, metric := range metrics { - return metric.GetCounter().GetValue() - } case "keda_scaler_detail_errors_total": metrics := val.GetMetric() result := 0. @@ -701,16 +652,6 @@ func getErrorMetricsValue(val *prommodel.MetricFamily) float64 { result += metric.GetCounter().GetValue() } return result - case "keda_scaled_object_errors": - metrics := val.GetMetric() - for _, metric := range metrics { - labels := metric.GetLabel() - for _, label := range labels { - if *label.Name == "scaledObject" && *label.Value == wrongScaledObjectName { - return *metric.Counter.Value - } - } - } case "keda_scaled_object_errors_total": metrics := val.GetMetric() for _, metric := range metrics { @@ -721,16 +662,6 @@ func getErrorMetricsValue(val *prommodel.MetricFamily) float64 { } } } - case "keda_scaled_job_errors": - metrics := val.GetMetric() - for _, metric := range metrics { - labels := metric.GetLabel() - for _, label := range labels { - if *label.Name == "scaledJob" && *label.Value == wrongScaledJobName { - return *metric.Counter.Value - } - } - } case "keda_scaled_job_errors_total": metrics := val.GetMetric() for _, metric := range metrics { @@ -741,7 +672,7 @@ func getErrorMetricsValue(val *prommodel.MetricFamily) float64 { } } } - case "keda_scaler_errors": + case "keda_scaler_errors_total": metrics := val.GetMetric() for _, metric := range metrics { labels := metric.GetLabel() @@ -819,6 +750,8 @@ func testScalerMetricLatency(t *testing.T) { } } assert.Equal(t, true, found) + } else { + t.Errorf("metric keda_scaler_metrics_latency_seconds not available") } } @@ -827,7 +760,7 @@ func testScalableObjectMetrics(t *testing.T) { family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - if val, ok := family["keda_internal_scale_loop_latency"]; ok { + if val, ok := family["keda_internal_scale_loop_latency_seconds"]; ok { var found bool metrics := val.GetMetric() @@ -885,7 +818,7 @@ func testScalableObjectMetrics(t *testing.T) { } assert.Equal(t, true, found) } else { - t.Errorf("scaledobject metric not available") + t.Errorf("keda_internal_scale_loop_latency_seconds metric not available") } } @@ -910,6 +843,8 @@ func testScalerActiveMetric(t *testing.T) { } } assert.Equal(t, true, found) + } else { + t.Errorf("metric keda_scaler_active not available") } } @@ -1041,6 +976,7 @@ func checkBuildInfo(t *testing.T, families map[string]*prommodel.MetricFamily) { family, ok := families["keda_build_info"] assert.True(t, ok, "keda_build_info not available") if !ok { + t.Errorf("metric keda_build_info not available") return } @@ -1075,8 +1011,8 @@ func getLatestCommit(t *testing.T) string { func checkTriggerTotalValues(t *testing.T, families map[string]*prommodel.MetricFamily, expectedValues map[string]int) { t.Log("--- testing trigger total metrics ---") expected := map[string]int{} - family, ok := families["keda_trigger_totals"] - assert.True(t, ok, "keda_trigger_totals not available") + family, ok := families["keda_trigger_registered_total"] + assert.True(t, ok, "keda_trigger_registered_total not available") if !ok { return } @@ -1129,8 +1065,8 @@ func checkTriggerTotalValues(t *testing.T, families map[string]*prommodel.Metric func checkCRTotalValues(t *testing.T, families map[string]*prommodel.MetricFamily, expected map[string]map[string]int) { t.Log("--- testing resource total metrics ---") - family, ok := families["keda_resource_totals"] - assert.True(t, ok, "keda_resource_totals not available") + family, ok := families["keda_resource_registered_total"] + assert.True(t, ok, "keda_resource_registered_total not available") if !ok { return } @@ -1362,9 +1298,9 @@ func checkGRPCClientMetrics(t *testing.T, families map[string]*prommodel.MetricF func checkWebhookValues(t *testing.T, families map[string]*prommodel.MetricFamily) { t.Log("--- testing webhook metrics ---") - family, ok := families["keda_webhook_scaled_object_validation_errors"] + family, ok := families["keda_webhook_scaled_object_validation_errors_total"] if !ok { - t.Errorf("metric keda_webhook_scaled_object_validation_errors not available") + t.Errorf("metric keda_webhook_scaled_object_validation_errors_total not available") return } @@ -1379,11 +1315,11 @@ func checkWebhookValues(t *testing.T, families map[string]*prommodel.MetricFamil } metricValue += *metric.Counter.Value } - assert.GreaterOrEqual(t, metricValue, 1.0, "keda_webhook_scaled_object_validation_errors has to be greater than 0") + assert.GreaterOrEqual(t, metricValue, 1.0, "keda_webhook_scaled_object_validation_errors_total has to be greater than 0") - family, ok = families["keda_webhook_scaled_object_validation_total"] + family, ok = families["keda_webhook_scaled_object_validations_total"] if !ok { - t.Errorf("metric keda_webhook_scaled_object_validation_total not available") + t.Errorf("metric keda_webhook_scaled_object_validations_total not available") return } @@ -1398,7 +1334,7 @@ func checkWebhookValues(t *testing.T, families map[string]*prommodel.MetricFamil } metricValue += *metric.Counter.Value } - assert.GreaterOrEqual(t, metricValue, 1.0, "keda_webhook_scaled_object_validation_total has to be greater than 0") + assert.GreaterOrEqual(t, metricValue, 1.0, "keda_webhook_scaled_object_validations_total has to be greater than 0") } func checkMetricServerValues(t *testing.T, families map[string]*prommodel.MetricFamily) { From ed7379c08d390c563d44fcf28bafe58ba7781458 Mon Sep 17 00:00:00 2001 From: Rick Brouwer Date: Tue, 26 Nov 2024 20:40:04 +0100 Subject: [PATCH 3/3] Fix test Signed-off-by: Rick Brouwer --- .../prometheus_metrics_test.go | 32 ++----------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go index 76f166a4a2e..da27f3948a4 100644 --- a/tests/sequential/prometheus_metrics/prometheus_metrics_test.go +++ b/tests/sequential/prometheus_metrics/prometheus_metrics_test.go @@ -608,28 +608,20 @@ func testScalerErrors(t *testing.T, data templateData) { KubectlApplyWithTemplate(t, data, "wrongScaledJobTemplate", wrongScaledJobTemplate) family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaler_errors_total"] - assert.True(t, ok, "keda_scaler_errors_total not available") valDetail, okDetail := family["keda_scaler_detail_errors_total"] assert.True(t, okDetail, "keda_scaler_detail_errors_total not available") - if ok && okDetail { - errCounterVal1 := getErrorMetricsValue(val) + if okDetail { errCounterValDetail1 := getErrorMetricsValue(valDetail) // wait for 20 seconds to correctly fetch metrics. time.Sleep(20 * time.Second) family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaler_errors_total"] - assert.True(t, ok, "keda_scaler_errors_total not available") valDetail, okDetail := family["keda_scaler_detail_errors_total"] assert.True(t, okDetail, "keda_scaler_detail_errors_total not available") - if ok && okDetail { - errCounterVal2 := getErrorMetricsValue(val) + if okDetail { errCounterValDetail2 := getErrorMetricsValue(valDetail) - assert.NotEqual(t, errCounterVal2, float64(0)) assert.NotEqual(t, errCounterValDetail2, float64(0)) - assert.GreaterOrEqual(t, errCounterVal2, errCounterVal1) assert.GreaterOrEqual(t, errCounterValDetail2, errCounterValDetail1) } } @@ -716,25 +708,7 @@ func testScalerMetricLatency(t *testing.T) { family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) - val, ok := family["keda_scaler_metrics_latency"] - assert.True(t, ok, "keda_scaler_metrics_latency not available") - if ok { - var found bool - metrics := val.GetMetric() - for _, metric := range metrics { - labels := metric.GetLabel() - for _, label := range labels { - if (*label.Name == labelScaledObject && *label.Value == scaledObjectName) || - (*label.Name == labelScaledJob && *label.Value == scaledJobName) { - assert.Equal(t, float64(0), *metric.Gauge.Value) - found = true - } - } - } - assert.Equal(t, true, found) - } - - val, ok = family["keda_scaler_metrics_latency_seconds"] + val, ok := family["keda_scaler_metrics_latency_seconds"] assert.True(t, ok, "keda_scaler_metrics_latency_seconds not available") if ok { var found bool