Skip to content

Commit d4aa1dc

Browse files
committed
fix: aligning the interceptor metrics vars with the OTEL spec
Signed-off-by: Joe Wogan <[email protected]>
1 parent b283195 commit d4aa1dc

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This changelog keeps track of work items that have been completed and are ready
3131

3232
### Fixes
3333

34+
- **General**: Align the interceptor metrics env var configuration with the OTEL spec ([#1031](https://github.com/kedacore/http-add-on/issues/1031))
3435
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
3536

3637
### Deprecations

config/interceptor/e2e-test/otel/deployment.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ spec:
99
containers:
1010
- name: interceptor
1111
env:
12-
- name: KEDA_HTTP_OTEL_PROM_EXPORTER_ENABLED
12+
- name: OTEL_PROM_EXPORTER_ENABLED
1313
value: "true"
14-
- name: KEDA_HTTP_OTEL_PROM_EXPORTER_PORT
14+
- name: OTEL_PROM_EXPORTER_PORT
1515
value: "2223"
16-
- name: KEDA_HTTP_OTEL_HTTP_EXPORTER_ENABLED
16+
- name: OTEL_EXPORTER_OTLP_METRICS_ENABLED
1717
value: "true"
18-
- name: KEDA_HTTP_OTEL_HTTP_COLLECTOR_ENDPOINT
18+
- name: OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
1919
value: "opentelemetry-collector.open-telemetry-system:4318"
20-
- name: KEDA_HTTP_OTEL_HTTP_COLLECTOR_INSECURE
20+
- name: OTEL_EXPORTER_OTLP_METRICS_INSECURE
2121
value: "true"
22-
- name: KEDA_HTTP_OTEL_METRIC_EXPORT_INTERVAL
22+
- name: OTEL_EXPORTER_OTLP_METRICS_EXPORT_INTERVAL
2323
value: "1"

docs/operate.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ There are currently 2 supported methods for exposing metrics from the intercepto
99
### Configuring the Prometheus compatible metrics endpoint
1010
When configured, the interceptor proxy can expose metrics on a Prometheus compatible endpoint.
1111

12-
This endpoint can be enabled by setting the `KEDA_HTTP_OTEL_PROM_EXPORTER_ENABLED` environment variable to `true` on the interceptor deployment (`true` by default) and by setting `KEDA_HTTP_OTEL_PROM_EXPORTER_PORT` to an unused port for the endpoint to be made avaialble on (`2223` by default).
12+
This endpoint can be enabled by setting the `OTEL_PROM_EXPORTER_ENABLED` environment variable to `true` on the interceptor 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).
1313

1414
### Configuring the OTEL HTTP exporter
1515
When configured, the interceptor proxy can export metrics to a OTEL HTTP collector.
1616

17-
The OTEL exporter can be enabled by setting the `KEDA_HTTP_OTEL_HTTP_EXPORTER_ENABLED` environment variable to `true` on the interceptor deployment (`false` by default). When enabled the `KEDA_HTTP_OTEL_HTTP_COLLECTOR_ENDPOINT` environment variable must also be configured so the exporter knows what collector to send the metrics to (e.g. opentelemetry-collector.open-telemetry-system:4318).
17+
The OTEL exporter can be enabled by setting the `OTEL_EXPORTER_OTLP_METRICS_ENABLED` environment variable to `true` on the interceptor deployment (`false` by default). When enabled the `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` environment variable must also be configured so the exporter knows what collector to send the metrics to (e.g. opentelemetry-collector.open-telemetry-system:4318).
1818

19-
If the collector is exposed on a unsecured endpoint then you can set the `KEDA_HTTP_OTEL_HTTP_COLLECTOR_INSECURE` environment variable to `true` (`false` by default) which will disable client security on the exporter.
19+
If the collector is exposed on a unsecured endpoint then you can set the `OTEL_EXPORTER_OTLP_METRICS_INSECURE` environment variable to `true` (`false` by default) which will disable client security on the exporter.
2020

21-
If you need to provide any headers such as authentication details in order to utilise your OTEL collector you can add them into the `KEDA_HTTP_OTEL_HTTP_HEADERS` environment variable. The frequency at which the metrics are exported can be configured by setting `KEDA_HTTP_OTEL_METRIC_EXPORT_INTERVAL` to the number of seconds you require between each export interval (`30` by default).
21+
If you need to provide any headers such as authentication details in order to utilise your OTEL collector you can add them into the `OTEL_EXPORTER_OTLP_METRICS_HEADERS` environment variable. The frequency at which the metrics are exported can be configured by setting `OTEL_EXPORTER_OTLP_METRICS_EXPORT_INTERVAL` to the number of seconds you require between each export interval (`30` by default).
2222

2323
# Configuring TLS for the KEDA HTTP Add-on interceptor proxy
2424

interceptor/config/metrics.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import (
77
// Metrics is the configuration for configuring metrics in the interceptor.
88
type Metrics struct {
99
// Sets whether or not to enable the Prometheus metrics exporter
10-
OtelPrometheusExporterEnabled bool `envconfig:"KEDA_HTTP_OTEL_PROM_EXPORTER_ENABLED" default:"true"`
10+
OtelPrometheusExporterEnabled bool `envconfig:"OTEL_PROM_EXPORTER_ENABLED" default:"true"`
1111
// Sets the port which the Prometheus compatible metrics endpoint should be served on
12-
OtelPrometheusExporterPort int `envconfig:"KEDA_HTTP_OTEL_PROM_EXPORTER_PORT" default:"2223"`
12+
OtelPrometheusExporterPort int `envconfig:"OTEL_PROM_EXPORTER_PORT" default:"2223"`
1313
// Sets whether or not to enable the OTEL metrics exporter
14-
OtelHTTPExporterEnabled bool `envconfig:"KEDA_HTTP_OTEL_HTTP_EXPORTER_ENABLED" default:"false"`
14+
OtelHTTPExporterEnabled bool `envconfig:"OTEL_EXPORTER_OTLP_METRICS_ENABLED" default:"false"`
1515
// Sets the HTTP endpoint where metrics should be sent to
16-
OtelHTTPCollectorEndpoint string `envconfig:"KEDA_HTTP_OTEL_HTTP_COLLECTOR_ENDPOINT" default:"localhost:4318"`
16+
OtelHTTPCollectorEndpoint string `envconfig:"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT" default:"localhost:4318"`
1717
// Sets the OTLP headers required by the otel exporter
18-
OtelHTTPHeaders string `envconfig:"KEDA_HTTP_OTEL_HTTP_HEADERS" default:""`
18+
OtelHTTPHeaders string `envconfig:"OTEL_EXPORTER_OTLP_METRICS_HEADERS" default:""`
1919
// Set the connection to the otel HTTP collector endpoint to use HTTP rather than HTTPS
20-
OtelHTTPCollectorInsecure bool `envconfig:"KEDA_HTTP_OTEL_HTTP_COLLECTOR_INSECURE" default:"false"`
20+
OtelHTTPCollectorInsecure bool `envconfig:"OTEL_EXPORTER_OTLP_METRICS_INSECURE" default:"false"`
2121
// Set the interval in seconds to export otel metrics to the configured collector endpoint
22-
OtelMetricExportInterval int `envconfig:"KEDA_HTTP_OTEL_METRIC_EXPORT_INTERVAL" default:"30"`
22+
OtelMetricExportInterval int `envconfig:"OTEL_EXPORTER_OTLP_METRICS_EXPORT_INTERVAL" default:"30"`
2323
}
2424

2525
// Parse parses standard configs using envconfig and returns a pointer to the

interceptor/metrics/otelmetrics.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ func NewOtelMetrics(metricsConfig *config.Metrics, options ...metric.Option) *Ot
3030
endpoint := otlpmetrichttp.WithEndpoint(metricsConfig.OtelHTTPCollectorEndpoint)
3131
headersFromEnvVar := getHeaders(metricsConfig.OtelHTTPHeaders)
3232
headers := otlpmetrichttp.WithHeaders(headersFromEnvVar)
33+
path := otlpmetrichttp.WithURLPath("/v1/metrics")
3334

3435
if metricsConfig.OtelHTTPCollectorInsecure {
3536
insecure := otlpmetrichttp.WithInsecure()
36-
exporter, err = otlpmetrichttp.New(ctx, endpoint, headers, insecure)
37+
exporter, err = otlpmetrichttp.New(ctx, endpoint, headers, path, insecure)
3738
} else {
38-
exporter, err = otlpmetrichttp.New(ctx, endpoint, headers)
39+
exporter, err = otlpmetrichttp.New(ctx, endpoint, headers, path)
3940
}
4041

4142
if err != nil {

tests/checks/interceptor_otel_metrics/interceptor_otel_metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func TestMetricGeneration(t *testing.T) {
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
174-
time.Sleep(5 * time.Second)
174+
time.Sleep(10 * time.Second)
175175
// Fetch metrics and validate them
176176
family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", otelCollectorPromURL))
177177
val, ok = family["interceptor_request_count_total"]

0 commit comments

Comments
 (0)