canonical / prometheus-k8s-operator

This charmed operator automates the operational procedures of running Prometheus, an open-source metrics backend.
https://charmhub.io/prometheus-k8s
Apache License 2.0
21 stars 34 forks source link

don't override existing labels in scrape jobs #593

Closed lucabello closed 4 months ago

lucabello commented 4 months ago

Issue

Closes #571.

Solution

Changing the order of the dictionaries to unpack makes sure that pre-exising labels have priority over the automatically-generated topology.

Testing Instructions

Modify a charm (e.g., blackbox) to specify a custom juju_application label; then relate it to two Prometheus instances (one without the fix, the other with the fix) and check the difference in the targets section.

Before: Screenshot_20240424_100749

After: Screenshot_20240424_100923


There is a unit test that explicitly checks that we do overwrite the topology labels (and it's aptly called test_consumer_overwrites_juju_topology_labels, in the file tests/unit/test_endpoint_consumer.py). I'm removing that test, since it doesn't really make sense with this PR :)

I would like another pair of eyes to confirm this PR is something we want to do!