Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions observability/integration/internal/verify/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package verify

import (
"context"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -108,8 +109,24 @@ func readMetrics(ctx context.Context, url string) (map[string]*dto.MetricFamily,
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("metrics endpoint returned HTTP %d", response.StatusCode)
}
var parser expfmt.TextParser
return parser.TextToMetricFamilies(io.LimitReader(response.Body, 8<<20))
return parseMetricFamilies(io.LimitReader(response.Body, 8<<20))
}

// parseMetricFamilies goes through NewDecoder, which sets the name validation
// scheme itself; a zero-value TextParser panics on newer prometheus/common.
func parseMetricFamilies(r io.Reader) (map[string]*dto.MetricFamily, error) {
decoder := expfmt.NewDecoder(r, expfmt.NewFormat(expfmt.TypeTextPlain))
families := make(map[string]*dto.MetricFamily)
for {
family := &dto.MetricFamily{}
if err := decoder.Decode(family); err != nil {
if errors.Is(err, io.EOF) {
return families, nil
}
return nil, err
}
families[family.GetName()] = family
}
}

func greetMetric(families map[string]*dto.MetricFamily, name string) (*dto.Metric, error) {
Expand Down
5 changes: 1 addition & 4 deletions observability/integration/internal/verify/histogram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import (

import (
dto "github.com/prometheus/client_model/go"

"github.com/prometheus/common/expfmt"
)

var sampleBounds = []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.3, 1}
Expand Down Expand Up @@ -63,8 +61,7 @@ func histogramFixture(role string, batches int) string {

func parseFixture(t *testing.T, text string) map[string]*dto.MetricFamily {
t.Helper()
var parser expfmt.TextParser
families, err := parser.TextToMetricFamilies(strings.NewReader(text))
families, err := parseMetricFamilies(strings.NewReader(text))
if err != nil {
t.Fatal(err)
}
Expand Down
Loading