MCPcopy
hub / github.com/prometheus/prometheus / TestQueryExemplars

Function TestQueryExemplars

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

Source from the content-addressed store, hash-verified

697}
698
699func TestQueryExemplars(t *testing.T) {
700 start := time.Unix(0, 0)
701 s := promqltest.LoadedStorage(t, `
702 load 1m
703 test_metric1{foo="bar"} 0+100x100
704 test_metric1{foo="boo"} 1+0x100
705 test_metric2{foo="boo"} 1+0x100
706 test_metric3{foo="bar", dup="1"} 1+0x100
707 test_metric3{foo="boo", dup="1"} 1+0x100
708 test_metric4{foo="bar", dup="1"} 1+0x100
709 test_metric4{foo="boo", dup="1"} 1+0x100
710 test_metric4{foo="boo"} 1+0x100
711 `)
712
713 api := &API{
714 Queryable: s,
715 QueryEngine: testEngine(t),
716 ExemplarQueryable: s,
717 parser: testParser,
718 }
719
720 request := func(method string, qs url.Values) (*http.Request, error) {
721 u, err := url.Parse("http://example.com")
722 require.NoError(t, err)
723 u.RawQuery = qs.Encode()
724 r, err := http.NewRequest(method, u.String(), http.NoBody)
725 if method == http.MethodPost {
726 r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
727 }
728 return r, err
729 }
730
731 for _, tc := range []struct {
732 name string
733 query url.Values
734 exemplars []exemplar.QueryResult
735 api *API
736 expectedErrorType errorType
737 }{
738 {
739 name: "no error",
740 api: api,
741 query: url.Values{
742 "query": []string{`test_metric3{foo="boo"} - test_metric4{foo="bar"}`},
743 "start": []string{"0"},
744 "end": []string{"4"},
745 },
746 exemplars: []exemplar.QueryResult{
747 {
748 SeriesLabels: labels.FromStrings("__name__", "test_metric3", "foo", "boo", "dup", "1"),
749 Exemplars: []exemplar.Exemplar{
750 {
751 Labels: labels.FromStrings("id", "abc"),
752 Value: 10,
753 Ts: timestamp.FromTime(start.Add(0 * time.Second)),
754 },
755 },
756 },

Callers

nothing calls this directly

Calls 14

LoadedStorageFunction · 0.92
FromStringsFunction · 0.92
FromTimeFunction · 0.92
appendExemplarsFunction · 0.85
assertAPIErrorFunction · 0.85
assertAPIResponseFunction · 0.85
queryExemplarsMethod · 0.80
testEngineFunction · 0.70
ParseMethod · 0.65
EncodeMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…