-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Prometheus scraper ignores __address__
overrides when it is used with kubernetes_sd_configs=pod
#32306
Comments
kubernetes_sd_configs=pod
__address__
overrides when it is used with kubernetes_sd_configs=pod
I suspect that the regex doesn't match the You can try out this instead: |
I'm having the same problem, and I think is related to what @JBodkin-Amphora said. I tried copying the rules of prometheus of this file and putting into the collector config -> https://raw.githubusercontent.com/cilium/cilium/1.15.3/examples/kubernetes/addons/prometheus/monitoring-example.yaml scrape_configs:
# https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml#L79
- job_name: 'kubernetes-endpoints'
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_k8s_app]
action: keep
regex: cilium
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
action: replace
target_label: __scheme__
regex: (https?)
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
action: replace
target_label: __address__
regex: (.+)(?::\d+);(\d+)
replacement: $1:$2
- action: labelmap
regex: __meta_kubernetes_service_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: namespace
- source_labels: [__meta_kubernetes_service_name]
action: replace
target_label: service
# https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml#L156
- job_name: 'kubernetes-pods'
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: true
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: (.+):(?:\d+);(\d+)
replacement: ${1}:${2}
target_label: __address__
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: namespace
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: pod
- source_labels: [__meta_kubernetes_pod_container_port_number]
action: keep
regex: \d+ It didn't worked, but when I changed the regex, to the one @JBodkin-Amphora mentioned, of this part (replace address with correct port) in all jobs it worked well. - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: (.+):(?:\d+);(\d+) ----> ([^:]+)(?::\d+)?
replacement: ${1}:${2} I think the regex in collector is working differently how it works in prometheus, because this rules works fine in prometheus without changing the regex. |
Hello @rooque, The regex pattern in the Prometheus example is different to the one you've specified in your initial configuration. In their example, the regex pattern is Note: There is an additional capturing group compared to the regex pattern I gave above, which takes the port from the annotation instead of a hardcoded value. Do you recall where you found the regex pattern? |
@JBodkin-Amphora I tried with the regex ([^:]+)(?::\d+)?;(\d+) and it isn't working as well |
This is the full configuration that I'm using:
Note: In the replacement, you need to use Then my pods are annotation with:
|
thank you very much @JBodkin-Amphora !! |
Component(s)
Prometheus scraper
What happened?
Description
When prometheus scraper is used with
kubernetes_sd_configs=pod
config :It ignores relabel_configs and does not override port to 9000.
Steps to Reproduce
K8s configmap with otel config:
Expected Result
Requests always sent to 9000 port
Actual Result
Requests sometimes sent to 9000, and sometimes to 80 port for some magical reasons
Collector version
0.85.0
Environment information
Environment
OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")
CentOS
OpenTelemetry Collector configuration
The text was updated successfully, but these errors were encountered: