Skip to content

Commit c7934e8

Browse files
committed
fix response to omitempty
Signed-off-by: Ben Ye <[email protected]>
1 parent 2527f9e commit c7934e8

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [ENHANCEMENT] Distributor/Ring: Allow disabling detailed ring metrics by ring member. #5931
1010
* [ENHANCEMENT] KV: Etcd Added etcd.ping-without-stream-allowed parameter to disable/enable PermitWithoutStream #5933
1111
* [CHANGE] Upgrade Dockerfile Node version from 14x to 18x. #5906
12+
* [CHANGE] Query Frontend/Ruler: Omit empty data field in API response. #5953
1213
* [BUGFIX] Configsdb: Fix endline issue in db password. #5920
1314
* [BUGFIX] Ingester: Fix `user` and `type` labels for the `cortex_ingester_tsdb_head_samples_appended_total` TSDB metric. #5952
1415

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)