@@ -35,30 +35,34 @@ var (
35
35
}
36
36
)
37
37
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 )
40
40
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" }
41
41
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
+ },
55
57
},
56
58
})
57
59
}
58
60
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
+ },
62
66
}
63
67
}
64
68
@@ -164,36 +168,44 @@ func Benchmark_convertV2RequestToV1(b *testing.B) {
164
168
}
165
169
166
170
func Test_convertV2RequestToV1 (t * testing.T ) {
167
- var v2Req writev2. Request
171
+ var v2Req cortexpb. PreallocWriteRequestV2
168
172
169
173
fh := tsdbutil .GenerateTestFloatHistogram (1 )
170
- ph := writev2 . FromFloatHistogram (4 , fh )
174
+ ph := cortexpb . FloatHistogramToHistogramProto (4 , fh )
171
175
172
176
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 {
174
178
{
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 ,
178
183
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 }},
181
189
},
182
- Samples : []writev2.Sample {{Value : 1 , Timestamp : 1 }},
183
- Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 1 }},
184
190
},
185
191
{
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
+ },
188
196
},
189
197
{
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
+ },
192
202
},
193
203
{
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
+ },
197
209
},
198
210
}
199
211
@@ -394,7 +406,7 @@ func TestHandler_ignoresSkipLabelNameValidationIfSet(t *testing.T) {
394
406
}
395
407
}
396
408
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 ) {
398
410
t .Helper ()
399
411
return func (ctx context.Context , request * cortexpb.WriteRequest ) (response * cortexpb.WriteResponse , err error ) {
400
412
assert .Len (t , request .Timeseries , 1 )
@@ -444,7 +456,7 @@ func createRequest(t *testing.T, protobuf []byte, isV2 bool) *http.Request {
444
456
return req
445
457
}
446
458
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 {
448
460
t .Helper ()
449
461
input := writev2.Request {
450
462
Symbols : []string {"" , "__name__" , "foo" },
@@ -500,7 +512,7 @@ func createPrometheusRemoteWriteProtobuf(t *testing.T) []byte {
500
512
require .NoError (t , err )
501
513
return inoutBytes
502
514
}
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 {
504
516
t .Helper ()
505
517
ts := cortexpb.PreallocTimeseries {
506
518
TimeSeries : & cortexpb.TimeSeries {
@@ -520,4 +532,4 @@ func createCortexWriteRequestProtobuf(t *testing.T, skipLabelNameValidation bool
520
532
inoutBytes , err := input .Marshal ()
521
533
require .NoError (t , err )
522
534
return inoutBytes
523
- }
535
+ }
0 commit comments