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

Function GenerateChunk

pkg/util/test_util.go:33–75  ·  view source on GitHub ↗
(t require.TestingT, step time.Duration, from model.Time, points int, enc promchunk.Encoding, additionalLabels ...labels.Label)

Source from the content-addressed store, hash-verified

31}
32
33func GenerateChunk(t require.TestingT, step time.Duration, from model.Time, points int, enc promchunk.Encoding, additionalLabels ...labels.Label) chunk.Chunk {
34 var hasMetricName bool
35 for _, lbl := range additionalLabels {
36 if lbl.Name == model.MetricNameLabel {
37 hasMetricName = true
38 }
39 }
40 metric := labels.NewBuilder(labels.New(additionalLabels...))
41 if !hasMetricName {
42 metric = metric.Set(model.MetricNameLabel, "foo")
43 }
44 pe := enc.PromChunkEncoding()
45 pc, err := chunkenc.NewEmptyChunk(pe)
46 require.NoError(t, err)
47 appender, err := pc.Appender()
48 require.NoError(t, err)
49 ts := from
50
51 switch pe {
52 case chunkenc.EncXOR:
53 for range points {
54 appender.Append(int64(ts), float64(ts))
55 ts = ts.Add(step)
56 }
57 case chunkenc.EncHistogram:
58 histograms := histogram_util.GenerateTestHistograms(int(from), int(step/time.Millisecond), points)
59 for i := range points {
60 _, _, appender, err = appender.AppendHistogram(nil, int64(ts), histograms[i], true)
61 require.NoError(t, err)
62 ts = ts.Add(step)
63 }
64 case chunkenc.EncFloatHistogram:
65 histograms := histogram_util.GenerateTestHistograms(int(from), int(step/time.Millisecond), points)
66 for i := range points {
67 _, _, appender, err = appender.AppendFloatHistogram(nil, int64(ts), histograms[i].ToFloat(nil), true)
68 require.NoError(t, err)
69 ts = ts.Add(step)
70 }
71 }
72
73 ts = ts.Add(-step) // undo the add that we did just before exiting the loop
74 return chunk.NewChunk(metric.Labels(), pc, from, ts)
75}

Callers 9

TestIngesterStreamingFunction · 0.92
createAggrChunkFunction · 0.92
makeMockChunksFunction · 0.92
mkGenericChunkFunction · 0.92
createChunksFunction · 0.92
TestSamplesCountFunction · 0.92

Calls 8

NewChunkFunction · 0.92
PromChunkEncodingMethod · 0.80
AppendMethod · 0.80
SetMethod · 0.65
AppenderMethod · 0.45
AddMethod · 0.45
AppendHistogramMethod · 0.45
LabelsMethod · 0.45

Tested by 9

TestIngesterStreamingFunction · 0.74
createAggrChunkFunction · 0.74
makeMockChunksFunction · 0.74
mkGenericChunkFunction · 0.74
createChunksFunction · 0.74
TestSamplesCountFunction · 0.74