@@ -35,30 +35,34 @@ var (
3535 }
3636)
3737
38- func makeV2ReqWithSeries (num int ) * writev2. Request {
39- ts := make ([]writev2. TimeSeries , 0 , num )
38+ func makeV2ReqWithSeries (num int ) * cortexpb. PreallocWriteRequestV2 {
39+ ts := make ([]cortexpb. PreallocTimeseriesV2 , 0 , num )
4040 symbols := []string {"" , "__name__" , "test_metric1" , "b" , "c" , "baz" , "qux" , "d" , "e" , "foo" , "bar" , "f" , "g" , "h" , "i" , "Test gauge for test purposes" , "Maybe op/sec who knows (:" , "Test counter for test purposes" }
4141 for i := 0 ; i < num ; i ++ {
42- ts = append (ts , writev2.TimeSeries {
43- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
44- Metadata : writev2.Metadata {
45- Type : writev2 .Metadata_METRIC_TYPE_GAUGE ,
46-
47- HelpRef : 15 ,
48- UnitRef : 16 ,
49- },
50- Samples : []writev2.Sample {{Value : 1 , Timestamp : 10 }},
51- Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 10 }},
52- Histograms : []writev2.Histogram {
53- writev2 .FromIntHistogram (10 , & testHistogram ),
54- writev2 .FromFloatHistogram (20 , testHistogram .ToFloat (nil )),
42+ ts = append (ts , cortexpb.PreallocTimeseriesV2 {
43+ TimeSeriesV2 : & cortexpb.TimeSeriesV2 {
44+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
45+ Metadata : cortexpb.MetadataV2 {
46+ Type : cortexpb .METRIC_TYPE_GAUGE ,
47+
48+ HelpRef : 15 ,
49+ UnitRef : 16 ,
50+ },
51+ Samples : []cortexpb.Sample {{Value : 1 , TimestampMs : 10 }},
52+ Exemplars : []cortexpb.ExemplarV2 {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 10 }},
53+ Histograms : []cortexpb.Histogram {
54+ cortexpb .HistogramToHistogramProto (10 , & testHistogram ),
55+ cortexpb .FloatHistogramToHistogramProto (20 , testHistogram .ToFloat (nil )),
56+ },
5557 },
5658 })
5759 }
5860
59- return & writev2.Request {
60- Symbols : symbols ,
61- Timeseries : ts ,
61+ return & cortexpb.PreallocWriteRequestV2 {
62+ WriteRequestV2 : cortexpb.WriteRequestV2 {
63+ Symbols : symbols ,
64+ Timeseries : ts ,
65+ },
6266 }
6367}
6468
@@ -164,36 +168,44 @@ func Benchmark_convertV2RequestToV1(b *testing.B) {
164168}
165169
166170func Test_convertV2RequestToV1 (t * testing.T ) {
167- var v2Req writev2. Request
171+ var v2Req cortexpb. PreallocWriteRequestV2
168172
169173 fh := tsdbutil .GenerateTestFloatHistogram (1 )
170- ph := writev2 . FromFloatHistogram (4 , fh )
174+ ph := cortexpb . FloatHistogramToHistogramProto (4 , fh )
171175
172176 symbols := []string {"" , "__name__" , "test_metric" , "b" , "c" , "baz" , "qux" , "d" , "e" , "foo" , "bar" , "f" , "g" , "h" , "i" , "Test gauge for test purposes" , "Maybe op/sec who knows (:" , "Test counter for test purposes" }
173- timeseries := []writev2. TimeSeries {
177+ timeseries := []cortexpb. PreallocTimeseriesV2 {
174178 {
175- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
176- Metadata : writev2.Metadata {
177- Type : writev2 .Metadata_METRIC_TYPE_COUNTER ,
179+ TimeSeriesV2 : & cortexpb.TimeSeriesV2 {
180+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
181+ Metadata : cortexpb.MetadataV2 {
182+ Type : cortexpb .METRIC_TYPE_COUNTER ,
178183
179- HelpRef : 15 ,
180- UnitRef : 16 ,
184+ HelpRef : 15 ,
185+ UnitRef : 16 ,
186+ },
187+ Samples : []cortexpb.Sample {{Value : 1 , TimestampMs : 1 }},
188+ Exemplars : []cortexpb.ExemplarV2 {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 1 }},
181189 },
182- Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
183- Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 1 }},
184190 },
185191 {
186- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
187- Samples : []writev2.Sample {{Value : 2 , Timestamp : 2 }},
192+ TimeSeriesV2 : & cortexpb.TimeSeriesV2 {
193+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
194+ Samples : []cortexpb.Sample {{Value : 2 , TimestampMs : 2 }},
195+ },
188196 },
189197 {
190- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
191- Samples : []writev2.Sample {{Value : 3 , Timestamp : 3 }},
198+ TimeSeriesV2 : & cortexpb.TimeSeriesV2 {
199+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
200+ Samples : []cortexpb.Sample {{Value : 3 , TimestampMs : 3 }},
201+ },
192202 },
193203 {
194- LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
195- Histograms : []writev2.Histogram {ph , ph },
196- Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 1 }},
204+ TimeSeriesV2 : & cortexpb.TimeSeriesV2 {
205+ LabelsRefs : []uint32 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 },
206+ Histograms : []cortexpb.Histogram {ph , ph },
207+ Exemplars : []cortexpb.ExemplarV2 {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 1 }},
208+ },
197209 },
198210 }
199211
@@ -394,7 +406,7 @@ func TestHandler_ignoresSkipLabelNameValidationIfSet(t *testing.T) {
394406 }
395407}
396408
397- func verifyWriteRequestHandler (t * testing.T , expectSource cortexpb.WriteRequest_SourceEnum ) func (ctx context.Context , request * cortexpb.WriteRequest ) (response * cortexpb.WriteResponse , err error ) {
409+ func verifyWriteRequestHandler (t * testing.T , expectSource cortexpb.SourceEnum ) func (ctx context.Context , request * cortexpb.WriteRequest ) (response * cortexpb.WriteResponse , err error ) {
398410 t .Helper ()
399411 return func (ctx context.Context , request * cortexpb.WriteRequest ) (response * cortexpb.WriteResponse , err error ) {
400412 assert .Len (t , request .Timeseries , 1 )
@@ -444,7 +456,7 @@ func createRequest(t *testing.T, protobuf []byte, isV2 bool) *http.Request {
444456 return req
445457}
446458
447- func createCortexRemoteWriteV2Protobuf (t * testing.T , skipLabelNameValidation bool , source cortexpb.WriteRequest_SourceEnum ) []byte {
459+ func createCortexRemoteWriteV2Protobuf (t * testing.T , skipLabelNameValidation bool , source cortexpb.SourceEnum ) []byte {
448460 t .Helper ()
449461 input := writev2.Request {
450462 Symbols : []string {"" , "__name__" , "foo" },
@@ -500,7 +512,7 @@ func createPrometheusRemoteWriteProtobuf(t *testing.T) []byte {
500512 require .NoError (t , err )
501513 return inoutBytes
502514}
503- func createCortexWriteRequestProtobuf (t * testing.T , skipLabelNameValidation bool , source cortexpb.WriteRequest_SourceEnum ) []byte {
515+ func createCortexWriteRequestProtobuf (t * testing.T , skipLabelNameValidation bool , source cortexpb.SourceEnum ) []byte {
504516 t .Helper ()
505517 ts := cortexpb.PreallocTimeseries {
506518 TimeSeries : & cortexpb.TimeSeries {
@@ -520,4 +532,4 @@ func createCortexWriteRequestProtobuf(t *testing.T, skipLabelNameValidation bool
520532 inoutBytes , err := input .Marshal ()
521533 require .NoError (t , err )
522534 return inoutBytes
523- }
535+ }
0 commit comments