Skip to content

Commit 354ea16

Browse files
committed
don't parse prometheus metrics since envoy label emission should be deterministic
Signed-off-by: William Zhang <williamzhang@roblox.com>
1 parent 0c19de0 commit 354ea16

3 files changed

Lines changed: 17 additions & 43 deletions

File tree

integration/go.mod

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ go 1.24.0
44

55
require (
66
github.com/mccutchen/go-httpbin/v2 v2.18.0
7-
github.com/prometheus/client_model v0.6.2
8-
github.com/prometheus/common v0.66.1
97
github.com/stretchr/testify v1.11.1
108
)
119

1210
require (
1311
github.com/davecgh/go-spew v1.1.1 // indirect
1412
github.com/kr/pretty v0.3.1 // indirect
15-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
1613
github.com/pmezard/go-difflib v1.0.0 // indirect
17-
go.yaml.in/yaml/v2 v2.4.2 // indirect
18-
google.golang.org/protobuf v1.36.8 // indirect
14+
github.com/rogpeppe/go-internal v1.10.0 // indirect
15+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
1916
gopkg.in/yaml.v3 v3.0.1 // indirect
2017
)

integration/go.sum

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4-
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
5-
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
4+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
65
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
76
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
7+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
8+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
89
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
910
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1011
github.com/mccutchen/go-httpbin/v2 v2.18.0 h1:WFU1OELp3nHYLvXct/3nrGVIgxU0X+RJfDPYRBnvicY=
1112
github.com/mccutchen/go-httpbin/v2 v2.18.0/go.mod h1:GBy5I7XwZ4ZLhT3hcq39I4ikwN9x4QUt6EAxNiR8Jus=
12-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
13-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
1413
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1514
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1615
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17-
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
18-
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
19-
github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs=
20-
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
2116
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
2217
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
2318
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
2419
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
2520
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
26-
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
27-
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
28-
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
29-
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
3021
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3122
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
3223
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

integration/main_test.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"bytes"
54
"cmp"
65
"encoding/json"
76
"io"
@@ -14,8 +13,6 @@ import (
1413
"time"
1514

1615
"github.com/mccutchen/go-httpbin/v2/httpbin"
17-
io_prometheus_client "github.com/prometheus/client_model/go"
18-
"github.com/prometheus/common/expfmt"
1916
"github.com/stretchr/testify/require"
2017
)
2118

@@ -374,33 +371,22 @@ func TestIntegration(t *testing.T) {
374371
body, err := io.ReadAll(resp.Body)
375372
require.NoError(t, err)
376373
lastStatsOutput = string(body)
377-
378-
decoder := expfmt.NewDecoder(bytes.NewReader(body), expfmt.NewFormat(expfmt.TypeTextPlain))
379-
for {
380-
var metricFamily io_prometheus_client.MetricFamily
381-
err := decoder.Decode(&metricFamily)
382-
if err == io.EOF {
383-
break
384-
}
385-
require.NoError(t, err)
386-
387-
if metricFamily.GetName() != "route_latency_ms" {
374+
for line := range strings.Lines(lastStatsOutput) {
375+
line = strings.TrimSpace(line)
376+
if !strings.HasPrefix(line, "route_latency_ms_count") {
388377
continue
389378
}
390-
for _, metric := range metricFamily.GetMetric() {
391-
hist := metric.GetHistogram()
392-
require.NotNil(t, hist)
393-
labels := make(map[string]string)
394-
for _, label := range metric.GetLabel() {
395-
labels[label.GetName()] = label.GetValue()
396-
}
397-
require.Equal(t, map[string]string{"version": "v1.0.0", "route_name": "catch_all"}, labels)
398-
if hist.GetSampleCount() > 0 {
399-
return true
400-
}
379+
t.Logf("found route_latency_ms metric line: %s", line)
380+
parts := strings.Fields(line)
381+
require.Equal(t, 2, len(parts), "expected 2 fields in route_latency_ms metric line")
382+
require.Equal(t, `route_latency_ms_count{version="v1.0.0",route_name="catch_all"}`, parts[0], "unexpected metric name and labels")
383+
count, err := strconv.Atoi(parts[1])
384+
require.NoError(t, err, "expected integer count in route_latency_ms metric line")
385+
if count >= 1 {
386+
return true
401387
}
402388
}
403-
t.Logf("route_latency_ms metric not found or no samples yet")
389+
t.Logf("route_latency_ms metric not found")
404390
return false
405391
}, 5*time.Second, 200*time.Millisecond)
406392
})

0 commit comments

Comments
 (0)