Skip to content

Commit

Permalink
fix response to omitempty (#5953)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 committed May 15, 2024
1 parent 2948539 commit 23b4148
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [ENHANCEMENT] Distributor/Ring: Allow disabling detailed ring metrics by ring member. #5931
* [ENHANCEMENT] KV: Etcd Added etcd.ping-without-stream-allowed parameter to disable/enable PermitWithoutStream #5933
* [CHANGE] Upgrade Dockerfile Node version from 14x to 18x. #5906
* [CHANGE] Query Frontend/Ruler: Omit empty data field in API response. #5953
* [BUGFIX] Configsdb: Fix endline issue in db password. #5920
* [BUGFIX] Ingester: Fix `user` and `type` labels for the `cortex_ingester_tsdb_head_samples_appended_total` TSDB metric. #5952

Expand Down
8 changes: 4 additions & 4 deletions pkg/ruler/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,15 @@ func TestRuler_DeleteNamespace(t *testing.T) {

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

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

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

func TestRuler_LimitsPerGroup(t *testing.T) {
Expand Down Expand Up @@ -430,7 +430,7 @@ rules:
- record: up_rule
expr: up{}
`,
output: "{\"status\":\"success\",\"data\":null,\"errorType\":\"\",\"error\":\"\"}",
output: "{\"status\":\"success\",\"errorType\":\"\",\"error\":\"\"}",
},
{
name: "when exceeding the rule group limit after sending the first group",
Expand Down Expand Up @@ -490,7 +490,7 @@ rules:
expr: |2+
up{}
`,
output: "{\"status\":\"success\",\"data\":null,\"errorType\":\"\",\"error\":\"\"}",
output: "{\"status\":\"success\",\"errorType\":\"\",\"error\":\"\"}",
},
{
name: "when pushing group that CANNOT be safely converted from RuleGroupDesc to RuleGroup yaml",
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
// Response defines the Prometheus response format.
type Response struct {
Status string `json:"status"`
Data interface{} `json:"data"`
Data interface{} `json:"data,omitempty"`
ErrorType v1.ErrorType `json:"errorType"`
Error string `json:"error"`
Warnings []string `json:"warnings,omitempty"`
Expand Down

0 comments on commit 23b4148

Please sign in to comment.