question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage Question - custom_query vs get_metric_range_data

See original GitHub issue

Question

I have the following custom query:

rate(memcached_evictions{environment=~'production',location=~'location1',service='service1'}[1m])

When I get the data return over raw HTTP (w/ requests.get()) I get my results back as a vector resultType with other related metric data. The values returned are what I expected:

“value”: [<float>, “0”]

Using custom_query I can obtain the same results. But when I attempt to use one of the other methods you kind folks provide, such as get_metric_range_data, the results returned are quite different than what I’d expect. What am I missing?

Here’s the code I’m using for get_metric_data_range:


start_time = parse_datetime("15m")
end_time = parse_datetime("now")

curr_range_data = prom.get_metric_range_data(
    metric_name="memcached_evictions{environment=~'production',location=~'location1',service='service1'}",
    start_time=start_time,
    end_time=end_time
)

calc_range_data = MetricSnapshotDataFrame(curr_range_data)

The data returned when printing out calc_range_data:

__name__                value
memcached_evictions ... 3452222
memcached_evictions ... 3333263
memcached_evictions ... 13454715
memcached_evictions ... 9638913

Based on the results I get back from custom_query and the Prometheus Expression Browser, the values returned here are quite different from the expected values.

Now, I feel like I’m doing something wrong here in how I’m using these pieces, I don’t believe this to be a bug in the code. Just trying to understand how to best make use of ya’lls good work 😃

Any guidance here is greatly appreciated.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Shackelford-Ardencommented, Apr 8, 2021

@chauhankaranraj You’re correct! That does do what I need. Thank you!

I didn’t realize that internally, it was just passing in the query I provided. I thought there was some other stuff going on in the query prep piece before it was sent off to Prometheus. I’ve looked at the source code now, makes waaaaay more sense.

Thanks for the quick response @4n4nd , I don’t think I’ve ever seen such a quick response 😃

2reactions
chauhankaranrajcommented, Apr 8, 2021

Using custom_query I can obtain the same results. But when I attempt to use one of the other methods you kind folks provide, such as get_metric_range_data, the results returned are quite different than what I’d expect. What am I missing?

Hi @Shackelford-Arden, could this be because the input being passed to custom_query is different than that being passed to get_metric_range_data? I.e. the former looks something like rate ( your_query [1m] ) vs the latter is just your_query.

Does using get_current_metric_value instead like shown below give the expected results?

curr_data = prom.get_current_metric_value(
    metric_name="rate(memcached_evictions{environment=~'production',location=~'location1',service='service1'}[1m])",
    params={'time': start_time.timestamp()},
)
calc_data = MetricSnapshotDataFrame(curr_data)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Querying basics - Prometheus.io
Prometheus provides a functional query language called PromQL (Prometheus Query ... Range vector - a set of time series containing a range of...
Read more >
Using the metric query option to query CloudWatch Metrics ...
You can query CloudWatch Metrics Insights data by choosing the metric query mode in the Metric query editor .
Read more >
Prometheus instant vector vs range vector - Stack Overflow
Instant vectors have a single value for every timestamp, while range vectors have many of them. For the purpose of charting a metric,...
Read more >
Use Query insights to improve query performance | Cloud SQL ...
Stores the client IP addresses where queries are coming from and helps you group that data to run metrics against it. Queries come...
Read more >
get-metric-data — AWS CLI 2.9.9 Command Reference
A GetMetricData operation that does not include a query can retrieve as many as 500 different metrics in a single request, with a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found