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

Function TestPusherAppendable

pkg/ruler/compat_test.go:42–252  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestPusherAppendable(t *testing.T) {
43 pusher := &fakePusher{}
44 pa := NewPusherAppendable(pusher, "user-1", nil, prometheus.NewCounter(prometheus.CounterOpts{}), prometheus.NewCounter(prometheus.CounterOpts{}))
45
46 lbls1 := cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{labels.MetricName: "foo_bar"}))
47 lbls2 := cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{labels.MetricName: "ALERTS", labels.AlertName: "boop"}))
48
49 testHistogram := tsdbutil.GenerateTestHistogram(1)
50 testFloatHistogram := tsdbutil.GenerateTestFloatHistogram(2)
51 testHistogramWithNaN := tsdbutil.GenerateTestHistogram(1)
52 testFloatHistogramWithNaN := tsdbutil.GenerateTestFloatHistogram(1)
53 testHistogramWithNaN.Sum = math.Float64frombits(value.StaleNaN)
54 testFloatHistogramWithNaN.Sum = math.Float64frombits(value.StaleNaN)
55
56 for _, tc := range []struct {
57 name string
58 series string
59 value float64
60 histogram *histogram.Histogram
61 floatHistogram *histogram.FloatHistogram
62 expectedReq *cortexpb.WriteRequest
63 }{
64 {
65 name: "tenant, normal value",
66 series: "foo_bar",
67 value: 1.234,
68 expectedReq: &cortexpb.WriteRequest{
69 Timeseries: []cortexpb.PreallocTimeseries{
70 {
71 TimeSeries: &cortexpb.TimeSeries{
72 Labels: lbls1,
73 Samples: []cortexpb.Sample{
74 {Value: 1.234, TimestampMs: 120_000},
75 },
76 },
77 },
78 },
79 Source: cortexpb.RULE,
80 },
81 },
82 {
83 name: "tenant, stale nan value",
84 series: "foo_bar",
85 value: math.Float64frombits(value.StaleNaN),
86 expectedReq: &cortexpb.WriteRequest{
87 Timeseries: []cortexpb.PreallocTimeseries{
88 {
89 TimeSeries: &cortexpb.TimeSeries{
90 Labels: lbls1,
91 Samples: []cortexpb.Sample{
92 {Value: math.Float64frombits(value.StaleNaN), TimestampMs: 120_000},
93 },
94 },
95 },
96 },
97 Source: cortexpb.RULE,
98 },
99 },

Callers

nothing calls this directly

Calls 12

AppenderMethod · 0.95
WrapHistogramFunction · 0.92
NewPusherAppendableFunction · 0.85
AppendMethod · 0.80
RunMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
AppendHistogramMethod · 0.45
CommitMethod · 0.45

Tested by

no test coverage detected