MetricsList not working with no-name metrics.
See original GitHub issueThe following code sample is breaking for me when attempting to instantiate a metricslist object
pc = PrometheusConnect(
url="my_prometheus_instance",
headers={"Authorization":"bearer my_private_token" },
disable_ssl=True,
)
end_time = datetime.datetime.now()
start_time = end_time - datetime.timedelta(days=365)
chunk_size = parse_timedelta("now", "1d")
query_result = pc.custom_query(query='avg_over_time(min(up{job=~"foo"})[7d:])*100')
bar=MetricsList(query_result)
This is the output of the code in question
bar=MetricsList(foo)
for item in bar:
print(item.metric_name, item.label_config)
print(item.metric_values)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-12-6b7c63e24b2a> in <module>
----> 1 bar=MetricsList(foo)
2 for item in bar:
3 print(item.metric_name, item.label_config)
4 print(item.metric_values)
/opt/app-root/lib/python3.6/site-packages/prometheus_api_client/metrics_list.py in __init__(self, metric_data_list)
40 metric_object_list.append(metric_object)
41 else:
---> 42 metric_object = Metric(i)
43 if metric_object in metric_object_list:
44 metric_object_list[metric_object_list.index(metric_object)] += metric_object
/opt/app-root/lib/python3.6/site-packages/prometheus_api_client/metric.py in __init__(self, metric, oldest_data_datetime)
68 self.oldest_data_datetime = oldest_data_datetime
69 else:
---> 70 self.metric_name = metric["metric"]["__name__"]
71 self.label_config = deepcopy(metric["metric"])
72 self.oldest_data_datetime = oldest_data_datetime
KeyError: '__name__'
The value of query_result
is [{'metric': {}, 'value': [1566485171.497, '14735']}]
My guess is that any prometheus query that returns a time_series without a name
will break. Setting a default value of some sort is probably the simplest solution here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Why can't I retrieve data points for CloudWatch metrics in the ...
To troubleshoot missing data points, follow these steps: Confirm that the metric namespace, metric name, and key-value pairs for the ...
Read more >Rules for creating metrics: requirements and tips
Here are some limits, requirements, and recommendations when you create metrics from events, logs, or spans. Metric aggregation. Your NRQL query must use...
Read more >MongoDB Prometheus exporter not scrapping all metrics
I have a Mongo deployment with a metrics exporter ...
Read more >Nsight Compute CLI - NVIDIA Documentation Center
If not specified and --section or --metrics are used, no sets are collected. Use --list-sets to see which set is the default. list-sections ......
Read more >Code metrics values - Visual Studio - Microsoft Learn
Software measurements. The following list shows the code metrics results that Visual Studio calculates: Maintainability Index - Calculates an ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can I work on this ?
For the next person who comes across this, I think I’ve found some success. In my query I was able to use label_replace to insert a label where there wasn’t one.
Updating the example above :
… which doesn’t run for me so here’s mine: