From 8d3dfa2473e06e98cdcfb28199efa577406182d5 Mon Sep 17 00:00:00 2001 From: Chris Mark Date: Thu, 2 Apr 2020 15:20:13 +0300 Subject: [PATCH] Remove dataType field of query metricset (#17383) (#17426) (cherry picked from commit deba29e3f8fa7e79d6326463f8d4d7deac480d92) --- .../module/prometheus/query/_meta/data.json | 5 ++- metricbeat/module/prometheus/query/data.go | 31 ++++++++----------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/metricbeat/module/prometheus/query/_meta/data.json b/metricbeat/module/prometheus/query/_meta/data.json index 6f03bd4ce7e..5f1d69b909a 100644 --- a/metricbeat/module/prometheus/query/_meta/data.json +++ b/metricbeat/module/prometheus/query/_meta/data.json @@ -16,12 +16,11 @@ "job": "prometheus" }, "query": { - "dataType": "vector", - "go_threads": 26 + "go_threads": 18 } }, "service": { - "address": "localhost:32768", + "address": "localhost:32769", "type": "prometheus" } } \ No newline at end of file diff --git a/metricbeat/module/prometheus/query/data.go b/metricbeat/module/prometheus/query/data.go index b89df6b4305..b0d3d4d1bb0 100644 --- a/metricbeat/module/prometheus/query/data.go +++ b/metricbeat/module/prometheus/query/data.go @@ -45,8 +45,7 @@ type ArrayResponse struct { Data arrayData `json:"data"` } type arrayData struct { - ResultType string `json:"resultType"` - Results []interface{} `json:"result"` + Results []interface{} `json:"result"` } // InstantVectorResponse is for "vector" type from Prometheus Query API Request @@ -63,8 +62,7 @@ type InstantVectorResponse struct { Data instantVectorData `json:"data"` } type instantVectorData struct { - ResultType string `json:"resultType"` - Results []instantVectorResult `json:"result"` + Results []instantVectorResult `json:"result"` } type instantVectorResult struct { Metric map[string]string `json:"metric"` @@ -85,8 +83,7 @@ type RangeVectorResponse struct { Data rangeVectorData `json:"data"` } type rangeVectorData struct { - ResultType string `json:"resultType"` - Results []rangeVectorResult `json:"result"` + Results []rangeVectorResult `json:"result"` } type rangeVectorResult struct { Metric map[string]string `json:"metric"` @@ -129,7 +126,6 @@ func parseResponse(body []byte, pathConfig QueryConfig) ([]mb.Event, error) { func getEventsFromMatrix(body []byte, queryName string) ([]mb.Event, error) { events := []mb.Event{} - resultType := "matrix" convertedMap, err := convertJSONToRangeVectorResponse(body) if err != nil { return events, err @@ -153,8 +149,7 @@ func getEventsFromMatrix(body []byte, queryName string) ([]mb.Event, error) { Timestamp: getTimestamp(timestamp), ModuleFields: common.MapStr{"labels": result.Metric}, MetricSetFields: common.MapStr{ - "dataType": resultType, - queryName: val, + queryName: val, }, }) } else { @@ -167,7 +162,6 @@ func getEventsFromMatrix(body []byte, queryName string) ([]mb.Event, error) { func getEventsFromVector(body []byte, queryName string) ([]mb.Event, error) { events := []mb.Event{} - resultType := "vector" convertedMap, err := convertJSONToInstantVectorResponse(body) if err != nil { return events, err @@ -190,8 +184,7 @@ func getEventsFromVector(body []byte, queryName string) ([]mb.Event, error) { Timestamp: getTimestamp(timestamp), ModuleFields: common.MapStr{"labels": result.Metric}, MetricSetFields: common.MapStr{ - "dataType": resultType, - queryName: val, + queryName: val, }, }) } else { @@ -222,8 +215,7 @@ func getEventFromScalarOrString(body []byte, resultType string, queryName string return mb.Event{ Timestamp: getTimestamp(timestamp), MetricSetFields: common.MapStr{ - "dataType": resultType, - queryName: val, + queryName: val, }, }, nil } else if resultType == "string" { @@ -233,11 +225,14 @@ func getEventFromScalarOrString(body []byte, resultType string, queryName string return mb.Event{}, errors.New(msg) } return mb.Event{ - Timestamp: getTimestamp(timestamp), - ModuleFields: common.MapStr{"labels": common.MapStr{queryName: value}}, + Timestamp: getTimestamp(timestamp), + ModuleFields: common.MapStr{ + "labels": common.MapStr{ + queryName: value, + }, + }, MetricSetFields: common.MapStr{ - "dataType": resultType, - queryName: 1, + queryName: 1, }, }, nil }