Skip to content

Commit cd7d229

Browse files
committed
fix response to omitempty (#5953)
Signed-off-by: Ben Ye <[email protected]>
1 parent a99ed24 commit cd7d229

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master / unreleased
44

5+
## 1.17.1 2024-05-20
6+
7+
* [CHANGE] Query Frontend/Ruler: Omit empty data field in API response. #5953
8+
59
## 1.17.0 2024-04-30
610

711
* [CHANGE] Azure Storage: Upgraded objstore dependency and support Azure Workload Identity Authentication. Added `connection_string` to support authenticating via SAS token. Marked `msi_resource` config as deprecating. #5645

pkg/ruler/api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@ func TestRuler_DeleteNamespace(t *testing.T) {
337337

338338
router.ServeHTTP(w, req)
339339
require.Equal(t, http.StatusAccepted, w.Code)
340-
require.Equal(t, "{\"status\":\"success\",\"data\":null,\"errorType\":\"\",\"error\":\"\"}", w.Body.String())
340+
require.Equal(t, "{\"status\":\"success\",\"errorType\":\"\",\"error\":\"\"}", w.Body.String())
341341

342342
// On Partial failures
343343
req = requestFor(t, http.MethodDelete, "https://localhost:8080/api/v1/rules/namespace2", nil, "user1")
344344
w = httptest.NewRecorder()
345345

346346
router.ServeHTTP(w, req)
347347
require.Equal(t, http.StatusInternalServerError, w.Code)
348-
require.Equal(t, "{\"status\":\"error\",\"data\":null,\"errorType\":\"server_error\",\"error\":\"unable to delete rg\"}", w.Body.String())
348+
require.Equal(t, "{\"status\":\"error\",\"errorType\":\"server_error\",\"error\":\"unable to delete rg\"}", w.Body.String())
349349
}
350350

351351
func TestRuler_LimitsPerGroup(t *testing.T) {
@@ -430,7 +430,7 @@ rules:
430430
- record: up_rule
431431
expr: up{}
432432
`,
433-
output: "{\"status\":\"success\",\"data\":null,\"errorType\":\"\",\"error\":\"\"}",
433+
output: "{\"status\":\"success\",\"errorType\":\"\",\"error\":\"\"}",
434434
},
435435
{
436436
name: "when exceeding the rule group limit after sending the first group",
@@ -490,7 +490,7 @@ rules:
490490
expr: |2+
491491
up{}
492492
`,
493-
output: "{\"status\":\"success\",\"data\":null,\"errorType\":\"\",\"error\":\"\"}",
493+
output: "{\"status\":\"success\",\"errorType\":\"\",\"error\":\"\"}",
494494
},
495495
{
496496
name: "when pushing group that CANNOT be safely converted from RuleGroupDesc to RuleGroup yaml",

pkg/util/api/response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
// Response defines the Prometheus response format.
2020
type Response struct {
2121
Status string `json:"status"`
22-
Data interface{} `json:"data"`
22+
Data interface{} `json:"data,omitempty"`
2323
ErrorType v1.ErrorType `json:"errorType"`
2424
Error string `json:"error"`
2525
Warnings []string `json:"warnings,omitempty"`

0 commit comments

Comments
 (0)