@@ -21,9 +21,7 @@ import (
21
21
"github.com/prometheus/prometheus/model/timestamp"
22
22
"github.com/weaveworks/common/httpgrpc"
23
23
24
- "github.com/cortexproject/cortex/pkg/cortexpb"
25
24
"github.com/cortexproject/cortex/pkg/querier/tripperware"
26
- "github.com/cortexproject/cortex/pkg/querier/tripperware/utils"
27
25
"github.com/cortexproject/cortex/pkg/util"
28
26
"github.com/cortexproject/cortex/pkg/util/spanlogger"
29
27
)
@@ -150,7 +148,7 @@ func (c prometheusCodec) MergeResponse(responses ...tripperware.Response) (tripp
150
148
Status : StatusSuccess ,
151
149
Data : PrometheusData {
152
150
ResultType : model .ValMatrix .String (),
153
- Result : matrixMerge (promResponses ),
151
+ Result : tripperware . MatrixMerge (promResponses ),
154
152
Stats : statsMerge (c .sharded , promResponses ),
155
153
},
156
154
}
@@ -345,49 +343,6 @@ func statsMerge(shouldSumStats bool, resps []*PrometheusResponse) *tripperware.P
345
343
return tripperware .StatsMerge (output )
346
344
}
347
345
348
- func matrixMerge (resps []* PrometheusResponse ) []tripperware.SampleStream {
349
- output := map [string ]* tripperware.SampleStream {}
350
- for _ , resp := range resps {
351
- for _ , stream := range resp .Data .Result {
352
- metric := cortexpb .FromLabelAdaptersToLabels (stream .Labels ).String ()
353
- existing , ok := output [metric ]
354
- if ! ok {
355
- existing = & tripperware.SampleStream {
356
- Labels : stream .Labels ,
357
- }
358
- }
359
- // We need to make sure we don't repeat samples. This causes some visualisations to be broken in Grafana.
360
- // The prometheus API is inclusive of start and end timestamps.
361
- if len (existing .Samples ) > 0 && len (stream .Samples ) > 0 {
362
- existingEndTs := existing .Samples [len (existing .Samples )- 1 ].TimestampMs
363
- if existingEndTs == stream .Samples [0 ].TimestampMs {
364
- // Typically this the cases where only 1 sample point overlap,
365
- // so optimize with simple code.
366
- stream .Samples = stream .Samples [1 :]
367
- } else if existingEndTs > stream .Samples [0 ].TimestampMs {
368
- // Overlap might be big, use heavier algorithm to remove overlap.
369
- stream .Samples = utils .SliceSamples (stream .Samples , existingEndTs )
370
- } // else there is no overlap, yay!
371
- }
372
- existing .Samples = append (existing .Samples , stream .Samples ... )
373
- output [metric ] = existing
374
- }
375
- }
376
-
377
- keys := make ([]string , 0 , len (output ))
378
- for key := range output {
379
- keys = append (keys , key )
380
- }
381
- sort .Strings (keys )
382
-
383
- result := make ([]tripperware.SampleStream , 0 , len (output ))
384
- for _ , key := range keys {
385
- result = append (result , * output [key ])
386
- }
387
-
388
- return result
389
- }
390
-
391
346
func parseDurationMs (s string ) (int64 , error ) {
392
347
if d , err := strconv .ParseFloat (s , 64 ); err == nil {
393
348
ts := d * float64 (time .Second / time .Millisecond )
0 commit comments