Skip to content

Commit 278cc60

Browse files
authored
[Bugfix] Fix GZIP encoding in case of small responses (#1397)
1 parent ecb3482 commit 278cc60

File tree

8 files changed

+283
-12
lines changed

8 files changed

+283
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- (Bugfix) (EE) Fix MemberMaintenance Context and ClusterMaintenance discovery
1313
- (Feature) Add proper Prometheus endpoint compression + 204 response code
1414
- (Feature) Reconciliation Loop Interval option
15+
- (Bugfix) Fix GZIP encoding in case of small responses
1516

1617
## [1.2.32](https://github.com/arangodb/kube-arangodb/tree/1.2.32) (2023-08-07)
1718
- (Feature) Backup lifetime - remove Backup once its lifetime has been reached

go.mod

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ require (
3939
github.com/pkg/errors v0.9.1
4040
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.44.1
4141
github.com/prometheus-operator/prometheus-operator/pkg/client v0.0.0-00010101000000-000000000000
42-
github.com/prometheus/client_golang v1.12.1
43-
github.com/prometheus/client_model v0.2.0
42+
github.com/prometheus/client_golang v1.15.1
43+
github.com/prometheus/client_model v0.4.0
4444
github.com/robfig/cron v1.2.0
4545
github.com/rs/zerolog v1.19.0
4646
github.com/spf13/cobra v1.4.0
@@ -94,7 +94,7 @@ require (
9494
github.com/goccy/go-json v0.10.2 // indirect
9595
github.com/gogo/protobuf v1.3.2 // indirect
9696
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
97-
github.com/golang/protobuf v1.5.2 // indirect
97+
github.com/golang/protobuf v1.5.3 // indirect
9898
github.com/google/cel-go v0.12.6 // indirect
9999
github.com/google/gnostic v0.5.7-v3refs // indirect
100100
github.com/google/go-cmp v0.5.9 // indirect
@@ -111,7 +111,7 @@ require (
111111
github.com/leodido/go-urn v1.2.4 // indirect
112112
github.com/mailru/easyjson v0.7.7 // indirect
113113
github.com/mattn/go-isatty v0.0.19 // indirect
114-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
114+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
115115
github.com/mitchellh/mapstructure v1.4.1 // indirect
116116
github.com/moby/spdystream v0.2.0 // indirect
117117
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -120,8 +120,9 @@ require (
120120
github.com/pavel-v-chernykh/keystore-go v2.1.0+incompatible // indirect
121121
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
122122
github.com/pmezard/go-difflib v1.0.0 // indirect
123-
github.com/prometheus/common v0.32.1 // indirect
124-
github.com/prometheus/procfs v0.7.3 // indirect
123+
github.com/prometheus/common v0.44.0 // indirect
124+
github.com/prometheus/procfs v0.9.0 // indirect
125+
github.com/prometheus/prom2json v1.3.3 // indirect
125126
github.com/stoewer/go-strcase v1.2.0 // indirect
126127
github.com/stretchr/objx v0.2.0 // indirect
127128
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
@@ -147,7 +148,7 @@ require (
147148
golang.org/x/crypto v0.11.0 // indirect
148149
golang.org/x/mod v0.8.0 // indirect
149150
golang.org/x/net v0.13.0 // indirect
150-
golang.org/x/oauth2 v0.4.0 // indirect
151+
golang.org/x/oauth2 v0.8.0 // indirect
151152
golang.org/x/term v0.10.0 // indirect
152153
golang.org/x/tools v0.6.0 // indirect
153154
google.golang.org/appengine v1.6.7 // indirect

go.sum

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
220220
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
221221
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
222222
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
223+
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
223224
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
224225
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
225226
github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
@@ -315,6 +316,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
315316
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
316317
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
317318
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
319+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
320+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
318321
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
319322
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
320323
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -485,6 +488,8 @@ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
485488
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
486489
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
487490
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
491+
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
492+
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
488493
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
489494
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
490495
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
@@ -571,11 +576,15 @@ github.com/prometheus/client_golang v1.11.1 h1:+4eQaD7vAZ6DsfsxB15hbE0odUjGI5ARs
571576
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
572577
github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk=
573578
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
579+
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
580+
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
574581
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
575582
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
576583
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
577584
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
578585
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
586+
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
587+
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
579588
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
580589
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
581590
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
@@ -586,6 +595,8 @@ github.com/prometheus/common v0.28.0 h1:vGVfV9KrDTvWt5boZO0I19g2E3CsWfpPPKZM9dt3
586595
github.com/prometheus/common v0.28.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
587596
github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4=
588597
github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
598+
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
599+
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
589600
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
590601
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
591602
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
@@ -594,6 +605,10 @@ github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3x
594605
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
595606
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
596607
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
608+
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
609+
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
610+
github.com/prometheus/prom2json v1.3.3 h1:IYfSMiZ7sSOfliBoo89PcufjWO4eAR0gznGcETyaUgo=
611+
github.com/prometheus/prom2json v1.3.3/go.mod h1:Pv4yIPktEkK7btWsrUTWDDDrnpUrAELaOCj+oFwlgmc=
597612
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
598613
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
599614
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
@@ -887,6 +902,8 @@ golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f/go.mod h1:KelEdhl1UZF7XfJ
887902
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
888903
golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M=
889904
golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec=
905+
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
906+
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
890907
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
891908
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
892909
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

pkg/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.

pkg/util/http/buffer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ func WithBuffer(maxSize int, in http.HandlerFunc) http.HandlerFunc {
4646
// We have constant size
4747
bytes := data.Bytes()
4848

49-
println(len(bytes))
50-
5149
writer.Header().Set(ContentLengthHeader, fmt.Sprintf("%d", len(bytes)))
5250

5351
_, err := util.WriteAll(writer, bytes)

pkg/util/http/encoding.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ func WithEncoding(in http.HandlerFunc) http.HandlerFunc {
4545
default:
4646
WithIdentityEncoding(in)(writer, request)
4747
}
48-
49-
in(writer, request)
5048
}
5149
}
5250

@@ -58,8 +56,14 @@ func WithIdentityEncoding(in http.HandlerFunc) http.HandlerFunc {
5856

5957
func WithGZipEncoding(in http.HandlerFunc) http.HandlerFunc {
6058
return func(responseWriter http.ResponseWriter, request *http.Request) {
59+
responseWriter.Header().Add(EncodingResponseHeader, "gzip")
60+
6161
stream := gzip.NewWriter(responseWriter)
6262

6363
in(NewWriter(responseWriter, stream), request)
64+
65+
if err := stream.Close(); err != nil {
66+
logger.Err(err).Warn("Unable to write GZIP response")
67+
}
6468
}
6569
}

pkg/util/metrics/handler_test.go

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package metrics
22+
23+
import (
24+
"compress/gzip"
25+
"fmt"
26+
"io"
27+
"net/http"
28+
"testing"
29+
30+
dto "github.com/prometheus/client_model/go"
31+
"github.com/prometheus/prom2json"
32+
"github.com/stretchr/testify/require"
33+
34+
operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http"
35+
)
36+
37+
func Test_Handler(t *testing.T) {
38+
m := http.NewServeMux()
39+
40+
m.HandleFunc("/metrics", Handler())
41+
m.HandleFunc("/empty", operatorHTTP.WithNoContent(func(writer http.ResponseWriter, request *http.Request) {
42+
43+
}))
44+
45+
endpoint, c := StartHTTP(t, m)
46+
defer c()
47+
48+
metricsEndpoint := fmt.Sprintf("%s/metrics", endpoint)
49+
emptyEndpoint := fmt.Sprintf("%s/empty", endpoint)
50+
51+
t.Run("Get metrics in plain", func(t *testing.T) {
52+
r, err := http.NewRequest("GET", metricsEndpoint, nil)
53+
require.NoError(t, err)
54+
55+
r.Header.Add("Accept-Encoding", "identity")
56+
57+
resp, err := http.DefaultClient.Do(r)
58+
require.NoError(t, err)
59+
60+
require.Equal(t, http.StatusOK, resp.StatusCode)
61+
62+
data, err := io.ReadAll(resp.Body)
63+
require.NoError(t, err)
64+
65+
require.True(t, len(data) > 0)
66+
})
67+
68+
t.Run("Get metrics in gzip", func(t *testing.T) {
69+
r, err := http.NewRequest("GET", metricsEndpoint, nil)
70+
require.NoError(t, err)
71+
72+
r.Header.Add("Accept-Encoding", "gzip")
73+
74+
resp, err := http.DefaultClient.Do(r)
75+
require.NoError(t, err)
76+
77+
require.Equal(t, http.StatusOK, resp.StatusCode)
78+
79+
data, err := io.ReadAll(resp.Body)
80+
require.NoError(t, err)
81+
82+
require.True(t, len(data) > 0)
83+
})
84+
85+
t.Run("Get metrics in default", func(t *testing.T) {
86+
r, err := http.NewRequest("GET", metricsEndpoint, nil)
87+
require.NoError(t, err)
88+
89+
resp, err := http.DefaultClient.Do(r)
90+
require.NoError(t, err)
91+
92+
require.Equal(t, http.StatusOK, resp.StatusCode)
93+
94+
data, err := io.ReadAll(resp.Body)
95+
require.NoError(t, err)
96+
97+
require.True(t, len(data) > 0)
98+
})
99+
100+
t.Run("Get empty", func(t *testing.T) {
101+
r, err := http.NewRequest("GET", emptyEndpoint, nil)
102+
require.NoError(t, err)
103+
104+
resp, err := http.DefaultClient.Do(r)
105+
require.NoError(t, err)
106+
107+
require.Equal(t, http.StatusNoContent, resp.StatusCode)
108+
109+
data, err := io.ReadAll(resp.Body)
110+
require.NoError(t, err)
111+
112+
require.True(t, len(data) == 0)
113+
})
114+
115+
t.Run("Read metrics - plain", func(t *testing.T) {
116+
mfChan := make(chan *dto.MetricFamily, 1024*1024)
117+
118+
r, err := http.NewRequest("GET", metricsEndpoint, nil)
119+
require.NoError(t, err)
120+
121+
r.Header.Add("Accept-Encoding", "identity")
122+
123+
resp, err := http.DefaultClient.Do(r)
124+
require.NoError(t, err)
125+
126+
require.Equal(t, http.StatusOK, resp.StatusCode)
127+
128+
require.NoError(t, prom2json.ParseReader(resp.Body, mfChan))
129+
130+
metrics := map[string]bool{}
131+
132+
for mf := range mfChan {
133+
result := prom2json.NewFamily(mf)
134+
metrics[result.Name] = true
135+
}
136+
137+
require.Contains(t, metrics, "go_info")
138+
})
139+
140+
t.Run("Read metrics - gzip", func(t *testing.T) {
141+
mfChan := make(chan *dto.MetricFamily, 1024*1024)
142+
143+
r, err := http.NewRequest("GET", metricsEndpoint, nil)
144+
require.NoError(t, err)
145+
146+
r.Header.Add("Accept-Encoding", "gzip")
147+
148+
resp, err := http.DefaultClient.Do(r)
149+
require.NoError(t, err)
150+
151+
require.Equal(t, http.StatusOK, resp.StatusCode)
152+
153+
reader, err := gzip.NewReader(resp.Body)
154+
require.NoError(t, err)
155+
156+
require.NoError(t, prom2json.ParseReader(reader, mfChan))
157+
158+
metrics := map[string]bool{}
159+
160+
for mf := range mfChan {
161+
result := prom2json.NewFamily(mf)
162+
metrics[result.Name] = true
163+
}
164+
165+
require.Contains(t, metrics, "go_info")
166+
})
167+
168+
t.Run("Read metrics - default", func(t *testing.T) {
169+
mfChan := make(chan *dto.MetricFamily, 1024*1024)
170+
171+
r, err := http.NewRequest("GET", metricsEndpoint, nil)
172+
require.NoError(t, err)
173+
174+
resp, err := http.DefaultClient.Do(r)
175+
require.NoError(t, err)
176+
177+
require.Equal(t, http.StatusOK, resp.StatusCode)
178+
179+
require.NoError(t, prom2json.ParseReader(resp.Body, mfChan))
180+
181+
metrics := map[string]bool{}
182+
183+
for mf := range mfChan {
184+
result := prom2json.NewFamily(mf)
185+
metrics[result.Name] = true
186+
}
187+
188+
require.Contains(t, metrics, "go_info")
189+
})
190+
}

0 commit comments

Comments
 (0)