prometheus / prometheus/client_python

Remove child metric

Open
#711 4 comments 0 reactions 0 assignees View on GitHub

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)

https://github.com/prometheus/client_python/blob/09fb45953bac018a90e89f0b1e7bcd1d5d81c01b/prometheus_client/metrics.py#L187

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.