Component(s)
targetAllocator
What happened?
Hi ;)
It seems that the Target Allocator is picking the wrong password when using ScrapeConfig from Prometheus Operator (no issue with username in the same secret)
Description
The following ScrapeConfig is working fine using Prometheus Operator :
apiVersion: monitoring.coreos.com/v1alpha1
kind: ScrapeConfig
metadata:
name: demo-scrapeconfig
spec:
staticConfigs:
- labels:
job: demo
targets:
- demo-remote-service:9999
metricsPath: /metrics
scheme: HTTPS
tlsConfig:
insecureSkipVerify: true
basicAuth:
username:
name: basic-auth
key: user
password:
name: basic-auth
key: password
But when using targetAllocator, I get 401 errors in OtelColector logs:
2025-02-25T18:41:37.945Z debug scrape/scrape.go:1347 Scrape failed {"kind": "receiver", "name": "prometheus", "data_type": "metrics", "scrape_pool": "scrapeConfig/demo/demo-scrapeconfig", "target": "https://demo-remote-service:9999/metrics", "error": "server returned HTTP status 401 Unauthorized"}
Using curl 'localhost:8080/scrape_configs' | jq to get the scrape config, I can see that the password is not the one created in the k8s secret
"scrapeConfig/demo/demo-scrapeconfig": {
"basic_auth": {
"password": "<secret>",
"username": "demo-user"
},
Using a remote webhook receiver to troubleshoot the final query, I can confirm that the secret value is not good
Steps to Reproduce
-
Create secret k create secret generic basic-auth-demo --from-literal='user=username-example' --from-literal='password=password-example'
-
Create a ScrapeConfig
apiVersion: monitoring.coreos.com/v1alpha1
kind: ScrapeConfig
metadata:
name: demo-scrape-config
labels:
app: kube-prometheus-stack-prometheus
release: prometheus-operator
prometheus: system-monitoring-prometheus
spec:
staticConfigs:
- labels:
job: demo-scrape-config
targets:
- webhook.site
metricsPath: /3ad6310f-79ed-4816-b74c-5616ff68d2a1 #Change here with your endpoint
scheme: HTTPS
tlsConfig:
insecureSkipVerify: true
basicAuth:
username:
name: basic-auth-demo
key: user
password:
name: basic-auth-demo
key: password
- Use portforward / curl on TA to get config
curl 'localhost:8080/scrape_configs' | jq
...
"scrapeConfig/test-sna/demo-scrape-config": {
"basic_auth": {
"password": "<secret>",
"username": "username-example"
},
- Check the webhook site
Expected Result
The right password:
"basic_auth": {
"password": "password-example",
"username": "username-example"
},
Actual Result
"basic_auth": {
"password": "<secret>",
"username": "username-example"
},
Kubernetes Version
v1.30.9
Operator version
otel/opentelemetry-collector-k8s:0.117.0
Collector version
otel/opentelemetry-collector-k8s:0.117.0
Environment information
Environment
OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")
Log output
2025-02-25T18:41:37.945Z debug scrape/scrape.go:1347 Scrape failed {"kind": "receiver", "name": "prometheus", "data_type": "metrics", "scrape_pool": "scrapeConfig/demo/demo-scrapeconfig", "target": "https://demo-remote-service:9999/metrics", "error": "server returned HTTP status 401 Unauthorized"}
Additional context
My OTEL Deployment:
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: collector-with-ta
spec:
mode: statefulset
targetAllocator:
enabled: true
prometheusCR:
enabled: true
serviceMonitorSelector: {}
scrapeConfigSelector: {}
config:
receivers:
prometheus:
config:
scrape_configs:
- job_name: 'otel-collector'
scrape_interval: 10s
static_configs:
- targets: [ '0.0.0.0:8888' ]
metric_relabel_configs:
- action: labeldrop
regex: (id|name)
- action: labelmap
regex: label_(.+)
replacement: $$1
exporters:
debug: {}
service:
pipelines:
metrics:
receivers: [prometheus]
exporters: [debug]
telemetry:
logs:
level: "debug"
metrics:
address: 0.0.0.0:8888
Component(s)
targetAllocator
What happened?
Hi ;)
It seems that the Target Allocator is picking the wrong password when using ScrapeConfig from Prometheus Operator (no issue with username in the same secret)
Description
The following ScrapeConfig is working fine using Prometheus Operator :
But when using targetAllocator, I get 401 errors in OtelColector logs:
Using
curl 'localhost:8080/scrape_configs' | jqto get the scrape config, I can see that the password is not the one created in the k8s secretUsing a remote webhook receiver to troubleshoot the final query, I can confirm that the secret value is not good
Steps to Reproduce
Create secret
k create secret generic basic-auth-demo --from-literal='user=username-example' --from-literal='password=password-example'Create a ScrapeConfig
Expected Result
The right password:
Actual Result
Kubernetes Version
v1.30.9
Operator version
otel/opentelemetry-collector-k8s:0.117.0
Collector version
otel/opentelemetry-collector-k8s:0.117.0
Environment information
Environment
OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")
Log output
2025-02-25T18:41:37.945Z debug scrape/scrape.go:1347 Scrape failed {"kind": "receiver", "name": "prometheus", "data_type": "metrics", "scrape_pool": "scrapeConfig/demo/demo-scrapeconfig", "target": "https://demo-remote-service:9999/metrics", "error": "server returned HTTP status 401 Unauthorized"}Additional context
My OTEL Deployment: