Prometheus/Promlib: Remove the PrometheusDataplane feature so always enabled (#92218)

This has been default behavior since v10

---------

Co-authored-by: Brendan O'Handley <brendan.ohandley@grafana.com>
This commit is contained in:
Kyle Brandt
2024-08-26 08:53:38 -04:00
committed by GitHub
parent fa95eb8c02
commit 84e5c3af22
17 changed files with 106 additions and 138 deletions

View File

@@ -242,7 +242,7 @@ func (s *QueryData) rangeQuery(ctx context.Context, c *client.Client, q *models.
}
}()
return s.parseResponse(ctx, q, res, enablePrometheusDataplaneFlag)
return s.parseResponse(ctx, q, res)
}
func (s *QueryData) instantQuery(ctx context.Context, c *client.Client, q *models.Query, enablePrometheusDataplaneFlag bool) backend.DataResponse {
@@ -268,7 +268,7 @@ func (s *QueryData) instantQuery(ctx context.Context, c *client.Client, q *model
}
}()
return s.parseResponse(ctx, q, res, enablePrometheusDataplaneFlag)
return s.parseResponse(ctx, q, res)
}
func (s *QueryData) exemplarQuery(ctx context.Context, c *client.Client, q *models.Query, enablePrometheusDataplaneFlag bool) backend.DataResponse {
@@ -285,7 +285,7 @@ func (s *QueryData) exemplarQuery(ctx context.Context, c *client.Client, q *mode
s.log.Warn("Failed to close response body", "error", err)
}
}()
return s.parseResponse(ctx, q, res, enablePrometheusDataplaneFlag)
return s.parseResponse(ctx, q, res)
}
func addDataResponse(res *backend.DataResponse, dr *backend.DataResponse) {

View File

@@ -137,7 +137,7 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) {
require.Equal(t, "Time", res[0].Fields[0].Name)
require.Len(t, res[0].Fields[1].Labels, 2)
require.Equal(t, "app=Application, tag2=tag2", res[0].Fields[1].Labels.String())
require.Equal(t, "legend Application", res[0].Name)
require.Equal(t, "legend Application", res[0].Fields[1].Config.DisplayNameFromDS)
// Ensure the timestamps are UTC zoned
testValue := res[0].Fields[0].At(0)
@@ -231,7 +231,7 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) {
require.Equal(t, res[0].Fields[0].Name, "Time")
require.Len(t, res[0].Fields[1].Labels, 2)
require.Equal(t, res[0].Fields[1].Labels.String(), "app=Application, tag2=tag2")
require.Equal(t, "{app=\"Application\", tag2=\"tag2\"}", res[0].Name)
require.Equal(t, `{app="Application", tag2="tag2"}`, res[0].Fields[1].Config.DisplayNameFromDS)
})
t.Run("matrix response with NaN value should be changed to null", func(t *testing.T) {
@@ -269,7 +269,7 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) {
res, err := execute(tctx, query, result)
require.NoError(t, err)
require.Equal(t, "{app=\"Application\"}", res[0].Name)
require.Equal(t, `{app="Application"}`, res[0].Fields[1].Config.DisplayNameFromDS)
require.True(t, math.IsNaN(res[0].Fields[1].At(0).(float64)))
})
@@ -308,7 +308,7 @@ func TestPrometheus_parseTimeSeriesResponse(t *testing.T) {
require.Equal(t, res[0].Fields[0].Name, "Time")
require.Len(t, res[0].Fields[1].Labels, 2)
require.Equal(t, res[0].Fields[1].Labels.String(), "app=Application, tag2=tag2")
require.Equal(t, "legend Application", res[0].Name)
require.Equal(t, "legend Application", res[0].Fields[1].Config.DisplayNameFromDS)
// Ensure the timestamps are UTC zoned
testValue := res[0].Fields[0].At(0)

View File

@@ -18,7 +18,7 @@ import (
"github.com/grafana/grafana/pkg/promlib/utils"
)
func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *http.Response, enablePrometheusDataplaneFlag bool) backend.DataResponse {
func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *http.Response) backend.DataResponse {
defer func() {
if err := res.Body.Close(); err != nil {
s.log.FromContext(ctx).Error("Failed to close response body", "err", err)
@@ -29,9 +29,7 @@ func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *htt
defer endSpan()
iter := jsoniter.Parse(jsoniter.ConfigDefault, res.Body, 1024)
r := converter.ReadPrometheusStyleResult(iter, converter.Options{
Dataplane: enablePrometheusDataplaneFlag,
})
r := converter.ReadPrometheusStyleResult(iter, converter.Options{Dataplane: true})
r.Status = backend.Status(res.StatusCode)
// Add frame to attach metadata
@@ -41,7 +39,7 @@ func (s *QueryData) parseResponse(ctx context.Context, q *models.Query, res *htt
// The ExecutedQueryString can be viewed in QueryInspector in UI
for i, frame := range r.Frames {
addMetadataToMultiFrame(q, frame, enablePrometheusDataplaneFlag)
addMetadataToMultiFrame(q, frame)
if i == 0 {
frame.Meta.ExecutedQueryString = executedQueryString(q)
}
@@ -106,7 +104,7 @@ func (s *QueryData) processExemplars(ctx context.Context, q *models.Query, dr ba
}
}
func addMetadataToMultiFrame(q *models.Query, frame *data.Frame, enableDataplane bool) {
func addMetadataToMultiFrame(q *models.Query, frame *data.Frame) {
if frame.Meta == nil {
frame.Meta = &data.FrameMeta{}
}
@@ -120,13 +118,9 @@ func addMetadataToMultiFrame(q *models.Query, frame *data.Frame, enableDataplane
frame.Fields[1].Config = &data.FieldConfig{DisplayNameFromDS: customName}
}
if enableDataplane {
valueField := frame.Fields[1]
if n, ok := valueField.Labels["__name__"]; ok {
valueField.Name = n
}
} else {
frame.Name = customName
valueField := frame.Fields[1]
if n, ok := valueField.Labels["__name__"]; ok {
valueField.Name = n
}
}

View File

@@ -19,7 +19,7 @@ func TestQueryData_parseResponse(t *testing.T) {
t.Run("resultType is before result the field must parsed normally", func(t *testing.T) {
resBody := `{"data":{"resultType":"vector", "result":[{"metric":{"__name__":"some_name","environment":"some_env","id":"some_id","instance":"some_instance:1234","job":"some_job","name":"another_name","region":"some_region"},"value":[1.1,"2"]}]},"status":"success"}`
res := &http.Response{Body: io.NopCloser(bytes.NewBufferString(resBody))}
result := qd.parseResponse(context.Background(), &models.Query{}, res, false)
result := qd.parseResponse(context.Background(), &models.Query{}, res)
assert.Nil(t, result.Error)
assert.Len(t, result.Frames, 1)
})
@@ -27,7 +27,7 @@ func TestQueryData_parseResponse(t *testing.T) {
t.Run("resultType is after the result field must parsed normally", func(t *testing.T) {
resBody := `{"data":{"result":[{"metric":{"__name__":"some_name","environment":"some_env","id":"some_id","instance":"some_instance:1234","job":"some_job","name":"another_name","region":"some_region"},"value":[1.1,"2"]}],"resultType":"vector"},"status":"success"}`
res := &http.Response{Body: io.NopCloser(bytes.NewBufferString(resBody))}
result := qd.parseResponse(context.Background(), &models.Query{}, res, false)
result := qd.parseResponse(context.Background(), &models.Query{}, res)
assert.Nil(t, result.Error)
assert.Len(t, result.Frames, 1)
})
@@ -35,7 +35,7 @@ func TestQueryData_parseResponse(t *testing.T) {
t.Run("no resultType is existed in the data", func(t *testing.T) {
resBody := `{"data":{"result":[{"metric":{"__name__":"some_name","environment":"some_env","id":"some_id","instance":"some_instance:1234","job":"some_job","name":"another_name","region":"some_region"},"value":[1.1,"2"]}]},"status":"success"}`
res := &http.Response{Body: io.NopCloser(bytes.NewBufferString(resBody))}
result := qd.parseResponse(context.Background(), &models.Query{}, res, false)
result := qd.parseResponse(context.Background(), &models.Query{}, res)
assert.Error(t, result.Error)
assert.Equal(t, result.Error.Error(), "no resultType found")
})
@@ -43,7 +43,7 @@ func TestQueryData_parseResponse(t *testing.T) {
t.Run("resultType is set as empty string before result", func(t *testing.T) {
resBody := `{"data":{"resultType":"", "result":[{"metric":{"__name__":"some_name","environment":"some_env","id":"some_id","instance":"some_instance:1234","job":"some_job","name":"another_name","region":"some_region"},"value":[1.1,"2"]}]},"status":"success"}`
res := &http.Response{Body: io.NopCloser(bytes.NewBufferString(resBody))}
result := qd.parseResponse(context.Background(), &models.Query{}, res, false)
result := qd.parseResponse(context.Background(), &models.Query{}, res)
assert.Error(t, result.Error)
assert.Equal(t, result.Error.Error(), "unknown result type: ")
})
@@ -51,7 +51,7 @@ func TestQueryData_parseResponse(t *testing.T) {
t.Run("resultType is set as empty string after result", func(t *testing.T) {
resBody := `{"data":{"result":[{"metric":{"__name__":"some_name","environment":"some_env","id":"some_id","instance":"some_instance:1234","job":"some_job","name":"another_name","region":"some_region"},"value":[1.1,"2"]}],"resultType":""},"status":"success"}`
res := &http.Response{Body: io.NopCloser(bytes.NewBufferString(resBody))}
result := qd.parseResponse(context.Background(), &models.Query{}, res, false)
result := qd.parseResponse(context.Background(), &models.Query{}, res)
assert.Error(t, result.Error)
assert.Equal(t, result.Error.Error(), "unknown result type: ")
})

View File

@@ -4,14 +4,14 @@
// "type": "timeseries-multi",
// "typeVersion": [
// 0,
// 0
// 1
// ],
// "custom": {
// "resultType": "matrix"
// },
// "executedQueryString": "Expr: histogram_quantile(0.95, sum(rate(tns_request_duration_seconds_bucket[4s])) by (le))\nStep: 1s"
// }
// Name: histogram_quantile(0.95, sum(rate(tns_request_duration_seconds_bucket[4s])) by (le))
// Name:
// Dimensions: 2 Fields by 301 Rows
// +-----------------------------------+----------------------+
// | Name: Time | Name: Value |
@@ -37,12 +37,11 @@
"frames": [
{
"schema": {
"name": "histogram_quantile(0.95, sum(rate(tns_request_duration_seconds_bucket[4s])) by (le))",
"meta": {
"type": "timeseries-multi",
"typeVersion": [
0,
0
1
],
"custom": {
"resultType": "matrix"

View File

@@ -4,14 +4,14 @@
// "type": "timeseries-multi",
// "typeVersion": [
// 0,
// 0
// 1
// ],
// "custom": {
// "resultType": "matrix"
// },
// "executedQueryString": "Expr: 1 / 0\nStep: 1s"
// }
// Name: 1 / 0
// Name:
// Dimensions: 2 Fields by 3 Rows
// +-------------------------------+-----------------+
// | Name: Time | Name: Value |
@@ -30,12 +30,11 @@
"frames": [
{
"schema": {
"name": "1 / 0",
"meta": {
"type": "timeseries-multi",
"typeVersion": [
0,
0
1
],
"custom": {
"resultType": "matrix"

View File

@@ -4,17 +4,17 @@
// "type": "timeseries-multi",
// "typeVersion": [
// 0,
// 0
// 1
// ],
// "custom": {
// "resultType": "matrix"
// },
// "executedQueryString": "Expr: test1\nStep: 1s"
// }
// Name: go_goroutines{job="prometheus"}
// Name:
// Dimensions: 2 Fields by 3 Rows
// +-------------------------------+------------------------------------------------+
// | Name: Time | Name: Value |
// | Name: Time | Name: go_goroutines |
// | Labels: | Labels: __name__=go_goroutines, job=prometheus |
// | Type: []time.Time | Type: []float64 |
// +-------------------------------+------------------------------------------------+
@@ -30,12 +30,11 @@
"frames": [
{
"schema": {
"name": "go_goroutines{job=\"prometheus\"}",
"meta": {
"type": "timeseries-multi",
"typeVersion": [
0,
0
1
],
"custom": {
"resultType": "matrix"
@@ -54,7 +53,7 @@
}
},
{
"name": "Value",
"name": "go_goroutines",
"type": "number",
"typeInfo": {
"frame": "float64"

View File

@@ -4,14 +4,14 @@
// "type": "timeseries-multi",
// "typeVersion": [
// 0,
// 0
// 1
// ],
// "custom": {
// "resultType": "matrix"
// },
// "executedQueryString": "Expr: \nStep: 1s"
// }
// Name: {handler="/api/v1/query_range", job="prometheus"}
// Name:
// Dimensions: 2 Fields by 3 Rows
// +-------------------------------+-----------------------------------------------------+
// | Name: Time | Name: Value |
@@ -30,12 +30,11 @@
"frames": [
{
"schema": {
"name": "{handler=\"/api/v1/query_range\", job=\"prometheus\"}",
"meta": {
"type": "timeseries-multi",
"typeVersion": [
0,
0
1
],
"custom": {
"resultType": "matrix"

View File

@@ -4,17 +4,17 @@
// "type": "timeseries-multi",
// "typeVersion": [
// 0,
// 0
// 1
// ],
// "custom": {
// "resultType": "matrix"
// },
// "executedQueryString": "Expr: \nStep: 1s"
// }
// Name: prometheus_http_requests_total{code="200", handler="/api/v1/query_range", job="prometheus"}
// Name:
// Dimensions: 2 Fields by 3 Rows
// +-----------------------------------+--------------------------------------------------------------------------------------------------------+
// | Name: Time | Name: Value |
// | Name: Time | Name: prometheus_http_requests_total |
// | Labels: | Labels: __name__=prometheus_http_requests_total, code=200, handler=/api/v1/query_range, job=prometheus |
// | Type: []time.Time | Type: []float64 |
// +-----------------------------------+--------------------------------------------------------------------------------------------------------+
@@ -29,16 +29,16 @@
// "type": "timeseries-multi",
// "typeVersion": [
// 0,
// 0
// 1
// ],
// "custom": {
// "resultType": "matrix"
// }
// }
// Name: prometheus_http_requests_total{code="400", handler="/api/v1/query_range", job="prometheus"}
// Name:
// Dimensions: 2 Fields by 2 Rows
// +-----------------------------------+--------------------------------------------------------------------------------------------------------+
// | Name: Time | Name: Value |
// | Name: Time | Name: prometheus_http_requests_total |
// | Labels: | Labels: __name__=prometheus_http_requests_total, code=400, handler=/api/v1/query_range, job=prometheus |
// | Type: []time.Time | Type: []float64 |
// +-----------------------------------+--------------------------------------------------------------------------------------------------------+
@@ -53,12 +53,11 @@
"frames": [
{
"schema": {
"name": "prometheus_http_requests_total{code=\"200\", handler=\"/api/v1/query_range\", job=\"prometheus\"}",
"meta": {
"type": "timeseries-multi",
"typeVersion": [
0,
0
1
],
"custom": {
"resultType": "matrix"
@@ -77,7 +76,7 @@
}
},
{
"name": "Value",
"name": "prometheus_http_requests_total",
"type": "number",
"typeInfo": {
"frame": "float64"
@@ -111,12 +110,11 @@
},
{
"schema": {
"name": "prometheus_http_requests_total{code=\"400\", handler=\"/api/v1/query_range\", job=\"prometheus\"}",
"meta": {
"type": "timeseries-multi",
"typeVersion": [
0,
0
1
],
"custom": {
"resultType": "matrix"
@@ -134,7 +132,7 @@
}
},
{
"name": "Value",
"name": "prometheus_http_requests_total",
"type": "number",
"typeInfo": {
"frame": "float64"