Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dataType field of query metricset #17383

Merged
merged 5 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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