Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: Fix rendered JSON state value for rules and alerts should be in lowercase #2834

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel

* [#2665](https://github.com/thanos-io/thanos/pull/2665) Swift: fix issue with missing Content-Type HTTP headers.
- [#2800](https://github.com/thanos-io/thanos/pull/2800) Query: Fix handling of `--web.external-prefix` and `--web.route-prefix`
- [#2834](https://github.com/thanos-io/thanos/pull/2834) Query: Fix rendered JSON state value for rules and alerts should be in lowercase

### Changed

Expand Down
8 changes: 4 additions & 4 deletions pkg/query/api/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@ func TestRulesHandler(t *testing.T) {
Type: "recording",
},
testpromcompatibility.AlertingRule{
State: all[2].GetAlert().State.String(),
State: strings.ToLower(all[2].GetAlert().State.String()),
Name: all[2].GetAlert().Name,
Query: all[2].GetAlert().Query,
Labels: storepb.LabelsToPromLabels(all[2].GetAlert().Labels.Labels),
Expand All @@ -1332,15 +1332,15 @@ func TestRulesHandler(t *testing.T) {
{
Labels: storepb.LabelsToPromLabels(all[2].GetAlert().Alerts[0].Labels.Labels),
Annotations: storepb.LabelsToPromLabels(all[2].GetAlert().Alerts[0].Annotations.Labels),
State: all[2].GetAlert().Alerts[0].State.String(),
State: strings.ToLower(all[2].GetAlert().Alerts[0].State.String()),
ActiveAt: all[2].GetAlert().Alerts[0].ActiveAt,
Value: all[2].GetAlert().Alerts[0].Value,
PartialResponseStrategy: all[2].GetAlert().Alerts[0].PartialResponseStrategy.String(),
},
{
Labels: storepb.LabelsToPromLabels(all[2].GetAlert().Alerts[1].Labels.Labels),
Annotations: storepb.LabelsToPromLabels(all[2].GetAlert().Alerts[1].Annotations.Labels),
State: all[2].GetAlert().Alerts[1].State.String(),
State: strings.ToLower(all[2].GetAlert().Alerts[1].State.String()),
ActiveAt: all[2].GetAlert().Alerts[1].ActiveAt,
Value: all[2].GetAlert().Alerts[1].Value,
PartialResponseStrategy: all[2].GetAlert().Alerts[1].PartialResponseStrategy.String(),
Expand All @@ -1349,7 +1349,7 @@ func TestRulesHandler(t *testing.T) {
Type: "alerting",
},
testpromcompatibility.AlertingRule{
State: all[3].GetAlert().State.String(),
State: strings.ToLower(all[3].GetAlert().State.String()),
Name: all[3].GetAlert().Name,
Query: all[3].GetAlert().Query,
Labels: storepb.LabelsToPromLabels(all[3].GetAlert().Labels.Labels),
Expand Down
2 changes: 1 addition & 1 deletion pkg/rules/rulespb/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (x *AlertState) UnmarshalJSON(entry []byte) error {
}

func (x *AlertState) MarshalJSON() ([]byte, error) {
return []byte(strconv.Quote(x.String())), nil
return []byte(strconv.Quote(strings.ToLower(x.String()))), nil
}

// Compare compares alert state x and y and returns:
Expand Down
6 changes: 3 additions & 3 deletions pkg/rules/rulespb/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,23 @@ func TestJSONUnmarshalMarshal(t *testing.T) {
Annotations: labels.Labels{
{Name: "annotation1", Value: "2"},
},
State: "INACTIVE",
State: "inactive",
ActiveAt: nil,
Value: "1",
PartialResponseStrategy: "WARN",
},
{
Labels: nil,
Annotations: nil,
State: "FIRING",
State: "firing",
ActiveAt: &twoHoursAgo,
Value: "2143",
PartialResponseStrategy: "ABORT",
},
},
LastError: "1",
Duration: 60,
State: "PENDING",
State: "pending",
LastEvaluation: now.Add(-1 * time.Minute),
EvaluationTime: 1.1,
},
Expand Down