Skip to content

Commit 8ba408b

Browse files
committed
modernize?
Signed-off-by: Bogdan Stancu <[email protected]>
1 parent 06195e0 commit 8ba408b

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

pkg/overrides/api.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (a *API) SetOverrides(w http.ResponseWriter, r *http.Request) {
7878
return
7979
}
8080

81-
var overrides map[string]interface{}
81+
var overrides map[string]any
8282
if err := json.NewDecoder(r.Body).Decode(&overrides); err != nil {
8383
http.Error(w, ErrInvalidJSON, http.StatusBadRequest)
8484
return
@@ -134,7 +134,7 @@ func (a *API) DeleteOverrides(w http.ResponseWriter, r *http.Request) {
134134
}
135135

136136
// getOverridesFromBucket reads overrides for a specific tenant from the runtime config file
137-
func (a *API) getOverridesFromBucket(ctx context.Context, userID string) (map[string]interface{}, error) {
137+
func (a *API) getOverridesFromBucket(ctx context.Context, userID string) (map[string]any, error) {
138138
reader, err := a.bucketClient.Get(ctx, a.runtimeConfigPath)
139139
if err != nil {
140140
return nil, fmt.Errorf("failed to get runtime config: %w", err)
@@ -155,7 +155,7 @@ func (a *API) getOverridesFromBucket(ctx context.Context, userID string) (map[st
155155
return nil, fmt.Errorf("failed to marshal limits: %w", err)
156156
}
157157

158-
var result map[string]interface{}
158+
var result map[string]any
159159
if err := yaml.Unmarshal(yamlData, &result); err != nil {
160160
return nil, fmt.Errorf("failed to unmarshal limits: %w", err)
161161
}
@@ -167,11 +167,11 @@ func (a *API) getOverridesFromBucket(ctx context.Context, userID string) (map[st
167167
}
168168

169169
// No tenant limits configured - return empty map (no overrides)
170-
return map[string]interface{}{}, nil
170+
return map[string]any{}, nil
171171
}
172172

173173
// setOverridesToBucket writes overrides for a specific tenant to the runtime config file
174-
func (a *API) setOverridesToBucket(ctx context.Context, userID string, overrides map[string]interface{}) error {
174+
func (a *API) setOverridesToBucket(ctx context.Context, userID string, overrides map[string]any) error {
175175
var config runtimeconfig.RuntimeConfigValues
176176
reader, err := a.bucketClient.Get(ctx, a.runtimeConfigPath)
177177
if err == nil {

pkg/overrides/limits.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
// No default allowed limits - these must be configured via runtime config
2222

2323
// ValidateOverrides checks if the provided overrides only contain allowed limits
24-
func ValidateOverrides(overrides map[string]interface{}, allowedLimits []string) error {
24+
func ValidateOverrides(overrides map[string]any, allowedLimits []string) error {
2525
var invalidLimits []string
2626

2727
for limitName := range overrides {
@@ -38,7 +38,7 @@ func ValidateOverrides(overrides map[string]interface{}, allowedLimits []string)
3838
}
3939

4040
// validateHardLimits checks if the provided overrides exceed any hard limits from the runtime config
41-
func (a *API) validateHardLimits(overrides map[string]interface{}, userID string) error {
41+
func (a *API) validateHardLimits(overrides map[string]any, userID string) error {
4242
// Read the runtime config to get hard limits
4343
reader, err := a.bucketClient.Get(context.Background(), a.runtimeConfigPath)
4444
if err != nil {
@@ -70,7 +70,7 @@ func (a *API) validateHardLimits(overrides map[string]interface{}, userID string
7070
return fmt.Errorf("failed to validate hard limits")
7171
}
7272

73-
var hardLimitsMap map[string]interface{}
73+
var hardLimitsMap map[string]any
7474
if err := yaml.Unmarshal(yamlData, &hardLimitsMap); err != nil {
7575
level.Error(a.logger).Log("msg", "failed to unmarshal hard limits", "userID", userID, "err", err)
7676
return fmt.Errorf("failed to validate hard limits")
@@ -89,7 +89,7 @@ func (a *API) validateHardLimits(overrides map[string]interface{}, userID string
8989
}
9090

9191
// validateSingleHardLimit validates a single limit against its hard limit
92-
func (a *API) validateSingleHardLimit(limitName string, value, hardLimit interface{}) error {
92+
func (a *API) validateSingleHardLimit(limitName string, value, hardLimit any) error {
9393
// Convert both values to float64 for comparison
9494
valueFloat, err := convertToFloat64(value)
9595
if err != nil {
@@ -109,7 +109,7 @@ func (a *API) validateSingleHardLimit(limitName string, value, hardLimit interfa
109109
}
110110

111111
// convertToFloat64 converts any value to float64
112-
func convertToFloat64(v interface{}) (float64, error) {
112+
func convertToFloat64(v any) (float64, error) {
113113
switch val := v.(type) {
114114
case float64:
115115
return val, nil

pkg/overrides/overrides_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestAPIEndpoints(t *testing.T) {
159159
method string
160160
path string
161161
tenantID string
162-
requestBody interface{}
162+
requestBody any
163163
expectedStatus int
164164
setupMock func(*bucket.ClientMock)
165165
validateResponse func(*testing.T, *httptest.ResponseRecorder)
@@ -182,7 +182,7 @@ func TestAPIEndpoints(t *testing.T) {
182182
mock.MockGet("runtime.yaml", "overrides:\n", nil)
183183
},
184184
validateResponse: func(t *testing.T, recorder *httptest.ResponseRecorder) {
185-
var response map[string]interface{}
185+
var response map[string]any
186186
err := json.Unmarshal(recorder.Body.Bytes(), &response)
187187
require.NoError(t, err)
188188
assert.Empty(t, response)
@@ -202,7 +202,7 @@ func TestAPIEndpoints(t *testing.T) {
202202
mock.MockGet("runtime.yaml", overridesData, nil)
203203
},
204204
validateResponse: func(t *testing.T, recorder *httptest.ResponseRecorder) {
205-
var response map[string]interface{}
205+
var response map[string]any
206206
err := json.Unmarshal(recorder.Body.Bytes(), &response)
207207
require.NoError(t, err)
208208
assert.Equal(t, float64(5000), response["ingestion_rate"])
@@ -228,15 +228,15 @@ func TestAPIEndpoints(t *testing.T) {
228228
method: "POST",
229229
path: "/api/v1/user-overrides",
230230
tenantID: "",
231-
requestBody: map[string]interface{}{"ingestion_rate": 5000},
231+
requestBody: map[string]any{"ingestion_rate": 5000},
232232
expectedStatus: http.StatusUnauthorized,
233233
},
234234
{
235235
name: "POST overrides - valid tenant ID, valid overrides",
236236
method: "POST",
237237
path: "/api/v1/user-overrides",
238238
tenantID: "user789",
239-
requestBody: map[string]interface{}{"ingestion_rate": 5000, "ruler_max_rules_per_rule_group": 10},
239+
requestBody: map[string]any{"ingestion_rate": 5000, "ruler_max_rules_per_rule_group": 10},
240240
expectedStatus: http.StatusOK,
241241
setupMock: func(mock *bucket.ClientMock) {
242242
// Mock runtime config with allowed limits
@@ -262,7 +262,7 @@ api_allowed_limits:
262262
method: "POST",
263263
path: "/api/v1/user-overrides",
264264
tenantID: "user999",
265-
requestBody: map[string]interface{}{"invalid_limit": 5000},
265+
requestBody: map[string]any{"invalid_limit": 5000},
266266
expectedStatus: http.StatusBadRequest,
267267
setupMock: func(mock *bucket.ClientMock) {
268268
// Mock runtime config with allowed limits (invalid_limit not included)
@@ -290,7 +290,7 @@ api_allowed_limits:
290290
method: "POST",
291291
path: "/api/v1/user-overrides",
292292
tenantID: "user999",
293-
requestBody: map[string]interface{}{"ingestion_rate": 1500000}, // Exceeds hard limit of 1000000
293+
requestBody: map[string]any{"ingestion_rate": 1500000}, // Exceeds hard limit of 1000000
294294
expectedStatus: http.StatusBadRequest,
295295
setupMock: func(mock *bucket.ClientMock) {
296296
// Mock runtime config with per-user hard limits and allowed limits
@@ -577,7 +577,7 @@ api_allowed_limits:
577577
// Create the request
578578
var req *http.Request
579579
if tt.method == "POST" {
580-
requestBody := map[string]interface{}{"ingestion_rate": 5000}
580+
requestBody := map[string]any{"ingestion_rate": 5000}
581581
body, err := json.Marshal(requestBody)
582582
require.NoError(t, err)
583583
req = httptest.NewRequest(tt.method, "/api/v1/user-overrides", bytes.NewReader(body))

0 commit comments

Comments
 (0)