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

Function TestOverridesAPIHardLimits

integration/overrides_test.go:202–288  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

200}
201
202func TestOverridesAPIHardLimits(t *testing.T) {
203 s, err := e2e.NewScenario(networkName)
204 require.NoError(t, err)
205 defer s.Close()
206
207 minio := e2edb.NewMinio(9001, "cortex")
208 require.NoError(t, s.StartAndWaitReady(minio))
209
210 // Runtime config with hard limits
211 runtimeConfig := map[string]interface{}{
212 "overrides": map[string]interface{}{},
213 "hard_overrides": map[string]interface{}{
214 "user1": map[string]interface{}{
215 "ingestion_rate": 10000,
216 "max_global_series_per_user": 50000,
217 },
218 },
219 "api_allowed_limits": []string{
220 "ingestion_rate",
221 "max_global_series_per_user",
222 },
223 }
224 uploadRuntimeConfig(t, minio, runtimeConfig)
225
226 cortexSvc := e2ecortex.NewSingleBinary("cortex-overrides-hard-limits", defaultArgsOverrides(minio), "")
227 require.NoError(t, s.StartAndWaitReady(cortexSvc))
228
229 t.Run("POST overrides within hard limits", func(t *testing.T) {
230 overrides := map[string]interface{}{
231 "ingestion_rate": 5000, // Within hard limit of 10000
232 "max_global_series_per_user": 25000, // Within hard limit of 50000
233 }
234 requestBody, err := json.Marshal(overrides)
235 require.NoError(t, err)
236
237 req, err := http.NewRequest("POST", "http://"+cortexSvc.HTTPEndpoint()+"/api/v1/user-overrides", bytes.NewReader(requestBody))
238 require.NoError(t, err)
239 req.Header.Set("X-Scope-OrgID", "user1")
240 req.Header.Set("Content-Type", "application/json")
241
242 resp, err := http.DefaultClient.Do(req)
243 require.NoError(t, err)
244 defer resp.Body.Close()
245
246 assert.Equal(t, http.StatusOK, resp.StatusCode)
247 })
248
249 t.Run("POST overrides exceeding hard limits", func(t *testing.T) {
250 overrides := map[string]interface{}{
251 "ingestion_rate": 15000, // Exceeds hard limit of 10000
252 }
253 requestBody, err := json.Marshal(overrides)
254 require.NoError(t, err)
255
256 req, err := http.NewRequest("POST", "http://"+cortexSvc.HTTPEndpoint()+"/api/v1/user-overrides", bytes.NewReader(requestBody))
257 require.NoError(t, err)
258 req.Header.Set("X-Scope-OrgID", "user1")
259 req.Header.Set("Content-Type", "application/json")

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
StopMethod · 0.95
NewScenarioFunction · 0.92
NewSingleBinaryFunction · 0.92
uploadRuntimeConfigFunction · 0.85
defaultArgsOverridesFunction · 0.85
HTTPEndpointMethod · 0.80
RunMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected