MCPcopy
hub / github.com/grafana/tempo / TestOverridesAPI_POST

Function TestOverridesAPI_POST

integration/api/overrides_api_test.go:199–334  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

197}
198
199func TestOverridesAPI_POST(t *testing.T) {
200 util.RunIntegrationTests(t, util.TestHarnessConfig{
201 ConfigOverlay: configOverrides,
202 DeploymentMode: util.DeploymentModeSingleBinary,
203 Backends: util.BackendObjectStorageS3, // this test fails on other backends b/c it's testing specific etag related code
204 }, func(h *util.TempoHarness) {
205 t.Run("API returns 428 without if-match header", func(t *testing.T) {
206 baseURL := h.BaseURL()
207
208 req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/overrides", baseURL), strings.NewReader(`{}`))
209 require.NoError(t, err)
210 req.Header.Set("Content-Type", "application/json")
211 req.Header.Set("X-Scope-OrgID", "tenant-post-1")
212
213 resp, err := http.DefaultClient.Do(req)
214 require.NoError(t, err)
215 require.Equal(t, http.StatusPreconditionRequired, resp.StatusCode)
216 err = resp.Body.Close()
217 require.NoError(t, err)
218 })
219
220 t.Run("creates config with If-Match 0 on new tenant", func(t *testing.T) {
221 apiClient := h.APIClientHTTP("tenant-post-2")
222
223 limits := &client.Limits{
224 MetricsGenerator: client.LimitsMetricsGenerator{
225 DisableCollection: boolPtr(true),
226 },
227 CostAttribution: client.CostAttribution{
228 Dimensions: &map[string]string{"host.name": "host_name"},
229 },
230 }
231 setEtag, err := apiClient.SetOverrides(limits, "0")
232 require.NoError(t, err)
233 require.NotEmpty(t, setEtag)
234
235 // verify we can read it back
236 returnedLimits, etag, err := apiClient.GetOverrides()
237 require.NoError(t, err)
238 require.Equal(t, setEtag, etag)
239 require.Equal(t, limits, returnedLimits)
240 disableCollection, ok := returnedLimits.GetMetricsGenerator().GetDisableCollection()
241 require.True(t, ok)
242 require.True(t, disableCollection)
243 })
244
245 t.Run("tenant with existing config returns 412 with If-Match 0", func(t *testing.T) {
246 apiClient := h.APIClientHTTP("tenant-post-3")
247
248 // create initial config for tenant so we can try again
249 limits := &client.Limits{
250 CostAttribution: client.CostAttribution{
251 Dimensions: &map[string]string{"service.name": "service_name"},
252 },
253 }
254 etag, err := apiClient.SetOverrides(limits, "0")
255 require.NotEmpty(t, etag)
256 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

RunIntegrationTestsFunction · 0.92
keysFunction · 0.85
BaseURLMethod · 0.80
APIClientHTTPMethod · 0.80
GetDisableCollectionMethod · 0.80
GetMetricsGeneratorMethod · 0.80
GetProcessorsMethod · 0.80
GetMapMethod · 0.80
boolPtrFunction · 0.70
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected