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:
Kyle Brandt 2024-01-18 13:23:31 -05:00 committed by GitHub
parent fb4125dfbb
commit 02e2e1c64e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -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,
}
}

View File

@ -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 {