MCPcopy Create free account
hub / github.com/cortexproject/cortex / sliceSamples

Function sliceSamples

pkg/querier/tripperware/merge.go:389–403  ·  view source on GitHub ↗

sliceSamples assumes given samples are sorted by timestamp in ascending order and return a sub slice whose first element's is the smallest timestamp that is strictly bigger than the given minTs. Empty slice is returned if minTs is bigger than all the timestamps in samples. If the given samples slice

(samples []cortexpb.Sample, minTs int64)

Source from the content-addressed store, hash-verified

387// timestamps in samples.
388// If the given samples slice is not sorted then unexpected samples would be returned.
389func sliceSamples(samples []cortexpb.Sample, minTs int64) []cortexpb.Sample {
390 if len(samples) == 0 || minTs < samples[0].TimestampMs {
391 return samples
392 }
393
394 if len(samples) > 0 && minTs > samples[len(samples)-1].TimestampMs {
395 return samples[len(samples):]
396 }
397
398 searchResult := sort.Search(len(samples), func(i int) bool {
399 return samples[i].TimestampMs > minTs
400 })
401
402 return samples[searchResult:]
403}
404
405// sliceHistograms assumes given histogram are sorted by timestamp in ascending order and
406// return a sub slice whose first element's is the smallest timestamp that is strictly

Callers 2

mergeSampleStreamsFunction · 0.85
TestSliceSamplesFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestSliceSamplesFunction · 0.68