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

Function TestOverridesAPIWithRunningCortex

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

Source from the content-addressed store, hash-verified

48}
49
50func TestOverridesAPIWithRunningCortex(t *testing.T) {
51 s, err := e2e.NewScenario(networkName)
52 require.NoError(t, err)
53 defer s.Close()
54
55 minio := e2edb.NewMinio(9000, "cortex")
56 require.NoError(t, s.StartAndWaitReady(minio))
57
58 runtimeConfig := map[string]interface{}{
59 "overrides": map[string]interface{}{
60 "user1": map[string]interface{}{
61 "ingestion_rate": 5000,
62 },
63 },
64 "api_allowed_limits": []string{
65 "ingestion_rate",
66 "max_global_series_per_user",
67 "max_global_series_per_metric",
68 "ingestion_burst_size",
69 "ruler_max_rules_per_rule_group",
70 "ruler_max_rule_groups_per_tenant",
71 },
72 }
73 uploadRuntimeConfig(t, minio, runtimeConfig)
74
75 cortexSvc := e2ecortex.NewSingleBinary("cortex-overrides", defaultArgsOverrides(minio), "")
76 require.NoError(t, s.StartAndWaitReady(cortexSvc))
77
78 t.Run("GET overrides for existing user", func(t *testing.T) {
79 req, err := http.NewRequest("GET", "http://"+cortexSvc.HTTPEndpoint()+"/api/v1/user-overrides", nil)
80 require.NoError(t, err)
81 req.Header.Set("X-Scope-OrgID", "user1")
82
83 resp, err := http.DefaultClient.Do(req)
84 require.NoError(t, err)
85 defer resp.Body.Close()
86
87 assert.Equal(t, http.StatusOK, resp.StatusCode)
88
89 var overrides map[string]interface{}
90 err = json.NewDecoder(resp.Body).Decode(&overrides)
91 require.NoError(t, err)
92
93 assert.Equal(t, float64(5000), overrides["ingestion_rate"])
94 })
95
96 t.Run("GET overrides for non-existing user", func(t *testing.T) {
97 req, err := http.NewRequest("GET", "http://"+cortexSvc.HTTPEndpoint()+"/api/v1/user-overrides", nil)
98 require.NoError(t, err)
99 req.Header.Set("X-Scope-OrgID", "user2")
100
101 resp, err := http.DefaultClient.Do(req)
102 require.NoError(t, err)
103 defer resp.Body.Close()
104
105 assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
106 })
107

Callers

nothing calls this directly

Calls 15

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