Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/phlare/scrape/target_test.go
4096 views
1
package scrape
2
3
import (
4
"net/url"
5
"sort"
6
"testing"
7
8
"github.com/prometheus/common/model"
9
"github.com/prometheus/prometheus/discovery/targetgroup"
10
"github.com/prometheus/prometheus/model/labels"
11
"github.com/stretchr/testify/require"
12
)
13
14
func Test_targetsFromGroup(t *testing.T) {
15
args := NewDefaultArguments()
16
args.ProfilingConfig.Block.Enabled = false
17
args.ProfilingConfig.Goroutine.Enabled = false
18
args.ProfilingConfig.Mutex.Enabled = false
19
20
active, dropped, err := targetsFromGroup(&targetgroup.Group{
21
Targets: []model.LabelSet{
22
{model.AddressLabel: "localhost:9090"},
23
},
24
Labels: model.LabelSet{"foo": "bar"},
25
}, args)
26
expected := []*Target{
27
NewTarget(
28
labels.FromMap(map[string]string{
29
model.AddressLabel: "localhost:9090",
30
model.MetricNameLabel: pprofMemory,
31
ProfilePath: "/debug/pprof/allocs",
32
model.SchemeLabel: "http",
33
"foo": "bar",
34
"instance": "localhost:9090",
35
}),
36
labels.FromMap(map[string]string{
37
model.AddressLabel: "localhost:9090",
38
model.MetricNameLabel: pprofMemory,
39
ProfilePath: "/debug/pprof/allocs",
40
model.SchemeLabel: "http",
41
"foo": "bar",
42
}),
43
url.Values{}),
44
NewTarget(
45
labels.FromMap(map[string]string{
46
model.AddressLabel: "localhost:9090",
47
model.MetricNameLabel: pprofProcessCPU,
48
ProfilePath: "/debug/pprof/profile",
49
model.SchemeLabel: "http",
50
"foo": "bar",
51
"instance": "localhost:9090",
52
}),
53
labels.FromMap(map[string]string{
54
model.AddressLabel: "localhost:9090",
55
model.MetricNameLabel: pprofProcessCPU,
56
ProfilePath: "/debug/pprof/profile",
57
model.SchemeLabel: "http",
58
"foo": "bar",
59
}),
60
url.Values{"seconds": []string{"14"}}),
61
}
62
require.NoError(t, err)
63
sort.Sort(Targets(active))
64
sort.Sort(Targets(expected))
65
require.Equal(t, expected, active)
66
require.Empty(t, dropped)
67
}
68
69