(t *testing.T)
| 697 | } |
| 698 | |
| 699 | func 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 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…