diff --git a/go.mod b/go.mod index c03a2611042..7905f8cfdec 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/grafana/xk6-browser v0.10.0 github.com/grafana/xk6-grpc v0.1.2 - github.com/grafana/xk6-output-prometheus-remote v0.2.1 + github.com/grafana/xk6-output-prometheus-remote v0.2.2-0.20230719110733-69f101ee8ade github.com/grafana/xk6-redis v0.1.1 github.com/grafana/xk6-timers v0.1.2 github.com/grafana/xk6-webcrypto v0.1.0 diff --git a/go.sum b/go.sum index 19a07381a70..94e7b218d88 100644 --- a/go.sum +++ b/go.sum @@ -183,8 +183,8 @@ github.com/grafana/xk6-browser v0.10.0 h1:Mnx0Ho+mlyFGlV7zW7zXkN0njRglh9JflLV+Oz github.com/grafana/xk6-browser v0.10.0/go.mod h1:ax6OHARpNEu9hSGYOAI4grAwiRapsNPi9TBQxDYurKw= github.com/grafana/xk6-grpc v0.1.2 h1:gNN3PYV2dIPoq1zTVz8YOxrWhl1D15jhRR0EA9ZYhBw= github.com/grafana/xk6-grpc v0.1.2/go.mod h1:iq6qHN64XgAEmDHKf0OXZ4mvoqF4Udr22fiCIXNpXA0= -github.com/grafana/xk6-output-prometheus-remote v0.2.1 h1:/JOMHwByfCkFe17iokUDKCIjh8e5g0gqqnrg8zSnxf4= -github.com/grafana/xk6-output-prometheus-remote v0.2.1/go.mod h1:JWUOn1fY8Yp3dM+IaPSNMM6t+sF3aJ2AA7Qzs6lKGww= +github.com/grafana/xk6-output-prometheus-remote v0.2.2-0.20230719110733-69f101ee8ade h1:DY8H7hMVBpP4yuKlNnPBykL+WJ4hBobwT0BG8nDcFLw= +github.com/grafana/xk6-output-prometheus-remote v0.2.2-0.20230719110733-69f101ee8ade/go.mod h1:rI7naMHdQ+vLVoonZ6LYkrXz8ZiWIptTstVbV2CSahY= github.com/grafana/xk6-redis v0.1.1 h1:rvWnLanRB2qzDwuY6NMBe6PXei3wJ3kjYvfCwRJ+q+8= github.com/grafana/xk6-redis v0.1.1/go.mod h1:z7el1Tz8advY+ex419KfLbENzSQYgaA2lQYwMlt9yMM= github.com/grafana/xk6-timers v0.1.2 h1:YVM6hPDgvy4SkdZQpd+/r9M0kDi1g+QdbSxW5ClfwDk= diff --git a/metrics/engine/ingester_test.go b/metrics/engine/ingester_test.go index b299322e363..766ecee201e 100644 --- a/metrics/engine/ingester_test.go +++ b/metrics/engine/ingester_test.go @@ -44,7 +44,7 @@ func TestIngesterOutputFlushMetrics(t *testing.T) { assert.Equal(t, testMetric, metric) sink := metric.Sink.(*metrics.TrendSink) //nolint:forcetypeassert - assert.Equal(t, 42.0, sink.Sum) + assert.Equal(t, 42.0, sink.Total()) } func TestIngesterOutputFlushSubmetrics(t *testing.T) { diff --git a/metrics/sink.go b/metrics/sink.go index 046a6bfee6a..f74804d92cd 100644 --- a/metrics/sink.go +++ b/metrics/sink.go @@ -99,9 +99,7 @@ type TrendSink struct { count uint64 min, max float64 - // TODO: unexport after this dependency is removed: - // https://github.com/grafana/xk6-output-prometheus-remote/blob/v0.2.1/pkg/remotewrite/remotewrite.go#L173 - Sum float64 + sum float64 } // IsEmpty indicates whether the TrendSink is empty. @@ -122,7 +120,7 @@ func (t *TrendSink) Add(s Sample) { t.values = append(t.values, s.Value) t.sorted = false t.count++ - t.Sum += s.Value + t.sum += s.Value } // P calculates the given percentile from sink values. @@ -167,14 +165,14 @@ func (t *TrendSink) Count() uint64 { // Avg returns the average (i.e. mean) value. func (t *TrendSink) Avg() float64 { if t.count > 0 { - return t.Sum / float64(t.count) + return t.sum / float64(t.count) } return 0 } // Total returns the total (i.e. "sum") value for all measurements. func (t *TrendSink) Total() float64 { - return t.Sum + return t.sum } func (t *TrendSink) Format(tt time.Duration) map[string]float64 { diff --git a/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/remotewrite.go b/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/remotewrite.go index fc1ecd01cbf..24ae3ddaf20 100644 --- a/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/remotewrite.go +++ b/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/remotewrite.go @@ -170,7 +170,7 @@ func (o *Output) setTrendStatsResolver(trendStats []string) error { // it adds it specifically if hasSum { resolvers["sum"] = func(t *metrics.TrendSink) float64 { - return t.Sum + return t.Total() } } o.trendStatsResolver = make(TrendStatsResolver, len(resolvers)) diff --git a/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/trend.go b/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/trend.go index e9686d0bb35..eb3d8b1d9ee 100644 --- a/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/trend.go +++ b/vendor/github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite/trend.go @@ -25,7 +25,7 @@ func newExtendedTrendSink(tsr TrendStatsResolver) (*extendedTrendSink, error) { return nil, fmt.Errorf("trend stats resolver is empty") } return &extendedTrendSink{ - TrendSink: &metrics.TrendSink{}, + TrendSink: metrics.NewTrendSink(), trendStats: tsr, }, nil } @@ -169,6 +169,16 @@ func (*nativeHistogramSink) IsEmpty() bool { panic("Native Histogram Sink has no support of emptiness check (IsEmpty)") } +// Drain implements metrics.Sink. +func (*nativeHistogramSink) Drain() ([]byte, error) { + panic("Native Histogram Sink has no support of draining") +} + +// Merge implements metrics.Sink. +func (*nativeHistogramSink) Merge(from []byte) error { + panic("Native Histogram Sink has no support of merging") +} + // MapPrompb maps the Trend type to the experimental Native Histogram. func (sink *nativeHistogramSink) MapPrompb(series metrics.TimeSeries, t time.Time) []*prompb.TimeSeries { suffix := baseUnit(series.Metric.Contains) diff --git a/vendor/modules.txt b/vendor/modules.txt index 369d75444c0..c02aa9629fa 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -160,7 +160,7 @@ github.com/grafana/xk6-browser/storage ## explicit; go 1.19 github.com/grafana/xk6-grpc/grpc github.com/grafana/xk6-grpc/lib/netext/grpcext -# github.com/grafana/xk6-output-prometheus-remote v0.2.1 +# github.com/grafana/xk6-output-prometheus-remote v0.2.2-0.20230719110733-69f101ee8ade ## explicit; go 1.18 github.com/grafana/xk6-output-prometheus-remote/pkg/remote github.com/grafana/xk6-output-prometheus-remote/pkg/remotewrite