canonical / prometheus-k8s-operator

https://charmhub.io/prometheus-k8s
Apache License 2.0
21 stars 35 forks source link

`metrics_path` is silently ignored when used together with *-notation #360

Closed sed-i closed 2 years ago

sed-i commented 2 years ago

Bug Description

When a scrape job has a custom metrics_path AND uses star-notation, then the other side of the relation (consumer, i.e. the prom that scrapes) has the custom metrics_path ignored, and uses the default one.

EDIT

Put differently, a job's target hostname has no effect, if the external_hostname= kwarg is not passed to MetricsEndpointProvider.

Still, after passing external_hostname, there is some duplication (apart from ingress nor path not being picked up):

> $ curl 10.1.13.180:9090/api/v1/targets| jq | grep "scrapeUrl"
        "scrapeUrl": "http://prometheus-0.prometheus-endpoints.test-external-url-f4ew.svc.cluster.local:9090/metrics",
        "scrapeUrl": "http://prometheus-0.prometheus-endpoints.test-external-url-f4ew.svc.cluster.local:80/metrics",
        "scrapeUrl": "http://prometheus-1.prometheus-endpoints.test-external-url-f4ew.svc.cluster.local:80/metrics",
        "scrapeUrl": "http://localhost:9090/metrics",

To Reproduce

Pass the following job to PromScrapeProvider:

{"metrics_path": "/foo/metrics", "static_configs": [{"targets": [f"*:{self._port}"]}]}

Environment

N/A

Relevant log output

scrape_jobs: '[{"metrics_path": "/metrics", "static_configs": [{"targets": ["*:9090"]}]}]'

Additional context

Noticed this while working on ingress (#349).

sed-i commented 2 years ago

Fixed by #370 + #373.