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

Method SetOverrides

pkg/overrides/api.go:83–126  ·  view source on GitHub ↗

SetOverrides updates overrides for a specific tenant

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

81
82// SetOverrides updates overrides for a specific tenant
83func (a *API) SetOverrides(w http.ResponseWriter, r *http.Request) {
84 userID, _, err := users.ExtractTenantIDFromHTTPRequest(r)
85 if err != nil {
86 http.Error(w, err.Error(), http.StatusBadRequest)
87 return
88 }
89
90 var overrides map[string]any
91 if err := json.NewDecoder(r.Body).Decode(&overrides); err != nil {
92 http.Error(w, ErrInvalidJSON, http.StatusBadRequest)
93 return
94 }
95
96 // Get allowed limits from runtime config
97 allowedLimits, err := a.getAllowedLimitsFromBucket(r.Context())
98 if err != nil {
99 level.Error(a.logger).Log("msg", "failed to get allowed limits from bucket", "userID", userID, "err", err)
100 http.Error(w, "Internal server error", http.StatusInternalServerError)
101 return
102 }
103
104 // Validate that only allowed limits are being changed
105 if err := ValidateOverrides(overrides, allowedLimits); err != nil {
106 level.Error(a.logger).Log("msg", "invalid overrides validation", "userID", userID, "err", err)
107 http.Error(w, "Invalid overrides", http.StatusBadRequest)
108 return
109 }
110
111 // Validate that values don't exceed hard limits from runtime config
112 if err := a.validateHardLimits(overrides, userID); err != nil {
113 level.Error(a.logger).Log("msg", "hard limits validation failed", "userID", userID, "err", err)
114 http.Error(w, "Invalid overrides", http.StatusBadRequest)
115 return
116 }
117
118 // Write overrides to bucket storage
119 if err := a.setOverridesToBucket(r.Context(), userID, overrides); err != nil {
120 level.Error(a.logger).Log("msg", "failed to set overrides to bucket", "userID", userID, "err", err)
121 http.Error(w, "Internal server error", http.StatusInternalServerError)
122 return
123 }
124
125 w.WriteHeader(http.StatusOK)
126}
127
128// DeleteOverrides removes tenant-specific overrides
129func (a *API) DeleteOverrides(w http.ResponseWriter, r *http.Request) {

Callers 2

TestAPIEndpointsFunction · 0.80
TestAPIBucketErrorsFunction · 0.80

Calls 9

validateHardLimitsMethod · 0.95
setOverridesToBucketMethod · 0.95
ValidateOverridesFunction · 0.85
DecodeMethod · 0.65
ErrorMethod · 0.45
ContextMethod · 0.45
LogMethod · 0.45

Tested by 2

TestAPIEndpointsFunction · 0.64
TestAPIBucketErrorsFunction · 0.64