Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default Prometheus query range route for Grafana integration #877

Merged
merged 11 commits into from
Sep 5, 2018

Conversation

robskillington
Copy link
Collaborator

No description provided.

@codecov
Copy link

codecov bot commented Sep 3, 2018

Codecov Report

Merging #877 into master will increase coverage by 0.17%.
The diff coverage is 86.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #877      +/-   ##
==========================================
+ Coverage   78.37%   78.55%   +0.17%     
==========================================
  Files         393      393              
  Lines       33391    33405      +14     
==========================================
+ Hits        26171    26240      +69     
+ Misses       5415     5365      -50     
+ Partials     1805     1800       -5
Flag Coverage Δ
#dbnode 81.4% <ø> (+0.09%) ⬆️
#m3ninx 71.99% <ø> (ø) ⬆️
#query 68.67% <86.27%> (+0.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dee4cb0...b90bb5c. Read the comment docs.

Copy link
Collaborator

@arnikola arnikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to update this script as well since endpoint as well as output formatting is changing:

https://github.com/m3db/m3/blob/master/src/cmd/services/m3query/scripts/prom-m3-diff.sh

if firstErr != nil {
// Try parsing as an integer value specifying seconds, the Prometheus default
if seconds, err := strconv.ParseInt(d, 10, 64); err == nil {
value = time.Duration(seconds) * time.Second
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return time.Duration(seconds) * time.Second, nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, also refactored the initial form value if/else too.

if !ok || len(targetQueries) == 0 || targetQueries[0] == "" {
func parseQuery(r *http.Request) (string, error) {
queries, ok := r.URL.Query()[queryParam]
if !ok || len(queries) == 0 || queries[0] == "" {
return "", errors.ErrNoTargetFound
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename ErrNoTargetFound to ErrNoQueryFound?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

`)

actual := mustPrettyJSON(t, buffer.String())

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unnecessary newline

@@ -42,7 +42,7 @@ import (
const (
endParam = "end"
startParam = "start"
targetParam = "target"
queryParam = "query"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to work fine for the prometheus remote read end point?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, this is the native end point, not the remote read one. Never mind!

@arnikola
Copy link
Collaborator

arnikola commented Sep 4, 2018

There's a couple of places which still use target rather than query, notably RequestParams

echo $m3url
echo $promurl
curl -G $m3url > m3out
curl -G $promurl > promout
jq ".[]|.tags,.datapoints" m3out > m3result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might have to be values rather than datapoints, and metric instead of tags

@@ -107,17 +107,17 @@ func (b *fixedResolutionValues) StartTime() time.Time {

// Resolution returns resolution per step
func (b *fixedResolutionValues) Resolution() time.Duration {
return b.MillisPerStep()
return b.MillisPerStep() * time.Millisecond
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this screw up things down the line?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like semaphore's failing a few unit tests, this seems like the likely culprit

dp := vals.DatapointAt(i)
// Skip points before the query boundary. Ideal place to adjust these would be at the result node but that would make it inefficient
// since we would need to create another block just for the sake of restricting the bounds.
// Each series have the same start time so we just need to calculate the correct startIdx once
// NB(r): Removing the optimization of computing startIdx once just in case our assumptions are wrong,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit odd that you're seeing more points after deleting this. Might bear further investigation to see where our assumptions go bad

Copy link
Collaborator

@arnikola arnikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving pending successful build

curl -G $m3command > m3out
curl -G $promcommand > promout
jq ".[]|.tags,.datapoints" m3out > m3result
queryurl="/api/v1/query_range?start=$start&end=$end&step=$step --data-urlencode query=$target"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet!

@@ -126,6 +126,8 @@ echo "Sleep for 30 seconds to let the remote write endpoint generate some data"

sleep 30

# Ensure Prometheus can proxy a Prometheus query
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you also want to test m3query directly ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do, I'm going to do this in a follow up change if that's ok - its not trivial.

// Prometheus native query endpoints, registered under both the default
// Prometheus server route and the Prometheus native read endpoint route
promNativeRead := logged(native.NewPromReadHandler(h.engine)).ServeHTTP
h.Router.HandleFunc(prometheus.DefaultQueryRangeURL, promNativeRead).Methods(prometheus.DefaultQueryRangeMethod)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to have both or shall we just update native.PromReadURL to point to /api/v1/query_range ?

@robskillington robskillington merged commit a852262 into master Sep 5, 2018
@robskillington robskillington deleted the r/register-default-prom-query-route branch September 5, 2018 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants