MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestParseQueryAPIQueryFrontend

Function TestParseQueryAPIQueryFrontend

integration/parse_query_api_test.go:74–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

72}
73
74func TestParseQueryAPIQueryFrontend(t *testing.T) {
75 s, err := e2e.NewScenario(networkName)
76 require.NoError(t, err)
77 defer s.Close()
78
79 // Start dependencies.
80 consul := e2edb.NewConsul()
81 minio := e2edb.NewMinio(9000, bucketName)
82 require.NoError(t, s.StartAndWaitReady(consul, minio))
83
84 flags := mergeFlags(BlocksStorageFlags(), map[string]string{
85 "-auth.enabled": "true",
86 })
87
88 // Start the query-frontend.
89 queryFrontend := e2ecortex.NewQueryFrontend("query-frontend", flags, "")
90 require.NoError(t, s.Start(queryFrontend))
91
92 distributor := e2ecortex.NewDistributor("distributor", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "")
93 ingester := e2ecortex.NewIngester("ingester", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "")
94 require.NoError(t, s.StartAndWaitReady(distributor, ingester))
95
96 // Wait until both the distributor updated the ring.
97 require.NoError(t, distributor.WaitSumMetrics(e2e.Equals(512), "cortex_ring_tokens_total"))
98
99 querier := e2ecortex.NewQuerier("querierWithFrontend", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), mergeFlags(flags, map[string]string{
100 "-querier.frontend-address": queryFrontend.NetworkGRPCEndpoint(),
101 }), "")
102
103 require.NoError(t, s.StartAndWaitReady(querier))
104 require.NoError(t, s.WaitReady(queryFrontend))
105
106 require.NoError(t, querier.WaitSumMetrics(e2e.Equals(512), "cortex_ring_tokens_total"))
107
108 endpoint := fmt.Sprintf("http://%s/api/prom/api/v1/parse_query?query=foo/bar", queryFrontend.HTTPEndpoint())
109
110 req, err := http.NewRequest("GET", endpoint, nil)
111 require.NoError(t, err)
112 req.Header.Set("X-Scope-OrgID", "user-1")
113
114 resp, err := http.DefaultClient.Do(req)
115 require.NoError(t, err)
116 defer resp.Body.Close()
117
118 body, err := io.ReadAll(resp.Body)
119 require.NoError(t, err)
120
121 require.Equal(t, http.StatusOK, resp.StatusCode)
122
123 var parsed struct {
124 Status string `json:"status"`
125 Data json.RawMessage `json:"data"`
126 }
127 require.NoError(t, json.Unmarshal(body, &parsed))
128 require.Equal(t, "success", parsed.Status)
129
130 // check for AST contents.
131 require.Contains(t, string(parsed.Data), "\"op\":\"/\"")

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
StartMethod · 0.95
WaitReadyMethod · 0.95
NewScenarioFunction · 0.92
NewQueryFrontendFunction · 0.92
NewDistributorFunction · 0.92
NewIngesterFunction · 0.92
EqualsFunction · 0.92
NewQuerierFunction · 0.92
NetworkHTTPEndpointMethod · 0.80
NetworkGRPCEndpointMethod · 0.80

Tested by

no test coverage detected