Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guides/overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Result:
}
```

**Response (200 OK):**
**Response (202 Accepted):**
Returns success with no body.

**Response (400 Bad Request):**
Expand Down
12 changes: 9 additions & 3 deletions pkg/overrides/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ func (a *API) GetOverrides(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(overrides); err != nil {

// Buffer the response before writing headers so http.Error works if encoding fails
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(overrides); err != nil {
level.Error(a.logger).Log("msg", "failed to encode overrides response", "err", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
if _, err := w.Write(buf.Bytes()); err != nil {
level.Error(a.logger).Log("msg", "failed to write overrides response", "err", err)
}
}

// SetOverrides updates overrides for a specific tenant
Expand Down Expand Up @@ -122,7 +128,7 @@ func (a *API) SetOverrides(w http.ResponseWriter, r *http.Request) {
return
}

w.WriteHeader(http.StatusOK)
w.WriteHeader(http.StatusAccepted)
}

// DeleteOverrides removes tenant-specific overrides
Expand Down
4 changes: 2 additions & 2 deletions pkg/overrides/overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestAPIEndpoints(t *testing.T) {
path: "/api/v1/user-overrides",
tenantID: "user789",
requestBody: map[string]any{"ingestion_rate": 5000, "ruler_max_rules_per_rule_group": 10},
expectedStatus: http.StatusOK,
expectedStatus: http.StatusAccepted,
setupMock: func(mock *bucket.ClientMock) {
// Mock runtime config with allowed limits
runtimeConfig := `overrides:
Expand Down Expand Up @@ -288,7 +288,7 @@ api_allowed_limits:
path: "/api/v1/user-overrides",
tenantID: "user888",
requestBody: map[string]any{"ingestion_rate": 8000}, // Only update ingestion_rate
expectedStatus: http.StatusOK,
expectedStatus: http.StatusAccepted,
setupMock: func(m *bucket.ClientMock) {
// Mock runtime config with existing overrides for user888
initialConfig := `overrides:
Expand Down
Loading