11package main
22
33import (
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