From 2952387ed1fcbb9d66d73eedba5a56838bf7cb51 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Tue, 8 May 2018 01:48:13 -0700 Subject: [PATCH] Pass query hints down into remote read query proto (#4122) Signed-off-by: Henri DF --- prompb/remote.pb.go | 96 ++++++++++++++---- prompb/remote.proto | 1 + prompb/types.pb.go | 210 ++++++++++++++++++++++++++++++++++++---- prompb/types.proto | 5 + storage/remote/codec.go | 8 +- storage/remote/read.go | 4 +- web/api/v1/api_test.go | 3 +- 7 files changed, 283 insertions(+), 44 deletions(-) diff --git a/prompb/remote.pb.go b/prompb/remote.pb.go index e7ad9d76d..5ed2d06c9 100644 --- a/prompb/remote.pb.go +++ b/prompb/remote.pb.go @@ -26,6 +26,7 @@ Label Labels LabelMatcher + ReadHints */ package prompb @@ -99,6 +100,7 @@ type Query struct { StartTimestampMs int64 `protobuf:"varint,1,opt,name=start_timestamp_ms,json=startTimestampMs,proto3" json:"start_timestamp_ms,omitempty"` EndTimestampMs int64 `protobuf:"varint,2,opt,name=end_timestamp_ms,json=endTimestampMs,proto3" json:"end_timestamp_ms,omitempty"` Matchers []*LabelMatcher `protobuf:"bytes,3,rep,name=matchers" json:"matchers,omitempty"` + Hints *ReadHints `protobuf:"bytes,4,opt,name=hints" json:"hints,omitempty"` } func (m *Query) Reset() { *m = Query{} } @@ -127,6 +129,13 @@ func (m *Query) GetMatchers() []*LabelMatcher { return nil } +func (m *Query) GetHints() *ReadHints { + if m != nil { + return m.Hints + } + return nil +} + type QueryResult struct { // Samples within a time series must be ordered by time. Timeseries []*TimeSeries `protobuf:"bytes,1,rep,name=timeseries" json:"timeseries,omitempty"` @@ -278,6 +287,16 @@ func (m *Query) MarshalTo(dAtA []byte) (int, error) { i += n } } + if m.Hints != nil { + dAtA[i] = 0x22 + i++ + i = encodeVarintRemote(dAtA, i, uint64(m.Hints.Size())) + n1, err := m.Hints.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n1 + } return i, nil } @@ -371,6 +390,10 @@ func (m *Query) Size() (n int) { n += 1 + l + sovRemote(uint64(l)) } } + if m.Hints != nil { + l = m.Hints.Size() + n += 1 + l + sovRemote(uint64(l)) + } return n } @@ -740,6 +763,39 @@ func (m *Query) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hints", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowRemote + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthRemote + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Hints == nil { + m.Hints = &ReadHints{} + } + if err := m.Hints.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRemote(dAtA[iNdEx:]) @@ -950,23 +1006,25 @@ var ( func init() { proto.RegisterFile("remote.proto", fileDescriptorRemote) } var fileDescriptorRemote = []byte{ - // 284 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0xcf, 0x4a, 0xc3, 0x40, - 0x10, 0xc6, 0x59, 0x8b, 0xad, 0x4c, 0x8a, 0xd4, 0x45, 0x34, 0x78, 0x08, 0x92, 0x53, 0x40, 0x09, - 0xf8, 0x07, 0x0f, 0xde, 0x14, 0xf4, 0x64, 0x0f, 0xae, 0x05, 0xc1, 0x4b, 0x49, 0xcc, 0x40, 0x03, - 0xdd, 0x64, 0xbb, 0x33, 0x39, 0xf4, 0x41, 0x7c, 0x27, 0x8f, 0x3e, 0x82, 0xe4, 0x49, 0xa4, 0x1b, - 0xa2, 0x2b, 0xde, 0x3c, 0xff, 0x7e, 0xdf, 0xc7, 0xc7, 0x0c, 0x8c, 0x2d, 0xea, 0x9a, 0x31, 0x35, - 0xb6, 0xe6, 0x5a, 0x82, 0xb1, 0xb5, 0x46, 0x5e, 0x60, 0x43, 0x47, 0x01, 0xaf, 0x0d, 0x52, 0x07, - 0xe2, 0x7b, 0x18, 0x3f, 0xdb, 0x92, 0x51, 0xe1, 0xaa, 0x41, 0x62, 0x79, 0x05, 0xc0, 0xa5, 0x46, - 0x42, 0x5b, 0x22, 0x85, 0xe2, 0x78, 0x90, 0x04, 0xe7, 0x07, 0xe9, 0x4f, 0x3a, 0x9d, 0x95, 0x1a, - 0x9f, 0x1c, 0x55, 0x9e, 0x19, 0x5f, 0x43, 0xa0, 0x30, 0x2b, 0xfa, 0x9a, 0x13, 0x18, 0xad, 0x1a, - 0xbf, 0x63, 0xcf, 0xef, 0x78, 0x6c, 0xd0, 0xae, 0x55, 0x6f, 0xc4, 0x37, 0x30, 0xee, 0xb2, 0x64, - 0xea, 0x8a, 0x50, 0x9e, 0xc1, 0xc8, 0x22, 0x35, 0x4b, 0xee, 0xc3, 0x87, 0x7f, 0xc3, 0x8e, 0xab, - 0xde, 0x8b, 0xdf, 0x04, 0x6c, 0x3b, 0x20, 0x4f, 0x41, 0x12, 0x67, 0x96, 0xe7, 0x6e, 0x1c, 0x67, - 0xda, 0xcc, 0xf5, 0xa6, 0x47, 0x24, 0x03, 0x35, 0x71, 0x64, 0xd6, 0x83, 0x29, 0xc9, 0x04, 0x26, - 0x58, 0x15, 0xbf, 0xdd, 0x2d, 0xe7, 0xee, 0x62, 0x55, 0xf8, 0xe6, 0x25, 0xec, 0xe8, 0x8c, 0x5f, - 0x17, 0x68, 0x29, 0x1c, 0xb8, 0x55, 0xa1, 0xbf, 0xea, 0x21, 0xcb, 0x71, 0x39, 0xed, 0x04, 0xf5, - 0x6d, 0xc6, 0x77, 0x10, 0x78, 0x7b, 0xff, 0x7b, 0xdd, 0xdb, 0xfd, 0xf7, 0x36, 0x12, 0x1f, 0x6d, - 0x24, 0x3e, 0xdb, 0x48, 0xbc, 0x0c, 0x37, 0x01, 0x93, 0xe7, 0x43, 0xf7, 0xc2, 0x8b, 0xaf, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x0a, 0x31, 0xaa, 0x60, 0xeb, 0x01, 0x00, 0x00, + // 308 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x91, 0x4f, 0x4b, 0xf3, 0x40, + 0x10, 0xc6, 0xd9, 0xb7, 0x6f, 0x5b, 0x99, 0x14, 0xa9, 0x8b, 0x7f, 0x82, 0x87, 0x52, 0x72, 0x0a, + 0x54, 0x0a, 0x56, 0xf1, 0xe0, 0x4d, 0x41, 0xf1, 0x60, 0x0f, 0xae, 0x05, 0xc1, 0x4b, 0x49, 0xed, + 0x40, 0x03, 0xdd, 0x64, 0xbb, 0x33, 0x39, 0xf4, 0xeb, 0x79, 0xf2, 0xe8, 0x47, 0x90, 0x7c, 0x12, + 0xc9, 0x86, 0xe8, 0x8a, 0x37, 0xcf, 0xbf, 0xdf, 0xf3, 0xf0, 0x0c, 0x03, 0x3d, 0x8b, 0x3a, 0x67, + 0x1c, 0x1b, 0x9b, 0x73, 0x2e, 0xc1, 0xd8, 0x5c, 0x23, 0xaf, 0xb0, 0xa0, 0xe3, 0x80, 0xb7, 0x06, + 0xa9, 0x06, 0xd1, 0x2d, 0xf4, 0x9e, 0x6c, 0xca, 0xa8, 0x70, 0x53, 0x20, 0xb1, 0xbc, 0x00, 0xe0, + 0x54, 0x23, 0xa1, 0x4d, 0x91, 0x42, 0x31, 0x6c, 0xc5, 0xc1, 0xe4, 0x70, 0xfc, 0x9d, 0x1e, 0xcf, + 0x52, 0x8d, 0x8f, 0x8e, 0x2a, 0xcf, 0x8c, 0x2e, 0x21, 0x50, 0x98, 0x2c, 0x9b, 0x9a, 0x11, 0x74, + 0x37, 0x85, 0xdf, 0xb1, 0xe7, 0x77, 0x3c, 0x14, 0x68, 0xb7, 0xaa, 0x31, 0xa2, 0x2b, 0xe8, 0xd5, + 0x59, 0x32, 0x79, 0x46, 0x28, 0x4f, 0xa1, 0x6b, 0x91, 0x8a, 0x35, 0x37, 0xe1, 0xa3, 0xdf, 0x61, + 0xc7, 0x55, 0xe3, 0x45, 0xaf, 0x02, 0xda, 0x0e, 0xc8, 0x13, 0x90, 0xc4, 0x89, 0xe5, 0xb9, 0x1b, + 0xc7, 0x89, 0x36, 0x73, 0x5d, 0xf5, 0x88, 0xb8, 0xa5, 0xfa, 0x8e, 0xcc, 0x1a, 0x30, 0x25, 0x19, + 0x43, 0x1f, 0xb3, 0xe5, 0x4f, 0xf7, 0x9f, 0x73, 0x77, 0x31, 0x5b, 0xfa, 0xe6, 0x39, 0xec, 0xe8, + 0x84, 0x5f, 0x56, 0x68, 0x29, 0x6c, 0xb9, 0x55, 0xa1, 0xbf, 0xea, 0x3e, 0x59, 0xe0, 0x7a, 0x5a, + 0x0b, 0xea, 0xcb, 0x94, 0x23, 0x68, 0xaf, 0xd2, 0x8c, 0x29, 0xfc, 0x3f, 0x14, 0x71, 0x30, 0x39, + 0xf0, 0x23, 0xd5, 0xcd, 0x77, 0x15, 0x54, 0xb5, 0x13, 0xdd, 0x40, 0xe0, 0x1d, 0xf7, 0xd7, 0x57, + 0x5c, 0xef, 0xbf, 0x95, 0x03, 0xf1, 0x5e, 0x0e, 0xc4, 0x47, 0x39, 0x10, 0xcf, 0x9d, 0x2a, 0x60, + 0x16, 0x8b, 0x8e, 0xfb, 0xf7, 0xd9, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x81, 0x1e, 0xc0, 0x24, + 0x18, 0x02, 0x00, 0x00, } diff --git a/prompb/remote.proto b/prompb/remote.proto index 172629792..90877cc22 100644 --- a/prompb/remote.proto +++ b/prompb/remote.proto @@ -35,6 +35,7 @@ message Query { int64 start_timestamp_ms = 1; int64 end_timestamp_ms = 2; repeated prometheus.LabelMatcher matchers = 3; + prometheus.ReadHints hints = 4; } message QueryResult { diff --git a/prompb/types.pb.go b/prompb/types.pb.go index 59a4a4b0c..7093ec173 100644 --- a/prompb/types.pb.go +++ b/prompb/types.pb.go @@ -165,12 +165,37 @@ func (m *LabelMatcher) GetValue() string { return "" } +type ReadHints struct { + StepMs int64 `protobuf:"varint,1,opt,name=step_ms,json=stepMs,proto3" json:"step_ms,omitempty"` + Func string `protobuf:"bytes,2,opt,name=func,proto3" json:"func,omitempty"` +} + +func (m *ReadHints) Reset() { *m = ReadHints{} } +func (m *ReadHints) String() string { return proto.CompactTextString(m) } +func (*ReadHints) ProtoMessage() {} +func (*ReadHints) Descriptor() ([]byte, []int) { return fileDescriptorTypes, []int{5} } + +func (m *ReadHints) GetStepMs() int64 { + if m != nil { + return m.StepMs + } + return 0 +} + +func (m *ReadHints) GetFunc() string { + if m != nil { + return m.Func + } + return "" +} + func init() { proto.RegisterType((*Sample)(nil), "prometheus.Sample") proto.RegisterType((*TimeSeries)(nil), "prometheus.TimeSeries") proto.RegisterType((*Label)(nil), "prometheus.Label") proto.RegisterType((*Labels)(nil), "prometheus.Labels") proto.RegisterType((*LabelMatcher)(nil), "prometheus.LabelMatcher") + proto.RegisterType((*ReadHints)(nil), "prometheus.ReadHints") proto.RegisterEnum("prometheus.LabelMatcher_Type", LabelMatcher_Type_name, LabelMatcher_Type_value) } func (m *Sample) Marshal() (dAtA []byte, err error) { @@ -339,6 +364,35 @@ func (m *LabelMatcher) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *ReadHints) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ReadHints) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.StepMs != 0 { + dAtA[i] = 0x8 + i++ + i = encodeVarintTypes(dAtA, i, uint64(m.StepMs)) + } + if len(m.Func) > 0 { + dAtA[i] = 0x12 + i++ + i = encodeVarintTypes(dAtA, i, uint64(len(m.Func))) + i += copy(dAtA[i:], m.Func) + } + return i, nil +} + func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -421,6 +475,19 @@ func (m *LabelMatcher) Size() (n int) { return n } +func (m *ReadHints) Size() (n int) { + var l int + _ = l + if m.StepMs != 0 { + n += 1 + sovTypes(uint64(m.StepMs)) + } + l = len(m.Func) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + func sovTypes(x uint64) (n int) { for { n++ @@ -942,6 +1009,104 @@ func (m *LabelMatcher) Unmarshal(dAtA []byte) error { } return nil } +func (m *ReadHints) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ReadHints: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ReadHints: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StepMs", wireType) + } + m.StepMs = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StepMs |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Func", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Func = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTypes(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 @@ -1050,25 +1215,28 @@ var ( func init() { proto.RegisterFile("types.proto", fileDescriptorTypes) } var fileDescriptorTypes = []byte{ - // 316 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xc1, 0x6a, 0xea, 0x40, - 0x14, 0x86, 0x9d, 0x24, 0x46, 0x3c, 0x5e, 0x2e, 0xe9, 0xe0, 0x22, 0x94, 0xd6, 0x4a, 0x56, 0x29, - 0x94, 0x88, 0x76, 0x55, 0xe8, 0x4a, 0xc8, 0xce, 0x16, 0x1c, 0x5d, 0x75, 0x37, 0x96, 0x83, 0x0a, - 0x99, 0x66, 0xc8, 0x8c, 0x05, 0x1f, 0xa4, 0xef, 0xe4, 0xb2, 0x4f, 0x50, 0x8a, 0x4f, 0x52, 0x66, - 0x46, 0x1b, 0xa1, 0x85, 0xee, 0xce, 0xf9, 0xf3, 0x1d, 0xfe, 0x8f, 0x0c, 0x74, 0xf4, 0x56, 0xa2, - 0xca, 0x64, 0x55, 0xea, 0x92, 0x82, 0xac, 0x4a, 0x81, 0x7a, 0x85, 0x1b, 0x75, 0xde, 0x5d, 0x96, -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0x0d, 0x58, 0x1e, 0xf9, 0xe3, 0xee, 0x6e, 0xdf, 0x23, 0xef, 0xfb, - 0x1e, 0xf9, 0xdc, 0xf7, 0xc8, 0x53, 0x68, 0x2c, 0xe4, 0x62, 0x11, 0xda, 0x77, 0xbc, 0xfd, 0x0a, - 0x00, 0x00, 0xff, 0xff, 0x6c, 0xee, 0x68, 0x81, 0xf8, 0x01, 0x00, 0x00, + // 353 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xc1, 0x6a, 0xea, 0x40, + 0x14, 0x86, 0x9d, 0x24, 0x46, 0x3c, 0x5e, 0x2e, 0xb9, 0x83, 0x70, 0x43, 0x69, 0xad, 0x64, 0x95, + 0x42, 0x89, 0x68, 0x37, 0x2d, 0x74, 0x25, 0x04, 0xba, 0xd0, 0x82, 0xa3, 0xab, 0x6e, 0x4a, 0xb4, + 0xa7, 0x1a, 0xc8, 0x98, 0x21, 0x33, 0x16, 0x7c, 0x90, 0xbe, 0x93, 0xcb, 0x3e, 0x41, 0x29, 0x3e, + 0x49, 0x99, 0x89, 0x56, 0xa1, 0x85, 0xee, 0xce, 0xf9, 0xf3, 0x1d, 0xfe, 0x8f, 0x30, 0xd0, 0x50, + 0x6b, 0x81, 0x32, 0x12, 0x45, 0xae, 0x72, 0x0a, 0xa2, 0xc8, 0x39, 0xaa, 0x05, 0xae, 0xe4, 0x49, + 0x73, 0x9e, 0xcf, 0x73, 0x13, 0x77, 0xf4, 0x54, 0x12, 0xc1, 0x2d, 0xb8, 0xe3, 0x84, 0x8b, 0x0c, + 0x69, 0x13, 0xaa, 0x2f, 0x49, 0xb6, 0x42, 0x9f, 0xb4, 0x49, 0x48, 0x58, 0xb9, 0xd0, 0x53, 0xa8, + 0xab, 0x94, 0xa3, 0x54, 0x09, 0x17, 0xbe, 0xd5, 0x26, 0xa1, 0xcd, 0x0e, 0x41, 0x80, 0x00, 0x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6d, 0x5b, 0xe4, 0x63, 0xdb, 0x22, 0x0f, 0xae, 0xf6, 0x17, 0xd3, 0xa9, 0x6b, + 0x5e, 0xc0, 0xd5, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0x99, 0xf3, 0x92, 0x3d, 0x32, 0x02, 0x00, + 0x00, } diff --git a/prompb/types.proto b/prompb/types.proto index 99bea18dc..427f77968 100644 --- a/prompb/types.proto +++ b/prompb/types.proto @@ -49,3 +49,8 @@ message LabelMatcher { string name = 2; string value = 3; } + +message ReadHints { + int64 step_ms = 1; // Query step size in milliseconds. + string func = 2; // String representation of surrounding function or aggregation. +} diff --git a/storage/remote/codec.go b/storage/remote/codec.go index 4fcd0f2ce..d68c442e5 100644 --- a/storage/remote/codec.go +++ b/storage/remote/codec.go @@ -86,16 +86,22 @@ func ToWriteRequest(samples []*model.Sample) *prompb.WriteRequest { } // ToQuery builds a Query proto. -func ToQuery(from, to int64, matchers []*labels.Matcher) (*prompb.Query, error) { +func ToQuery(from, to int64, matchers []*labels.Matcher, p *storage.SelectParams) (*prompb.Query, error) { ms, err := toLabelMatchers(matchers) if err != nil { return nil, err } + rp := &prompb.ReadHints{ + StepMs: p.Step, + Func: p.Func, + } + return &prompb.Query{ StartTimestampMs: from, EndTimestampMs: to, Matchers: ms, + Hints: rp, }, nil } diff --git a/storage/remote/read.go b/storage/remote/read.go index 1fedad884..c99a8a961 100644 --- a/storage/remote/read.go +++ b/storage/remote/read.go @@ -43,8 +43,8 @@ type querier struct { // Select implements storage.Querier and uses the given matchers to read series // sets from the Client. -func (q *querier) Select(_ *storage.SelectParams, matchers ...*labels.Matcher) (storage.SeriesSet, error) { - query, err := ToQuery(q.mint, q.maxt, matchers) +func (q *querier) Select(p *storage.SelectParams, matchers ...*labels.Matcher) (storage.SeriesSet, error) { + query, err := ToQuery(q.mint, q.maxt, matchers, p) if err != nil { return nil, err } diff --git a/web/api/v1/api_test.go b/web/api/v1/api_test.go index ed57e7d9b..d935f12ed 100644 --- a/web/api/v1/api_test.go +++ b/web/api/v1/api_test.go @@ -40,6 +40,7 @@ import ( "github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/scrape" + "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage/remote" ) @@ -588,7 +589,7 @@ func TestReadEndpoint(t *testing.T) { if err != nil { t.Fatal(err) } - query, err := remote.ToQuery(0, 1, []*labels.Matcher{matcher1, matcher2}) + query, err := remote.ToQuery(0, 1, []*labels.Matcher{matcher1, matcher2}, &storage.SelectParams{Step: 0, Func: "avg"}) if err != nil { t.Fatal(err) }