forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape_configs.go
49 lines (42 loc) · 1.21 KB
/
scrape_configs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package linkerd
import (
"bytes"
"text/template"
"github.com/prometheus/prometheus/config"
"github.com/solo-io/go-utils/errors"
"gopkg.in/yaml.v2"
)
func PrometheusScrapeConfigs(linkerdNamespace string) ([]*config.ScrapeConfig, error) {
buf := &bytes.Buffer{}
if err := linkerdScrapeConfigsYamlTemplate.Execute(buf, struct {
Namespace string
}{
Namespace: linkerdNamespace,
}); err != nil {
return nil, errors.Wrapf(err, "failed to execute linkerdScrapeConfigsYaml template")
}
var scrapeConfigs []*config.ScrapeConfig
if err := yaml.Unmarshal(buf.Bytes(), &scrapeConfigs); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal linkerdScrapeConfigsYaml")
}
return scrapeConfigs, nil
}
// imported from default linkerd install
var linkerdScrapeConfigsYamlTemplate = template.Must(template.New("linkerd-scrape-configs").Parse(`
- job_name: 'linkerd'
kubernetes_sd_configs:
- role: pod
namespaces:
names: ['{{.Namespace}}']
relabel_configs:
- source_labels:
- __meta_kubernetes_pod_container_name
action: keep
regex: ^prometheus$
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="linkerd-proxy"}'
- '{job="linkerd-controller"}'
`))