Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/v2/targetgroup.go
5340 views
1
package integrations
2
3
import (
4
"encoding/json"
5
6
"github.com/prometheus/common/model"
7
"github.com/prometheus/prometheus/discovery/targetgroup"
8
)
9
10
// targetGroup implements json.Marshaler for targetgroup.Group. This is
11
// required do to an issue with Prometheus: HTTP SD expects to be unmarshaled
12
// as JSON, but the form it expects to unmarshal the target groups in is not the form
13
// it marshals out to JSON as.
14
type targetGroup targetgroup.Group
15
16
func (tg *targetGroup) MarshalJSON() ([]byte, error) {
17
g := &struct {
18
Targets []string `json:"targets"`
19
Labels model.LabelSet `json:"labels,omitempty"`
20
}{
21
Targets: make([]string, 0, len(tg.Targets)),
22
Labels: tg.Labels,
23
}
24
for _, t := range tg.Targets {
25
g.Targets = append(g.Targets, string(t[model.AddressLabel]))
26
}
27
return json.Marshal(g)
28
}
29
30