From 9b8a8b46887cc47489a08fdf827415c999fd1002 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Thu, 26 Aug 2021 10:52:52 +0200 Subject: [PATCH] Remove mapPoints() utility Signed-off-by: Marco Pracucci --- pkg/mimirpb/compat.go | 6 ++ pkg/mimirpb/compat_test.go | 8 +++ pkg/mimirpb/mimir.pb.go | 107 ++++++++++++++++---------------- pkg/mimirpb/mimir.proto | 3 +- pkg/querier/queryrange/value.go | 22 ++----- 5 files changed, 76 insertions(+), 70 deletions(-) diff --git a/pkg/mimirpb/compat.go b/pkg/mimirpb/compat.go index 14fa7c871d3..64b1f7d30b4 100644 --- a/pkg/mimirpb/compat.go +++ b/pkg/mimirpb/compat.go @@ -20,6 +20,7 @@ import ( "github.com/prometheus/prometheus/pkg/exemplar" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/textparse" + "github.com/prometheus/prometheus/promql" "github.com/grafana/mimir/pkg/util" ) @@ -146,6 +147,11 @@ func FromExemplarProtosToExemplars(es []Exemplar) []exemplar.Exemplar { return result } +// FromPointsToSamples casts []promql.Point to []Sample. It uses unsafe. +func FromPointsToSamples(points []promql.Point) []Sample { + return *(*[]Sample)(unsafe.Pointer(&points)) +} + type byLabel []LabelAdapter func (s byLabel) Len() int { return len(s) } diff --git a/pkg/mimirpb/compat_test.go b/pkg/mimirpb/compat_test.go index 13ef27aa6e3..eb79fd3838f 100644 --- a/pkg/mimirpb/compat_test.go +++ b/pkg/mimirpb/compat_test.go @@ -15,6 +15,7 @@ import ( jsoniter "github.com/json-iterator/go" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/textparse" + "github.com/prometheus/prometheus/promql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -142,3 +143,10 @@ func BenchmarkFromLabelAdaptersToLabelsWithCopy(b *testing.B) { FromLabelAdaptersToLabelsWithCopy(input) } } + +func TestFromPointsToSamples(t *testing.T) { + input := []promql.Point{{T: 1, V: 2}, {T: 3, V: 4}} + expected := []Sample{{TimestampMs: 1, Value: 2}, {TimestampMs: 3, Value: 4}} + + assert.Equal(t, expected, FromPointsToSamples(input)) +} diff --git a/pkg/mimirpb/mimir.pb.go b/pkg/mimirpb/mimir.pb.go index 6c5043ab694..2d3d6da0893 100644 --- a/pkg/mimirpb/mimir.pb.go +++ b/pkg/mimirpb/mimir.pb.go @@ -288,8 +288,9 @@ func (m *LabelPair) GetValue() []byte { } type Sample struct { - Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"` + // Fields order MUST match promql.Point so that we can cast types between them. TimestampMs int64 `protobuf:"varint,2,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"` + Value float64 `protobuf:"fixed64,1,opt,name=value,proto3" json:"value,omitempty"` } func (m *Sample) Reset() { *m = Sample{} } @@ -324,16 +325,16 @@ func (m *Sample) XXX_DiscardUnknown() { var xxx_messageInfo_Sample proto.InternalMessageInfo -func (m *Sample) GetValue() float64 { +func (m *Sample) GetTimestampMs() int64 { if m != nil { - return m.Value + return m.TimestampMs } return 0 } -func (m *Sample) GetTimestampMs() int64 { +func (m *Sample) GetValue() float64 { if m != nil { - return m.TimestampMs + return m.Value } return 0 } @@ -510,51 +511,51 @@ func init() { func init() { proto.RegisterFile("mimir.proto", fileDescriptor_86d4d7485f544059) } var fileDescriptor_86d4d7485f544059 = []byte{ - // 700 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xf6, 0xe6, 0x7f, 0x26, 0x69, 0x7e, 0xd6, 0xfe, 0x2a, 0x61, 0xf5, 0xe0, 0xa4, 0xe6, 0x92, - 0x03, 0xa4, 0xa8, 0x08, 0x10, 0x08, 0x0e, 0x0e, 0x4a, 0x4b, 0xd5, 0xe6, 0x8f, 0x36, 0x0e, 0x15, - 0x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x0a, 0xaa, 0xa1, 0x7a, 0x99, - 0x08, 0x1b, 0x2f, 0x43, 0xf6, 0x88, 0x5a, 0xd3, 0x48, 0xc2, 0x32, 0x89, 0x1c, 0x4d, 0x87, 0x5c, - 0x34, 0x47, 0x82, 0x87, 0x24, 0x14, 0xe3, 0x78, 0x15, 0xca, 0xe2, 0x0e, 0x7c, 0xca, 0x9d, 0x21, - 0xf7, 0x04, 0x39, 0x4d, 0x4a, 0x8b, 0x58, 0xdb, 0xd3, 0xbe, 0xa7, 0xa0, 0x72, 0x5b, 0x48, 0xfc, - 0x02, 0x32, 0xfe, 0xcc, 0x89, 0x4a, 0x55, 0xd6, 0x1f, 0xde, 0x25, 0x78, 0xec, 0x1a, 0x33, 0x87, - 0x11, 0x41, 0xc0, 0x8f, 0x00, 0x73, 0x11, 0x1b, 0xee, 0x53, 0x6e, 0x5a, 0x33, 0x21, 0xba, 0x68, - 0x5a, 0x24, 0x72, 0x84, 0x6c, 0x08, 0x20, 0xd4, 0x3a, 0x7c, 0xe6, 0x21, 0xb3, 0x1c, 0x25, 0x23, - 0x70, 0x61, 0x87, 0xb1, 0xe9, 0xc4, 0xf4, 0x95, 0x6c, 0x14, 0x0b, 0x6d, 0x6d, 0x06, 0x90, 0x74, - 0xc2, 0x25, 0xc8, 0x0f, 0x3a, 0xdb, 0x9d, 0xee, 0x6e, 0x47, 0x96, 0x42, 0xe7, 0x6d, 0x77, 0xd0, - 0x31, 0x5a, 0x44, 0x46, 0xb8, 0x08, 0xd9, 0x4d, 0x7d, 0xb0, 0xd9, 0x92, 0x53, 0x78, 0x09, 0x8a, - 0xef, 0xb6, 0xfa, 0x46, 0x77, 0x93, 0xe8, 0x6d, 0x39, 0x8d, 0x31, 0x54, 0x04, 0x92, 0xc4, 0x32, - 0x21, 0xb5, 0x3f, 0x68, 0xb7, 0x75, 0xf2, 0x41, 0xce, 0x86, 0x57, 0xb5, 0xd5, 0xd9, 0xe8, 0xca, - 0x39, 0x5c, 0x86, 0x42, 0xdf, 0xd0, 0x8d, 0x56, 0xbf, 0x65, 0xc8, 0x79, 0x6d, 0x1b, 0x72, 0x51, - 0xeb, 0x7b, 0xb8, 0x26, 0xed, 0x2b, 0x82, 0xc2, 0xfc, 0x02, 0xee, 0xe3, 0x3a, 0x6f, 0x9d, 0xc4, - 0x9d, 0x92, 0xa7, 0xff, 0x91, 0xbc, 0xf9, 0xe6, 0xf4, 0x42, 0x95, 0xce, 0x2e, 0x54, 0xe9, 0xfa, - 0x42, 0x45, 0x5f, 0x02, 0x15, 0xfd, 0x08, 0x54, 0x74, 0x12, 0xa8, 0xe8, 0x34, 0x50, 0xd1, 0x9f, - 0x40, 0x45, 0x57, 0x81, 0x2a, 0x5d, 0x07, 0x2a, 0xfa, 0x76, 0xa9, 0x4a, 0xa7, 0x97, 0xaa, 0x74, - 0x76, 0xa9, 0x4a, 0x1f, 0xf3, 0xe2, 0xbb, 0x73, 0x46, 0xa3, 0x9c, 0xf8, 0xb8, 0x9e, 0xfe, 0x0d, - 0x00, 0x00, 0xff, 0xff, 0xe2, 0x8d, 0xe5, 0xa3, 0x00, 0x05, 0x00, 0x00, + // 701 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xbd, 0x6e, 0xd3, 0x5e, + 0x14, 0xf7, 0xcd, 0x77, 0x4e, 0xd2, 0xfc, 0xad, 0xfb, 0xaf, 0x84, 0xd5, 0xc1, 0x49, 0xcd, 0x92, + 0x01, 0x52, 0x54, 0x04, 0x08, 0x04, 0x83, 0x83, 0xd2, 0x52, 0xb5, 0xf9, 0xd0, 0x8d, 0x43, 0x05, + 0x4b, 0x74, 0x93, 0xde, 0xb6, 0x16, 0xbe, 0xb1, 0xb1, 0x9d, 0xaa, 0xd9, 0x98, 0x98, 0x99, 0x79, + 0x02, 0x9e, 0x00, 0x89, 0x37, 0xe8, 0xd8, 0xb1, 0x62, 0xa8, 0xa8, 0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xfb, + 0xbc, 0x73, 0x08, 0xe9, 0x3b, 0x87, 0xd0, 0x7c, 0x73, 0x7a, 0xa1, 0x4a, 0x67, 0x17, 0xaa, 0x74, + 0x7d, 0xa1, 0xa2, 0x2f, 0x81, 0x8a, 0x7e, 0x04, 0x2a, 0x3a, 0x09, 0x54, 0x74, 0x1a, 0xa8, 0xe8, + 0x4f, 0xa0, 0xa2, 0xab, 0x40, 0x95, 0xae, 0x03, 0x15, 0x7d, 0xbb, 0x54, 0xa5, 0xd3, 0x4b, 0x55, + 0x3a, 0xbb, 0x54, 0xa5, 0x8f, 0x79, 0xf1, 0xbb, 0x73, 0x46, 0xa3, 0x9c, 0xf8, 0x71, 0x3d, 0xfd, + 0x1b, 0x00, 0x00, 0xff, 0xff, 0x40, 0x35, 0x74, 0x55, 0x00, 0x05, 0x00, 0x00, } func (x WriteRequest_SourceEnum) String() string { @@ -726,10 +727,10 @@ func (this *Sample) Equal(that interface{}) bool { } else if this == nil { return false } - if this.Value != that1.Value { + if this.TimestampMs != that1.TimestampMs { return false } - if this.TimestampMs != that1.TimestampMs { + if this.Value != that1.Value { return false } return true @@ -896,8 +897,8 @@ func (this *Sample) GoString() string { } s := make([]string, 0, 6) s = append(s, "&mimirpb.Sample{") - s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") s = append(s, "TimestampMs: "+fmt.Sprintf("%#v", this.TimestampMs)+",\n") + s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") s = append(s, "}") return strings.Join(s, "") } diff --git a/pkg/mimirpb/mimir.proto b/pkg/mimirpb/mimir.proto index f22b059cfba..2aa77e25bdb 100644 --- a/pkg/mimirpb/mimir.proto +++ b/pkg/mimirpb/mimir.proto @@ -41,8 +41,9 @@ message LabelPair { } message Sample { - double value = 1; + // Fields order MUST match promql.Point so that we can cast types between them. int64 timestamp_ms = 2; + double value = 1; } message MetricMetadata { diff --git a/pkg/querier/queryrange/value.go b/pkg/querier/queryrange/value.go index 500f19f3556..c30736c4015 100644 --- a/pkg/querier/queryrange/value.go +++ b/pkg/querier/queryrange/value.go @@ -41,8 +41,11 @@ func FromResult(res *promql.Result) ([]SampleStream, error) { res := make([]SampleStream, 0, len(v)) for _, sample := range v { res = append(res, SampleStream{ - Labels: mapLabels(sample.Metric), - Samples: mapPoints(sample.Point), + Labels: mapLabels(sample.Metric), + Samples: []mimirpb.Sample{{ + TimestampMs: sample.Point.T, + Value: sample.Point.V, + }}, }) } return res, nil @@ -52,7 +55,7 @@ func FromResult(res *promql.Result) ([]SampleStream, error) { for _, series := range v { res = append(res, SampleStream{ Labels: mapLabels(series.Metric), - Samples: mapPoints(series.Points...), + Samples: mimirpb.FromPointsToSamples(series.Points), }) } return res, nil @@ -71,19 +74,6 @@ func mapLabels(ls labels.Labels) []mimirpb.LabelAdapter { return result } -func mapPoints(pts ...promql.Point) []mimirpb.Sample { - result := make([]mimirpb.Sample, 0, len(pts)) - - for _, pt := range pts { - result = append(result, mimirpb.Sample{ - Value: pt.V, - TimestampMs: pt.T, - }) - } - - return result -} - // ResponseToSamples is needed to map back from api response to the underlying series data func ResponseToSamples(resp Response) ([]SampleStream, error) { promRes, ok := resp.(*PrometheusResponse)