fixes for ZMON client

Changes:
- only add group_by "key" if key is provided
- remove deprecated aggregators "dev" and "first"
- add X-Attribution header for query attribution

Signed-off-by: ☃ pitr <peter.vernigorov@zalando.de>
This commit is contained in:
☃ pitr 2021-07-24 21:38:56 +02:00
parent eefd5ef512
commit 1d4beab7a4

View File

@ -15,9 +15,7 @@ var (
// https://kairosdb.github.io/docs/build/html/restapi/Aggregators.html
validAggregators = map[string]struct{}{
"avg": struct{}{},
"dev": struct{}{},
"count": struct{}{},
"first": struct{}{},
"last": struct{}{},
"max": struct{}{},
"min": struct{}{},
@ -115,14 +113,7 @@ func (c *Client) Query(checkID int, key string, tags map[string]string, aggregat
Name: fmt.Sprintf("zmon.check.%d", checkID),
Limit: 10000, // maximum limit of ZMON
Tags: tagsSlice,
GroupBy: []tagGroup{
{
Name: "tag",
Tags: []string{
"key",
},
},
},
GroupBy: []tagGroup{},
Aggregators: make([]aggregator, 0, len(aggregators)),
},
},
@ -142,6 +133,10 @@ func (c *Client) Query(checkID int, key string, tags map[string]string, aggregat
// add key to query if defined
if key != "" {
query.Metrics[0].Tags["key"] = []string{key}
query.Metrics[0].GroupBy = append(query.Metrics[0].GroupBy, tagGroup{
Name: "tag",
Tags: []string{"key"},
})
}
body, err := json.Marshal(&query)
@ -158,6 +153,7 @@ func (c *Client) Query(checkID int, key string, tags map[string]string, aggregat
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("X-Attribution", fmt.Sprintf("kube-metrics-adapter/%d", checkID))
resp, err := c.http.Do(req)
if err != nil {