Skip to content

Commit 5d3ca01

Browse files
cmd-ntrf4n4ndCopilot
authored
Allow creation of Metric from data structure without __name__ (#306)
* Allow creation of Metric from datastructure without __name__ When applying a function to a time series in a query to Prometheus, the Prometheus server returns a data structure without __name__ key. Apart from that aspect, the time series could still be used to create a Metric object. This PR proposes to set "metric_name" to None when __name__ is missing. * Update prometheus_api_client/metric.py Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Anand Sanmukhani <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 61adf20 commit 5d3ca01

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

prometheus_api_client/metric.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ def __init__(self, metric, oldest_data_datetime=None):
5454
self.metric_values = metric.metric_values
5555
self.oldest_data_datetime = oldest_data_datetime
5656
else:
57-
self.metric_name = metric["metric"]["__name__"]
57+
self.metric_name = metric["metric"].get("__name__", None)
5858
self.label_config = deepcopy(metric["metric"])
59+
if "__name__" in self.label_config:
60+
del self.label_config["__name__"]
5961
self.oldest_data_datetime = oldest_data_datetime
60-
del self.label_config["__name__"]
6162

6263
# if it is a single value metric change key name
6364
if "value" in metric:

0 commit comments

Comments
 (0)