diff --git a/pkg/logql/metrics.go b/pkg/logql/metrics.go index 4627e05622e15..871cea3e6d944 100644 --- a/pkg/logql/metrics.go +++ b/pkg/logql/metrics.go @@ -2,9 +2,11 @@ package logql import ( "context" + "strings" "time" "github.com/cortexproject/cortex/pkg/util" + "github.com/dustin/go-humanize" "github.com/go-kit/kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -87,8 +89,8 @@ func RecordMetrics(ctx context.Context, p Params, status string, stats stats.Res "step", p.Step(), "duration", time.Duration(int64(stats.Summary.ExecTime*float64(time.Second))), "status", status, - "throughput_mb", float64(stats.Summary.BytesProcessedPerSecond)/1e6, - "total_bytes_mb", float64(stats.Summary.TotalBytesProcessed)/1e6, + "throughput", strings.Replace(humanize.Bytes(uint64(stats.Summary.BytesProcessedPerSecond)), " ", "", 1), + "total_bytes", strings.Replace(humanize.Bytes(uint64(stats.Summary.TotalBytesProcessed)), " ", "", 1), ) bytesPerSecond.WithLabelValues(status, queryType, rt, latencyType). diff --git a/pkg/logql/metrics_test.go b/pkg/logql/metrics_test.go index e0d2064f85d53..ea75d36f454a2 100644 --- a/pkg/logql/metrics_test.go +++ b/pkg/logql/metrics_test.go @@ -72,7 +72,7 @@ func TestLogSlowQuery(t *testing.T) { }) require.Equal(t, fmt.Sprintf( - "level=info org_id=foo traceID=%s latency=slow query=\"{foo=\\\"bar\\\"} |= \\\"buzz\\\"\" query_type=filter range_type=range length=1h0m0s step=1m0s duration=25.25s status=200 throughput_mb=0.1 total_bytes_mb=0.1\n", + "level=info org_id=foo traceID=%s latency=slow query=\"{foo=\\\"bar\\\"} |= \\\"buzz\\\"\" query_type=filter range_type=range length=1h0m0s step=1m0s duration=25.25s status=200 throughput=100kB total_bytes=100kB\n", sp.Context().(jaeger.SpanContext).SpanID().String(), ), buf.String())