prometheus / prometheus/client_python
Remove child metric
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 876
- Avg merge
- 8d 4h
- Merged PRs (30d)
- 1
Description
Hello.
Tried to remove some childs, but got KeyError.
My custom metric (gauge) have some lables and worked fine. But when i needed to delete some childs, i'm stuck:
global statusOK
statusOK = "OK"
global statusNOK
statusNOK = "Fail"
service_login_status_prom = prom.Gauge('service_login_status', 'Check access token availability', ['status', 'dc_name'])
result = str('0')
service_login_status_prom.labels(statusOK, dc_name).set(result)
service_login_status_prom.remove(statusNOK, dc_name)
Error is -
File "/usr/local/lib/python3.8/site-packages/prometheus_client/metrics.py", line 187, in remove
del self._metrics[labelvalues]
KeyError: ('Fail', '11u25')
When label is only one, error quite different -
File "/usr/local/lib/python3.8/site-packages/prometheus_client/metrics.py", line 187, in remove
del self._metrics[labelvalues]
KeyError: ('Fail', )
Comma at the end of labelvalues confused me
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with prometheus_client/metrics.py at the remove implementation around line 187 and reproduce the two label-count examples from the issue. Check the existing metric tests for child removal and missing label tuples. Done means the expected behavior for removing a child is covered by tests and reflected in the issue's outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100