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