mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Fix handling errors in streaming client (#61643)
* Return errors from data parsing * Better error handling * Fix the tests * When there is no frame add empty frame to get metadata attached to it * Fix tests * Update testdata
This commit is contained in:
parent
2c46f46d37
commit
29c8ce12a0
@ -87,7 +87,7 @@ func TestIntegrationPrometheus(t *testing.T) {
|
|||||||
// nolint:gosec
|
// nolint:gosec
|
||||||
resp, err := http.Post(u, "application/json", buf1)
|
resp, err := http.Post(u, "application/json", buf1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
err := resp.Body.Close()
|
err := resp.Body.Close()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -123,7 +123,7 @@ func TestIntegrationPrometheus(t *testing.T) {
|
|||||||
// nolint:gosec
|
// nolint:gosec
|
||||||
resp, err := http.Post(u, "application/json", buf1)
|
resp, err := http.Post(u, "application/json", buf1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
err := resp.Body.Close()
|
err := resp.Body.Close()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -125,23 +125,17 @@ func (s *QueryData) fetch(ctx context.Context, client *client.Client, q *models.
|
|||||||
|
|
||||||
if q.InstantQuery {
|
if q.InstantQuery {
|
||||||
res, err := s.instantQuery(traceCtx, client, q, headers)
|
res, err := s.instantQuery(traceCtx, client, q, headers)
|
||||||
if err != nil {
|
response.Error = err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
response.Error = res.Error
|
|
||||||
response.Frames = res.Frames
|
response.Frames = res.Frames
|
||||||
}
|
}
|
||||||
|
|
||||||
if q.RangeQuery {
|
if q.RangeQuery {
|
||||||
res, err := s.rangeQuery(traceCtx, client, q, headers)
|
res, err := s.rangeQuery(traceCtx, client, q, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if res.Error != nil {
|
|
||||||
if response.Error == nil {
|
if response.Error == nil {
|
||||||
response.Error = res.Error
|
response.Error = err
|
||||||
} else {
|
} else {
|
||||||
response.Error = fmt.Errorf("%v %w", response.Error, res.Error) // lovely
|
response.Error = fmt.Errorf("%v %w", response.Error, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response.Frames = append(response.Frames, res.Frames...)
|
response.Frames = append(response.Frames, res.Frames...)
|
||||||
|
@ -29,11 +29,13 @@ func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *htt
|
|||||||
MatrixWideSeries: s.enableWideSeries,
|
MatrixWideSeries: s.enableWideSeries,
|
||||||
VectorWideSeries: s.enableWideSeries,
|
VectorWideSeries: s.enableWideSeries,
|
||||||
})
|
})
|
||||||
if r.Frames == nil {
|
|
||||||
return r, fmt.Errorf("received empty response from prometheus")
|
|
||||||
}
|
|
||||||
|
|
||||||
// The ExecutedQueryString can be viewed in QueryInspector in UI
|
// The ExecutedQueryString can be viewed in QueryInspector in UI
|
||||||
|
// Add frame to attach metadata to it
|
||||||
|
if len(r.Frames) == 0 {
|
||||||
|
r.Frames = append(r.Frames, data.NewFrame(""))
|
||||||
|
}
|
||||||
|
|
||||||
for _, frame := range r.Frames {
|
for _, frame := range r.Frames {
|
||||||
if s.enableWideSeries {
|
if s.enableWideSeries {
|
||||||
addMetadataToWideFrame(q, frame)
|
addMetadataToWideFrame(q, frame)
|
||||||
@ -42,6 +44,10 @@ func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *htt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.Error != nil {
|
||||||
|
return r, r.Error
|
||||||
|
}
|
||||||
|
|
||||||
r = s.processExemplars(q, r)
|
r = s.processExemplars(q, r)
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,16 @@
|
|||||||
// +-----------------------------------+-----------------+--------------------------------------------+----------------+-------------------+-------------------+----------------+----------------+--------------------+----------------+------------------+-----------------+-------------------+----------------------------------+
|
// +-----------------------------------+-----------------+--------------------------------------------+----------------+-------------------+-------------------+----------------+----------------+--------------------+----------------+------------------+-----------------+-------------------+----------------------------------+
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
// Frame[1] {
|
||||||
|
// "executedQueryString": "Expr: histogram_quantile(0.99, sum(rate(traces_spanmetrics_duration_seconds_bucket[15s])) by (le))\nStep: 15s"
|
||||||
|
// }
|
||||||
|
// Name:
|
||||||
|
// Dimensions: 0 Fields by 0 Rows
|
||||||
|
// +
|
||||||
|
// +
|
||||||
|
//
|
||||||
|
//
|
||||||
// 🌟 This was machine generated. Do not edit. 🌟
|
// 🌟 This was machine generated. Do not edit. 🌟
|
||||||
{
|
{
|
||||||
"status": 200,
|
"status": 200,
|
||||||
@ -1040,6 +1050,17 @@
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"schema": {
|
||||||
|
"meta": {
|
||||||
|
"executedQueryString": "Expr: histogram_quantile(0.99, sum(rate(traces_spanmetrics_duration_seconds_bucket[15s])) by (le))\nStep: 15s"
|
||||||
|
},
|
||||||
|
"fields": []
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"values": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -26,6 +26,16 @@
|
|||||||
// +-----------------------------------+-----------------+--------------------------------------------+----------------+-------------------+-------------------+----------------+----------------+--------------------+----------------+------------------+-----------------+-------------------+----------------------------------+
|
// +-----------------------------------+-----------------+--------------------------------------------+----------------+-------------------+-------------------+----------------+----------------+--------------------+----------------+------------------+-----------------+-------------------+----------------------------------+
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
// Frame[1] {
|
||||||
|
// "executedQueryString": "Expr: histogram_quantile(0.99, sum(rate(traces_spanmetrics_duration_seconds_bucket[15s])) by (le))\nStep: 15s"
|
||||||
|
// }
|
||||||
|
// Name:
|
||||||
|
// Dimensions: 0 Fields by 0 Rows
|
||||||
|
// +
|
||||||
|
// +
|
||||||
|
//
|
||||||
|
//
|
||||||
// 🌟 This was machine generated. Do not edit. 🌟
|
// 🌟 This was machine generated. Do not edit. 🌟
|
||||||
{
|
{
|
||||||
"status": 200,
|
"status": 200,
|
||||||
@ -1040,6 +1050,17 @@
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"schema": {
|
||||||
|
"meta": {
|
||||||
|
"executedQueryString": "Expr: histogram_quantile(0.99, sum(rate(traces_spanmetrics_duration_seconds_bucket[15s])) by (le))\nStep: 15s"
|
||||||
|
},
|
||||||
|
"fields": []
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"values": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user