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

Error querying Prometheus: bad_data: cannot parse "" to a valid timestamp #801

Closed
kayrosik opened this issue Sep 8, 2020 · 4 comments
Closed

Comments

@kayrosik
Copy link

kayrosik commented Sep 8, 2020

This is part of my function QueryRange:

	start := time.Now()
	end := now.Add(time.Duration(-config.Prometheus.MetricsTimeRange) * time.Minute)
        resolution := math.Max(math.Floor(end.Sub(start).Seconds()/250), 1)
	step := time.Duration(resolution * 1e9)

	v1api := v1.NewAPI(client)
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()
	r := v1.Range{
		Start: start,
		End:   end,
		Step:  step,
	}
	result, warnings, err := v1api.QueryRange(ctx, metric, r)

I use trickster + prometheus(Thanos).
When I try to call the function, I get:
Error querying Prometheus: bad_data: cannot parse "" to a valid timestamp

And I can't understand why it can be (

I change DoGetFallback function (always HTTP-Get):

	resp, body, warnings, err := h.Do(ctx, req)
	u.RawQuery = args.Encode()
	req, err = http.NewRequest(http.MethodGet, u.String(), nil)
	if err != nil {
		return nil, nil, warnings, err
	}
	return h.Do(ctx, req)

And it works! The problem is POST-request.

@beorn7
Copy link
Member

beorn7 commented Sep 9, 2020

It's is actually recommended to use POST for the query and query-range endpoints because it avoids complications with length restrictions of the URL. (PromQL queries can become quite long.)

Maybe Trickster or Thanos don't support POST requests for those endpoints?

But even then, the HTTP client should transparently fallback to GET. Perhaps something doesn't work as intended with the fallback.

My understanding is limited here. This was implemented back in #557 by @jacksontj . Or perhaps @lilic @bwplotka or @joe-elliott would have an idea?

@joe-elliott
Copy link
Contributor

DoGetFallback relies on the server returning a 405. @kayrosik can you confirm what status code the POST is returning? My guess is that Error querying Prometheus: bad_data: cannot parse "" to a valid timestamp is a 400.

Also guessing that error is returned by Trickster based on the text, but it would be nice to confirm.

@kayrosik
Copy link
Author

Status-code is 400

@beorn7
Copy link
Member

beorn7 commented Sep 10, 2020

OK, that explains it then. Thanks @joe-elliott for the catch.

@kayrosik I recommend to file an issue with Trickster to either support POST (as it is recommended anyway) or return a 405 so that the client will properly retry.

@beorn7 beorn7 closed this as completed Sep 10, 2020
beorn7 added a commit that referenced this issue Sep 10, 2020
When discussing #801, I remembered #794. While dealing with the
latter, I read the HTTP RFC, stumbling upon the following:

    When a request method is received
    that is unrecognized or not implemented by an origin server, the
    origin server SHOULD respond with the 501 (Not Implemented) status
    code.  When a request method is received that is known by an origin
    server but not allowed for the target resource, the origin server
    SHOULD respond with the 405 (Method Not Allowed) status code.

Concluding from that, it is possible that a server desiring a fallback
to GET will send a status code of 501. It is even preferred if that
server does not offer any resource to be used with the POST method.

Therefore, I think we should fallback to GET on a 501, too.

Signed-off-by: beorn7 <beorn@grafana.com>
sbookworm pushed a commit to sbookworm/client_golang that referenced this issue Oct 20, 2020
When discussing prometheus#801, I remembered prometheus#794. While dealing with the
latter, I read the HTTP RFC, stumbling upon the following:

    When a request method is received
    that is unrecognized or not implemented by an origin server, the
    origin server SHOULD respond with the 501 (Not Implemented) status
    code.  When a request method is received that is known by an origin
    server but not allowed for the target resource, the origin server
    SHOULD respond with the 405 (Method Not Allowed) status code.

Concluding from that, it is possible that a server desiring a fallback
to GET will send a status code of 501. It is even preferred if that
server does not offer any resource to be used with the POST method.

Therefore, I think we should fallback to GET on a 501, too.

Signed-off-by: beorn7 <beorn@grafana.com>
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

No branches or pull requests

3 participants