Skip to content

Commit e3bf90c

Browse files
committed
Revert "don't parse prometheus metrics since envoy label emission should be deterministic"
This reverts commit 354ea16.
1 parent 354ea16 commit e3bf90c

3 files changed

Lines changed: 43 additions & 17 deletions

File tree

integration/go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ 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
79
github.com/stretchr/testify v1.11.1
810
)
911

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

integration/go.sum

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
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/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
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=
56
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
67
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=
98
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
109
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1110
github.com/mccutchen/go-httpbin/v2 v2.18.0 h1:WFU1OELp3nHYLvXct/3nrGVIgxU0X+RJfDPYRBnvicY=
1211
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=
1314
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1415
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1516
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=
1621
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
1722
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
1823
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
1924
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
2025
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=
2130
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2231
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
2332
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

integration/main_test.go

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

33
import (
4+
"bytes"
45
"cmp"
56
"encoding/json"
67
"io"
@@ -13,6 +14,8 @@ import (
1314
"time"
1415

1516
"github.com/mccutchen/go-httpbin/v2/httpbin"
17+
io_prometheus_client "github.com/prometheus/client_model/go"
18+
"github.com/prometheus/common/expfmt"
1619
"github.com/stretchr/testify/require"
1720
)
1821

@@ -371,22 +374,33 @@ func TestIntegration(t *testing.T) {
371374
body, err := io.ReadAll(resp.Body)
372375
require.NoError(t, err)
373376
lastStatsOutput = string(body)
374-
for line := range strings.Lines(lastStatsOutput) {
375-
line = strings.TrimSpace(line)
376-
if !strings.HasPrefix(line, "route_latency_ms_count") {
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" {
377388
continue
378389
}
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
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+
}
387401
}
388402
}
389-
t.Logf("route_latency_ms metric not found")
403+
t.Logf("route_latency_ms metric not found or no samples yet")
390404
return false
391405
}, 5*time.Second, 200*time.Millisecond)
392406
})

0 commit comments

Comments
 (0)