Skip to content

Commit c930bd6

Browse files
jmoscoso1rootalanprot
authored
fixing unnecessary fields in rule_groups api (#4767)
Signed-off-by: jmoscoso1 <[email protected]> Signed-off-by: jmoscoso1 <[email protected]> Signed-off-by: Alan Protasio <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: Alan Protasio <[email protected]>
1 parent 68e781a commit c930bd6

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## master / unreleased
4+
45
**This release removes support for chunks storage. See below for more.**
56
* [CHANGE] Remove support for chunks storage entirely. If you are using chunks storage on a previous version, you must [migrate your data](https://github.com/cortexproject/cortex/blob/v1.11.1/docs/blocks-storage/migrate-from-chunks-to-blocks.md) on version 1.12 or earlier. Before upgrading to this release, you should also remove any deprecated chunks-related configuration, as this release will no longer accept that. The following flags are gone:
67
- `-dynamodb.*`
@@ -45,6 +46,7 @@
4546
* [FEATURE] Compactor: Added -compactor.blocks-fetch-concurrency` allowing to configure number of go routines for blocks during compaction. #4787
4647
* [FEATURE] Compactor: Added configurations for Azure MSI in blocks-storage, ruler-storage and alertmanager-storage. #4818
4748
* [BUGFIX] Memberlist: Add join with no retrying when starting service. #4804
49+
* [BUGFIX] Ruler: Fix /ruler/rule_groups returns YAML with extra fields #4767
4850

4951
## 1.13.0 2022-07-14
5052

Diff for: pkg/ruler/ruler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ func (r *Ruler) ListAllRules(w http.ResponseWriter, req *http.Request) {
874874
iter := make(chan interface{})
875875

876876
go func() {
877-
util.StreamWriteYAMLResponse(w, iter, logger)
877+
util.StreamWriteYAMLV3Response(w, iter, logger)
878878
close(done)
879879
}()
880880

Diff for: pkg/ruler/ruler_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
"github.com/weaveworks/common/user"
3939
"go.uber.org/atomic"
4040
"google.golang.org/grpc"
41-
"gopkg.in/yaml.v2"
41+
"gopkg.in/yaml.v3"
4242

4343
"github.com/cortexproject/cortex/pkg/chunk/purger"
4444
"github.com/cortexproject/cortex/pkg/cortexpb"
@@ -1123,6 +1123,13 @@ func TestRuler_ListAllRules(t *testing.T) {
11231123
for userID := range mockRules {
11241124
gs[userID] = mockRules[userID].Formatted()
11251125
}
1126+
1127+
// check for unnecessary fields
1128+
unnecessaryFields := []string{"kind", "style", "tag", "value", "anchor", "alias", "content", "headcomment", "linecomment", "footcomment", "line", "column"}
1129+
for _, word := range unnecessaryFields {
1130+
require.NotContains(t, string(body), word)
1131+
}
1132+
11261133
expectedResponse, err := yaml.Marshal(gs)
11271134
require.NoError(t, err)
11281135
require.YAMLEq(t, string(expectedResponse), string(body))

Diff for: pkg/util/http.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
"github.com/golang/snappy"
1818
"github.com/opentracing/opentracing-go"
1919
otlog "github.com/opentracing/opentracing-go/log"
20-
"gopkg.in/yaml.v2"
20+
yaml "gopkg.in/yaml.v2"
21+
yamlv3 "gopkg.in/yaml.v3"
2122
)
2223

2324
const messageSizeLargerErrFmt = "received message larger than max (%d vs %d)"
@@ -108,11 +109,11 @@ func RenderHTTPResponse(w http.ResponseWriter, v interface{}, t *template.Templa
108109
}
109110
}
110111

111-
// StreamWriteYAMLResponse stream writes data as http response
112-
func StreamWriteYAMLResponse(w http.ResponseWriter, iter chan interface{}, logger log.Logger) {
112+
// StreamWriteYAMLResponseCommon stream writes data as http response
113+
func streamWriteYAMLResponseCommon(w http.ResponseWriter, iter chan interface{}, logger log.Logger, marshalFn func(in interface{}) (out []byte, err error)) {
113114
w.Header().Set("Content-Type", "application/yaml")
114115
for v := range iter {
115-
data, err := yaml.Marshal(v)
116+
data, err := marshalFn(v)
116117
if err != nil {
117118
level.Error(logger).Log("msg", "yaml marshal failed", "err", err)
118119
continue
@@ -125,6 +126,16 @@ func StreamWriteYAMLResponse(w http.ResponseWriter, iter chan interface{}, logge
125126
}
126127
}
127128

129+
// StreamWriteYAMLResponse stream writes data as http response using yaml v2 library
130+
func StreamWriteYAMLResponse(w http.ResponseWriter, iter chan interface{}, logger log.Logger) {
131+
streamWriteYAMLResponseCommon(w, iter, logger, yaml.Marshal)
132+
}
133+
134+
// StreamWriteYAMLV3Response stream writes data as http response using yaml v3 library
135+
func StreamWriteYAMLV3Response(w http.ResponseWriter, iter chan interface{}, logger log.Logger) {
136+
streamWriteYAMLResponseCommon(w, iter, logger, yamlv3.Marshal)
137+
}
138+
128139
// CompressionType for encoding and decoding requests and responses.
129140
type CompressionType int
130141

0 commit comments

Comments
 (0)