Skip to content

Commit 8657c2a

Browse files
committed
update metrics names and dots are used instead of underscores for otel
Signed-off-by: Elieser Pereira <[email protected]>
1 parent bdcef77 commit 8657c2a

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

docs/operate.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ Optional variables
6464
# Configuring metrics for the KEDA HTTP Add-on Operator
6565

6666
### Exportable metrics:
67-
* **operator_http_scaled_object_count** - the number of http_scaled_object
67+
* **keda_http_scaled_object_total** - the number of http_scaled_objects
6868

6969
There are currently 2 supported methods for exposing metrics from the operator - via a Prometheus compatible metrics endpoint or by pushing metrics to a OTEL HTTP collector.
7070

7171
### Configuring the Prometheus compatible metrics endpoint
7272
When configured, the operator can expose metrics on a Prometheus compatible endpoint.
7373

74-
This endpoint can be enabled by setting the `OTEL_PROM_EXPORTER_ENABLED` environment variable to `true` on the operator deployment (`true` by default) and by setting `OTEL_PROM_EXPORTER_PORT` to an unused port for the endpoint to be made avaialble on (`2223` by default).
74+
This endpoint can be enabled by setting the `OTEL_PROM_EXPORTER_ENABLED` environment variable to `true` on the operator deployment (`true` by default) and by setting `OTEL_PROM_EXPORTER_PORT` to an unused port for the endpoint to be made avaialble on (`8080` by default).
7575

7676
### Configuring the OTEL HTTP exporter
7777
When configured, the ioperator can export metrics to a OTEL HTTP collector.

operator/metrics/otelmetrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewOtelMetrics(options ...metric.Option) *OtelMetrics {
4343
provider := metric.NewMeterProvider(options...)
4444
meter := provider.Meter(meterName)
4545

46-
httpScaledObjectCounter, err := meter.Int64UpDownCounter("operator_http_scaled_object_count", api.WithDescription("a counter of http_scaled_objects processed by the operator"))
46+
httpScaledObjectCounter, err := meter.Int64UpDownCounter("keda.http.scaled.object.total", api.WithDescription("a counter of http_scaled_objects processed by the operator"))
4747
if err != nil {
4848
log.Fatalf("could not create new otelhttpmetric request counter: %v", err)
4949
}

operator/metrics/otelmetrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestHTTPScaledObjectCount(t *testing.T) {
2929
scopeMetrics := got.ScopeMetrics[0]
3030
assert.NotEqual(t, len(scopeMetrics.Metrics), 0)
3131

32-
metricInfo := retrieveMetric(scopeMetrics.Metrics, "operator_http_scaled_object_count")
32+
metricInfo := retrieveMetric(scopeMetrics.Metrics, "keda.http.scaled.object.total")
3333
data := metricInfo.Data.(metricdata.Sum[int64]).DataPoints[0]
3434
assert.Equal(t, data.Value, int64(1))
3535
}

operator/metrics/prommetrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewPrometheusMetrics(options ...prometheus.Option) *PrometheusMetrics {
4242
)
4343
meter := provider.Meter(meterName)
4444

45-
httpScaledObjectCounter, err := meter.Int64UpDownCounter("operator_http_scaled_object_count", api.WithDescription("a counter of http_scaled_objects processed by the operator"))
45+
httpScaledObjectCounter, err := meter.Int64UpDownCounter("keda_http_scaled_object_total", api.WithDescription("a counter of http_scaled_objects processed by the operator"))
4646
if err != nil {
4747
log.Fatalf("could not create new Prometheus request counter: %v", err)
4848
}

operator/metrics/prommetrics_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func TestPromRequestCountMetric(t *testing.T) {
1515
options := []promexporter.Option{promexporter.WithRegisterer(testRegistry)}
1616
testPrometheus := NewPrometheusMetrics(options...)
1717
expectedOutput := `
18-
# HELP operator_http_scaled_object_count a counter of http_scaled_objects processed by the operator
19-
# TYPE operator_http_scaled_object_count gauge
20-
operator_http_scaled_object_count{namespace="test-namespace",otel_scope_name="keda-http-add-on-operator",otel_scope_version=""} 0
21-
operator_http_scaled_object_count{namespace="other-test-namespace",otel_scope_name="keda-http-add-on-operator",otel_scope_version=""} 1
18+
# HELP keda_http_scaled_object_total a counter of http_scaled_objects processed by the operator
19+
# TYPE keda_http_scaled_object_total gauge
20+
keda_http_scaled_object_total{namespace="test-namespace",otel_scope_name="keda-http-add-on-operator",otel_scope_version=""} 0
21+
keda_http_scaled_object_total{namespace="other-test-namespace",otel_scope_name="keda-http-add-on-operator",otel_scope_version=""} 1
2222
# HELP otel_scope_info Instrumentation Scope metadata
2323
# TYPE otel_scope_info gauge
2424
otel_scope_info{otel_scope_name="keda-http-add-on-operator",otel_scope_version=""} 1

tests/checks/operator_otel_metrics/operator_otel_metrics_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,16 @@ func TestMetricGeneration(t *testing.T) {
167167

168168
// Fetch metrics and validate them
169169
family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", otelCollectorPromURL))
170-
val, ok := family["operator_http_scaled_object_count"]
170+
val, ok := family["keda_http_scaled_object_total"]
171171
// If the metric is not found first time around then retry with a delay.
172172
if !ok {
173173
// Add a small sleep to allow metrics to be pushed from the exporter to the collector
174174
time.Sleep(10 * time.Second)
175175
// Fetch metrics and validate them
176176
family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", otelCollectorPromURL))
177-
val, ok = family["operator_http_scaled_object_count"]
177+
val, ok = family["keda_http_scaled_object_total"]
178178
}
179-
assert.True(t, ok, "operator_http_scaled_object_count is available")
179+
assert.True(t, ok, "keda_http_scaled_object_total is available")
180180

181181
requestCount := getMetricsValue(val)
182182
assert.GreaterOrEqual(t, requestCount, float64(1))
@@ -208,7 +208,7 @@ func fetchAndParsePrometheusMetrics(t *testing.T, cmd string) map[string]*prommo
208208
}
209209

210210
func getMetricsValue(val *prommodel.MetricFamily) float64 {
211-
if val.GetName() == "operator_http_scaled_object_count" {
211+
if val.GetName() == "keda_http_scaled_object_total" {
212212
metrics := val.GetMetric()
213213
for _, metric := range metrics {
214214
labels := metric.GetLabel()

tests/checks/operator_prometheus_metrics/operator_prometheus_metrics_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func TestMetricGeneration(t *testing.T) {
167167

168168
// Fetch metrics and validate them
169169
family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL))
170-
val, ok := family["operator_http_scaled_object_count"]
171-
assert.True(t, ok, "operator_http_scaled_object_count is available")
170+
val, ok := family["keda_http_scaled_object_total"]
171+
assert.True(t, ok, "keda_http_scaled_object_total is available")
172172

173173
requestCount := getMetricsValue(val)
174174
assert.GreaterOrEqual(t, requestCount, float64(1))
@@ -201,7 +201,7 @@ func fetchAndParsePrometheusMetrics(t *testing.T, cmd string) map[string]*prommo
201201
}
202202

203203
func getMetricsValue(val *prommodel.MetricFamily) float64 {
204-
if val.GetName() == "operator_http_scaled_object_count" {
204+
if val.GetName() == "keda_http_scaled_object_total" {
205205

206206
metrics := val.GetMetric()
207207
for _, metric := range metrics {

0 commit comments

Comments
 (0)