MCPcopy
hub / github.com/prometheus/prometheus / TestLabelNames

Function TestLabelNames

web/api/v1/api_test.go:814–919  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

812}
813
814func TestLabelNames(t *testing.T) {
815 // TestEndpoints doesn't have enough label names to test api.labelNames
816 // endpoint properly. Hence we test it separately.
817 s := promqltest.LoadedStorage(t, `
818 load 1m
819 test_metric1{foo1="bar", baz="abc"} 0+100x100
820 test_metric1{foo2="boo"} 1+0x100
821 test_metric2{foo="boo"} 1+0x100
822 test_metric2{foo="boo", xyz="qwerty"} 1+0x100
823 test_metric2{foo="baz", abc="qwerty"} 1+0x100
824 `)
825
826 api := &API{
827 Queryable: s,
828 parser: testParser,
829 }
830 request := func(method, limit string, matchers ...string) (*http.Request, error) {
831 u, err := url.Parse("http://example.com")
832 require.NoError(t, err)
833 q := u.Query()
834 for _, matcher := range matchers {
835 q.Add("match[]", matcher)
836 }
837 if limit != "" {
838 q.Add("limit", limit)
839 }
840 u.RawQuery = q.Encode()
841
842 r, err := http.NewRequest(method, u.String(), http.NoBody)
843 if method == http.MethodPost {
844 r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
845 }
846 return r, err
847 }
848
849 for _, tc := range []struct {
850 name string
851 api *API
852 matchers []string
853 limit string
854 expected []string
855 expectedErrorType errorType
856 }{
857 {
858 name: "no matchers",
859 expected: []string{"__name__", "abc", "baz", "foo", "foo1", "foo2", "xyz"},
860 api: api,
861 },
862 {
863 name: "non empty label matcher",
864 matchers: []string{`{foo=~".+"}`},
865 expected: []string{"__name__", "abc", "foo", "xyz"},
866 api: api,
867 },
868 {
869 name: "non empty label matcher with limit",
870 matchers: []string{`{foo=~".+"}`},
871 expected: []string{"__name__", "abc"},

Callers

nothing calls this directly

Calls 11

LoadedStorageFunction · 0.92
assertAPIErrorFunction · 0.85
assertAPIResponseFunction · 0.85
ParseMethod · 0.65
QueryMethod · 0.65
AddMethod · 0.65
EncodeMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65
RunMethod · 0.65
labelNamesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…