client_python
client_python copied to clipboard
push_to_gateway: handling of spaces in group key values
Spaces in a group key value, come back as "+":
reproduction: (assumes docker interface at 172.17.0.1)
- Start PGW:
docker run -it --rm -p 9091:9091 prom/pushgateway:v1.6.2 - Push metrics and read back
docker run -it -e PIP_ROOT_USER_ACTION=ignore --rm python:3.10 bash -c " pip --disable-pip-version-check install -q prometheus-client && \ python3 << 'EOF' from prometheus_client import push_to_gateway from prometheus_client.metrics_core import GaugeMetricFamily from prometheus_client.registry import Collector, CollectorRegistry m1 = GaugeMetricFamily(name='spaces_in_group_key_values_status', documentation='N/A') class _CustomCollector(Collector): def collect(self): yield m1 registry = CollectorRegistry() registry.register(_CustomCollector()) push_to_gateway('http://172.17.0.1:9091',job='job_name',grouping_key={'label': 'value with spaces'},registry=registry) EOF "; curl -s http://172.17.0.1:9091/metrics | grep spaces
expected output:
push_failure_time_seconds{instance="",job="job_name",label="value with spaces"} 0
push_time_seconds{instance="",job="job_name",label="value with spaces"} 1.7290223660476923e+09
actual output:
push_failure_time_seconds{instance="",job="job_name",label="value+with+spaces"} 0
push_time_seconds{instance="",job="job_name",label="value+with+spaces"} 1.7290223660476923e+09