Skip to content

Commit

Permalink
Remove dataType field of query metricset (elastic#17383) (elastic#17426)
Browse files Browse the repository at this point in the history
(cherry picked from commit deba29e)
  • Loading branch information
ChrsMark committed Apr 2, 2020
1 parent f3fe4a5 commit 8d3dfa2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
5 changes: 2 additions & 3 deletions metricbeat/module/prometheus/query/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
"job": "prometheus"
},
"query": {
"dataType": "vector",
"go_threads": 26
"go_threads": 18
}
},
"service": {
"address": "localhost:32768",
"address": "localhost:32769",
"type": "prometheus"
}
}
31 changes: 13 additions & 18 deletions metricbeat/module/prometheus/query/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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" {
Expand All @@ -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
}
Expand Down

0 comments on commit 8d3dfa2

Please sign in to comment.