From 70a79ffbd4baa074faae27ed28d32367f4ddee60 Mon Sep 17 00:00:00 2001 From: Sergiusz Urbaniak Date: Thu, 2 Jul 2020 13:32:29 +0200 Subject: [PATCH] pkg/rules/rulespb.AlertState: marshal JSON as lowercase Currently, alert state is rendered as upper case. In Prometheus it is lower case. This fixes it. Signed-off-by: Sergiusz Urbaniak --- CHANGELOG.md | 1 + pkg/rules/rulespb/custom.go | 2 +- pkg/rules/rulespb/custom_test.go | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7e2b5889d5..d09d3aa1722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/rules/rulespb/custom.go b/pkg/rules/rulespb/custom.go index 98205960e46..582d055bff3 100644 --- a/pkg/rules/rulespb/custom.go +++ b/pkg/rules/rulespb/custom.go @@ -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: diff --git a/pkg/rules/rulespb/custom_test.go b/pkg/rules/rulespb/custom_test.go index ac2d865b022..a2ba74f45a6 100644 --- a/pkg/rules/rulespb/custom_test.go +++ b/pkg/rules/rulespb/custom_test.go @@ -207,7 +207,7 @@ func TestJSONUnmarshalMarshal(t *testing.T) { Annotations: labels.Labels{ {Name: "annotation1", Value: "2"}, }, - State: "INACTIVE", + State: "inactive", ActiveAt: nil, Value: "1", PartialResponseStrategy: "WARN", @@ -215,7 +215,7 @@ func TestJSONUnmarshalMarshal(t *testing.T) { { Labels: nil, Annotations: nil, - State: "FIRING", + State: "firing", ActiveAt: &twoHoursAgo, Value: "2143", PartialResponseStrategy: "ABORT", @@ -223,7 +223,7 @@ func TestJSONUnmarshalMarshal(t *testing.T) { }, LastError: "1", Duration: 60, - State: "PENDING", + State: "pending", LastEvaluation: now.Add(-1 * time.Minute), EvaluationTime: 1.1, },