-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reworks the prometheus metrics to adhere to best practices #5174
Closed
wonko
wants to merge
17
commits into
kedacore:main
from
wonko:feature/rework-prometheus-metric-names
Closed
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a08cc7c
Reworks the prometheus metrics to adhere to best practices
wonko 4521af3
Updates help info to align with the public docs
wonko a0e5ab8
Updates grafana dashboard to use the new metrics
wonko 571419b
resolved review comments
wonko c557a34
Updates webhook metrics and e2e tests
wonko 2fae5f3
newline at the end of json :thinking_face:
wonko 7158f7f
correct tests
wonko 49aaff2
another go at the newline issue
wonko 623d4c7
Reworked otel metrics to align with best practices
wonko 13ca4a5
updated E2E tests for Otel
wonko d72b860
Handled -> Registered
wonko fd45826
align namespace naming to not be pluralized
wonko f97a650
rewrite the metric names in the tests
wonko 36ca55a
even more rewriting ... :facepalm:
wonko 8c97d52
Merge branch 'main' into feature/rework-prometheus-metric-names
wonko 3a85292
Tuning merge
wonko 388be0f
fixing tests
wonko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |||||
"fmt" | ||||||
"runtime" | ||||||
"strconv" | ||||||
"time" | ||||||
|
||||||
"go.opentelemetry.io/otel" | ||||||
"go.opentelemetry.io/otel/attribute" | ||||||
|
@@ -22,12 +23,14 @@ const meterName = "keda-open-telemetry-metrics" | |||||
const defaultNamespace = "default" | ||||||
|
||||||
var ( | ||||||
meterProvider *metric.MeterProvider | ||||||
meter api.Meter | ||||||
otScalerErrorsCounter api.Int64Counter | ||||||
otScaledObjectErrorsCounter api.Int64Counter | ||||||
otTriggerTotalsCounter api.Int64UpDownCounter | ||||||
otCrdTotalsCounter api.Int64UpDownCounter | ||||||
meterProvider *metric.MeterProvider | ||||||
meter api.Meter | ||||||
otScalerErrorsCounter api.Int64Counter | ||||||
otScaledObjectErrorsCounter api.Int64Counter | ||||||
otTriggerTotalsCounterDeprecated api.Int64UpDownCounter | ||||||
otCrdTotalsCounterDeprecated api.Int64UpDownCounter | ||||||
otTriggerRegisteredTotalsCounter api.Int64UpDownCounter | ||||||
otCrdRegisteredTotalsCounter api.Int64UpDownCounter | ||||||
|
||||||
otelScalerMetricVal OtelMetricFloat64Val | ||||||
otelScalerMetricsLatencyVal OtelMetricFloat64Val | ||||||
|
@@ -86,19 +89,29 @@ func initMeters() { | |||||
otLog.Error(err, msg) | ||||||
} | ||||||
|
||||||
otTriggerTotalsCounter, err = meter.Int64UpDownCounter("keda.trigger.totals", api.WithDescription("Total triggers")) | ||||||
otTriggerTotalsCounterDeprecated, err = meter.Int64UpDownCounter("keda.trigger.totals", api.WithDescription("DEPRECATED - will be removed in 2.15 - use 'keda.triggers.count' instead")) | ||||||
if err != nil { | ||||||
otLog.Error(err, msg) | ||||||
} | ||||||
|
||||||
otCrdTotalsCounter, err = meter.Int64UpDownCounter("keda.resource.totals", api.WithDescription("Total resources")) | ||||||
otTriggerRegisteredTotalsCounter, err = meter.Int64UpDownCounter("keda.trigger.registered.count", api.WithDescription("Total number of triggers per trigger type registered")) | ||||||
if err != nil { | ||||||
otLog.Error(err, msg) | ||||||
} | ||||||
|
||||||
otCrdTotalsCounterDeprecated, err = meter.Int64UpDownCounter("keda.resource.totals", api.WithDescription("DEPRECATED - will be removed in 2.15 - use 'keda.resources.count' instead")) | ||||||
if err != nil { | ||||||
otLog.Error(err, msg) | ||||||
} | ||||||
|
||||||
otCrdRegisteredTotalsCounter, err = meter.Int64UpDownCounter("keda.resource.registered.count", api.WithDescription("Total number of KEDA custom resources per namespace for each custom resource type (CRD) registered")) | ||||||
if err != nil { | ||||||
otLog.Error(err, msg) | ||||||
} | ||||||
|
||||||
_, err = meter.Float64ObservableGauge( | ||||||
"keda.scaler.metrics.value", | ||||||
api.WithDescription("Metric Value used for HPA"), | ||||||
api.WithDescription("The current value for each scaler's metric that would be used by the HPA in computing the target average"), | ||||||
api.WithFloat64Callback(ScalerMetricValueCallback), | ||||||
) | ||||||
if err != nil { | ||||||
|
@@ -107,7 +120,8 @@ func initMeters() { | |||||
|
||||||
_, err = meter.Float64ObservableGauge( | ||||||
"keda.scaler.metrics.latency", | ||||||
api.WithDescription("Scaler Metrics Latency"), | ||||||
api.WithDescription("The latency of retrieving current metric from each scaler"), | ||||||
api.WithUnit("s"), | ||||||
api.WithFloat64Callback(ScalerMetricsLatencyCallback), | ||||||
) | ||||||
if err != nil { | ||||||
|
@@ -117,6 +131,7 @@ func initMeters() { | |||||
_, err = meter.Float64ObservableGauge( | ||||||
"keda.internal.scale.loop.latency", | ||||||
api.WithDescription("Internal latency of ScaledObject/ScaledJob loop execution"), | ||||||
api.WithUnit("s"), | ||||||
api.WithFloat64Callback(ScalableObjectLatencyCallback), | ||||||
) | ||||||
if err != nil { | ||||||
|
@@ -125,7 +140,7 @@ func initMeters() { | |||||
|
||||||
_, err = meter.Float64ObservableGauge( | ||||||
"keda.scaler.active", | ||||||
api.WithDescription("Activity of a Scaler Metric"), | ||||||
api.WithDescription("Indicates whether a scaler is active (1), or not (0)"), | ||||||
api.WithFloat64Callback(ScalerActiveCallback), | ||||||
) | ||||||
if err != nil { | ||||||
|
@@ -185,8 +200,8 @@ func ScalerMetricsLatencyCallback(_ context.Context, obsrv api.Float64Observer) | |||||
} | ||||||
|
||||||
// RecordScalerLatency create a measurement of the latency to external metric | ||||||
func (o *OtelMetrics) RecordScalerLatency(namespace string, scaledObject string, scaler string, scalerIndex int, metric string, value float64) { | ||||||
otelScalerMetricsLatencyVal.val = value | ||||||
func (o *OtelMetrics) RecordScalerLatency(namespace string, scaledObject string, scaler string, scalerIndex int, metric string, value time.Duration) { | ||||||
otelScalerMetricsLatencyVal.val = value.Seconds() | ||||||
otelScalerMetricsLatencyVal.measurementOption = getScalerMeasurementOption(namespace, scaledObject, scaler, scalerIndex, metric) | ||||||
} | ||||||
|
||||||
|
@@ -199,7 +214,7 @@ func ScalableObjectLatencyCallback(_ context.Context, obsrv api.Float64Observer) | |||||
} | ||||||
|
||||||
// RecordScalableObjectLatency create a measurement of the latency executing scalable object loop | ||||||
func (o *OtelMetrics) RecordScalableObjectLatency(namespace string, name string, isScaledObject bool, value float64) { | ||||||
func (o *OtelMetrics) RecordScalableObjectLatency(namespace string, name string, isScaledObject bool, value time.Duration) { | ||||||
resourceType := "scaledjob" | ||||||
if isScaledObject { | ||||||
resourceType = "scaledobject" | ||||||
|
@@ -210,7 +225,7 @@ func (o *OtelMetrics) RecordScalableObjectLatency(namespace string, name string, | |||||
attribute.Key("type").String(resourceType), | ||||||
attribute.Key("name").String(name)) | ||||||
|
||||||
otelInternalLoopLatencyVal.val = value | ||||||
otelInternalLoopLatencyVal.val = value.Seconds() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's been settled that KEDA will use |
||||||
otelInternalLoopLatencyVal.measurementOption = opt | ||||||
} | ||||||
|
||||||
|
@@ -281,13 +296,15 @@ func (o *OtelMetrics) RecordScaledObjectError(namespace string, scaledObject str | |||||
|
||||||
func (o *OtelMetrics) IncrementTriggerTotal(triggerType string) { | ||||||
if triggerType != "" { | ||||||
otTriggerTotalsCounter.Add(context.Background(), 1, api.WithAttributes(attribute.Key("type").String(triggerType))) | ||||||
otTriggerTotalsCounterDeprecated.Add(context.Background(), 1, api.WithAttributes(attribute.Key("type").String(triggerType))) | ||||||
otTriggerRegisteredTotalsCounter.Add(context.Background(), 1, api.WithAttributes(attribute.Key("type").String(triggerType))) | ||||||
} | ||||||
} | ||||||
|
||||||
func (o *OtelMetrics) DecrementTriggerTotal(triggerType string) { | ||||||
if triggerType != "" { | ||||||
otTriggerTotalsCounter.Add(context.Background(), -1, api.WithAttributes(attribute.Key("type").String(triggerType))) | ||||||
otTriggerTotalsCounterDeprecated.Add(context.Background(), -1, api.WithAttributes(attribute.Key("type").String(triggerType))) | ||||||
otTriggerRegisteredTotalsCounter.Add(context.Background(), -1, api.WithAttributes(attribute.Key("type").String(triggerType))) | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -300,7 +317,8 @@ func (o *OtelMetrics) IncrementCRDTotal(crdType, namespace string) { | |||||
attribute.Key("type").String(crdType), | ||||||
) | ||||||
|
||||||
otCrdTotalsCounter.Add(context.Background(), 1, opt) | ||||||
otCrdTotalsCounterDeprecated.Add(context.Background(), 1, opt) | ||||||
otCrdRegisteredTotalsCounter.Add(context.Background(), 1, opt) | ||||||
} | ||||||
|
||||||
func (o *OtelMetrics) DecrementCRDTotal(crdType, namespace string) { | ||||||
|
@@ -312,7 +330,8 @@ func (o *OtelMetrics) DecrementCRDTotal(crdType, namespace string) { | |||||
attribute.Key("namespace").String(namespace), | ||||||
attribute.Key("type").String(crdType), | ||||||
) | ||||||
otCrdTotalsCounter.Add(context.Background(), -1, opt) | ||||||
otCrdTotalsCounterDeprecated.Add(context.Background(), -1, opt) | ||||||
otCrdRegisteredTotalsCounter.Add(context.Background(), -1, opt) | ||||||
} | ||||||
|
||||||
func getScalerMeasurementOption(namespace string, scaledObject string, scaler string, scalerIndex int, metric string) api.MeasurementOption { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's been settled that KEDA will use
Seconds
in opentelemetry metrics.