mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 19:54:10 -06:00
Prometheus: Set Status(Code) on backend response (#80806)
Sets that status code on backend data responses in prometheus to match the status code returned by prometheus. If the failure is below HTTP/Application Layer, Bad Gateway is returned (502). --------- Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
parent
fb4125dfbb
commit
02e2e1c64e
@ -130,6 +130,7 @@ func (s *QueryData) fetch(ctx context.Context, client *client.Client, q *models.
|
||||
res := s.instantQuery(traceCtx, client, q, headers)
|
||||
dr.Error = res.Error
|
||||
dr.Frames = res.Frames
|
||||
dr.Status = res.Status
|
||||
}
|
||||
|
||||
if q.RangeQuery {
|
||||
@ -140,6 +141,9 @@ func (s *QueryData) fetch(ctx context.Context, client *client.Client, q *models.
|
||||
} else {
|
||||
dr.Error = fmt.Errorf("%v %w", dr.Error, res.Error)
|
||||
}
|
||||
// When both instant and range are true, we may overwrite the status code.
|
||||
// To fix this (and other things) they should come in separate http requests.
|
||||
dr.Status = res.Status
|
||||
}
|
||||
dr.Frames = append(dr.Frames, res.Frames...)
|
||||
}
|
||||
@ -161,7 +165,8 @@ func (s *QueryData) rangeQuery(ctx context.Context, c *client.Client, q *models.
|
||||
res, err := c.QueryRange(ctx, q)
|
||||
if err != nil {
|
||||
return backend.DataResponse{
|
||||
Error: err,
|
||||
Error: err,
|
||||
Status: backend.StatusBadGateway,
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,7 +184,8 @@ func (s *QueryData) instantQuery(ctx context.Context, c *client.Client, q *model
|
||||
res, err := c.QueryInstant(ctx, q)
|
||||
if err != nil {
|
||||
return backend.DataResponse{
|
||||
Error: err,
|
||||
Error: err,
|
||||
Status: backend.StatusBadGateway,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *htt
|
||||
r := converter.ReadPrometheusStyleResult(iter, converter.Options{
|
||||
Dataplane: s.enableDataplane,
|
||||
})
|
||||
r.Status = backend.Status(res.StatusCode)
|
||||
|
||||
// Add frame to attach metadata
|
||||
if len(r.Frames) == 0 && !q.ExemplarQuery {
|
||||
|
Loading…
Reference in New Issue
Block a user