prometheus / prometheus/client_python
Labels on function decorator that are defined at runtime
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 876
- Avg merge
- 8d 4h
- Merged PRs (30d)
- 1
Description
Referring back to this thread: https://github.com/prometheus/client_python/issues/157
I wanted to know if there's a way to use the function decorator syntax with labels that will be instantiated at a later point? I need to fetch the label values from another service first. I am currently filling in some dummy values which will give me duplicated metrics:
inference_time_created{edge="EMPTY_SCOPE",line="EMPTY_SCOPE",module="EMPTY_SCOPE",plant="EMPTY_SCOPE",workload="EMPTY_SCOPE"} 1.6311126626366935e+09
inference_time_created{edge="ACTUAL_VALUE",line="ACTUAL_VALUE",module="ACTUAL_VALUE",plant="ACTUAL_VALUE",workload="ACTUAL_VALUE"} 1.6311126626709173e+09
So my question is if there's a way to not have the EMPTY_SCOPE metric on the endpoint.
This is the basic idea of what I'm doing:
scope_keys = ["plant", "edge", "line", "workload", "module"]
scope_values = ["EMPTY_SCOPE"] * 5
inference_time_created= Gauge('inference_time', 'How long (in seconds) does it take for an inference', scope_keys)
inference_time_created_labeled = inference_time_created.labels(*scope_values)
def set_metrics_scope(scope): # this function gets called later in the main code
scope_values = scope
inference_time_created_labeled = inference_time_created.labels(*scope_values)
@inference_time_created_labeled.time()
def inference():
# do some calculations
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
No source file or test is identified in the issue. Start by tracing the Gauge.labels call and the decorator's .time() entry point used in the example; done should allow label values to be supplied later without exposing the initial EMPTY_SCOPE metric.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100