Skip to content
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

Custom metric path does not work #4052

Closed
dbluxo opened this Issue Apr 6, 2018 · 9 comments

Comments

Projects
None yet
3 participants
@dbluxo
Copy link

dbluxo commented Apr 6, 2018

What did you do?

I've configured a custom service inside kubernetes, with the following annotations:

apiVersion: v1
kind: Service
metadata:
  annotations:
    prometheus.io/scrape: 'true'
    prometheus.io/path: '/custom'
    prometheus.io/port:  '8080'

What did you expect to see?

I've configured the following relabel operation inside prometheus.yml, as of:
https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml

  - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
    action: replace
    target_label: __metrics_path__
    regex: (.+)

I'm expecting __metrics_path__ will be replaced with /custom

What did you see instead? Under which circumstances?

__metrics_path__ is still /metrics (default)

Environment

We are using prometheus 2.2.1 inside kubernetes.

  • System information:

    Linux 4.9.75-rancher x86_64

  • Prometheus version:

    prometheus, version 2.2.1 (branch: HEAD, revision: bc6058c)
    build user: root@149e5b3f0829
    build date: 20180314-14:15:45
    go version: go1.10

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Apr 6, 2018

Does the service discovery status page show that __meta_kubernetes_service_annotation_prometheus_io_path is set as you expect?

@dbluxo

This comment has been minimized.

Copy link
Author

dbluxo commented Apr 6, 2018

Yes, as of service discovery status page io_path is set to /custom:

__meta_kubernetes_service_annotation_prometheus_io_path="/custom"

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Apr 6, 2018

Can you share the full relabel configs and the relevant row on the discovery status page?

@dbluxo

This comment has been minimized.

Copy link
Author

dbluxo commented Apr 6, 2018

Yes of course:

service_discovery

@simonpasquier

This comment has been minimized.

Copy link
Member

simonpasquier commented Apr 6, 2018

I can't reproduce it with v2.2.1, there may be an error with your configuration.
Can you share the targets page too?

@dbluxo

This comment has been minimized.

Copy link
Author

dbluxo commented Apr 6, 2018

Here is the job config (prometheus.yml):

    - job_name: 'kubernetes-endpoints'
      scheme: http
      kubernetes_sd_configs:
      - role: endpoints
      tls_config:
        ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        insecure_skip_verify: true
      bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
      relabel_configs:
      - 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: kubernetes_namespace
      - source_labels: [__meta_kubernetes_service_name]
        action: replace
        target_label: kubernetes_service

Here are the targets for this job (kubernetes-endpoints):

targets

Last target is down, because the metrics are under "/prometheus" not under "/metrics".

@simonpasquier

This comment has been minimized.

Copy link
Member

simonpasquier commented Apr 6, 2018

you've got a typo: the label name should be __metrics_path__ (you're missing trailing __).

@dbluxo

This comment has been minimized.

Copy link
Author

dbluxo commented Apr 6, 2018

Omg, thank you!

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 22, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.