Backport created timestamp to existing tests
Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
This commit is contained in:
parent
3c7e78cf3e
commit
226eb8dcd4
|
@ -26,10 +26,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCounterAdd(t *testing.T) {
|
func TestCounterAdd(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
nowFn := func() time.Time { return now }
|
||||||
counter := NewCounter(CounterOpts{
|
counter := NewCounter(CounterOpts{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Help: "test help",
|
Help: "test help",
|
||||||
ConstLabels: Labels{"a": "1", "b": "2"},
|
ConstLabels: Labels{"a": "1", "b": "2"},
|
||||||
|
now: nowFn,
|
||||||
}).(*counter)
|
}).(*counter)
|
||||||
counter.Inc()
|
counter.Inc()
|
||||||
if expected, got := 0.0, math.Float64frombits(counter.valBits); expected != got {
|
if expected, got := 0.0, math.Float64frombits(counter.valBits); expected != got {
|
||||||
|
@ -66,7 +69,10 @@ func TestCounterAdd(t *testing.T) {
|
||||||
{Name: proto.String("a"), Value: proto.String("1")},
|
{Name: proto.String("a"), Value: proto.String("1")},
|
||||||
{Name: proto.String("b"), Value: proto.String("2")},
|
{Name: proto.String("b"), Value: proto.String("2")},
|
||||||
},
|
},
|
||||||
Counter: &dto.Counter{Value: proto.Float64(67.42)},
|
Counter: &dto.Counter{
|
||||||
|
Value: proto.Float64(67.42),
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if !proto.Equal(expected, m) {
|
if !proto.Equal(expected, m) {
|
||||||
t.Errorf("expected %q, got %q", expected, m)
|
t.Errorf("expected %q, got %q", expected, m)
|
||||||
|
@ -139,9 +145,12 @@ func expectPanic(t *testing.T, op func(), errorMsg string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCounterAddInf(t *testing.T) {
|
func TestCounterAddInf(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
nowFn := func() time.Time { return now }
|
||||||
counter := NewCounter(CounterOpts{
|
counter := NewCounter(CounterOpts{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Help: "test help",
|
Help: "test help",
|
||||||
|
now: nowFn,
|
||||||
}).(*counter)
|
}).(*counter)
|
||||||
|
|
||||||
counter.Inc()
|
counter.Inc()
|
||||||
|
@ -173,7 +182,8 @@ func TestCounterAddInf(t *testing.T) {
|
||||||
|
|
||||||
expected := &dto.Metric{
|
expected := &dto.Metric{
|
||||||
Counter: &dto.Counter{
|
Counter: &dto.Counter{
|
||||||
Value: proto.Float64(math.Inf(1)),
|
Value: proto.Float64(math.Inf(1)),
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +193,12 @@ func TestCounterAddInf(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCounterAddLarge(t *testing.T) {
|
func TestCounterAddLarge(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
nowFn := func() time.Time { return now }
|
||||||
counter := NewCounter(CounterOpts{
|
counter := NewCounter(CounterOpts{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Help: "test help",
|
Help: "test help",
|
||||||
|
now: nowFn,
|
||||||
}).(*counter)
|
}).(*counter)
|
||||||
|
|
||||||
// large overflows the underlying type and should therefore be stored in valBits.
|
// large overflows the underlying type and should therefore be stored in valBits.
|
||||||
|
@ -203,7 +216,8 @@ func TestCounterAddLarge(t *testing.T) {
|
||||||
|
|
||||||
expected := &dto.Metric{
|
expected := &dto.Metric{
|
||||||
Counter: &dto.Counter{
|
Counter: &dto.Counter{
|
||||||
Value: proto.Float64(large),
|
Value: proto.Float64(large),
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,9 +227,12 @@ func TestCounterAddLarge(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCounterAddSmall(t *testing.T) {
|
func TestCounterAddSmall(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
nowFn := func() time.Time { return now }
|
||||||
counter := NewCounter(CounterOpts{
|
counter := NewCounter(CounterOpts{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Help: "test help",
|
Help: "test help",
|
||||||
|
now: nowFn,
|
||||||
}).(*counter)
|
}).(*counter)
|
||||||
small := 0.000000000001
|
small := 0.000000000001
|
||||||
counter.Add(small)
|
counter.Add(small)
|
||||||
|
@ -231,7 +248,8 @@ func TestCounterAddSmall(t *testing.T) {
|
||||||
|
|
||||||
expected := &dto.Metric{
|
expected := &dto.Metric{
|
||||||
Counter: &dto.Counter{
|
Counter: &dto.Counter{
|
||||||
Value: proto.Float64(small),
|
Value: proto.Float64(small),
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -319,6 +319,8 @@ func ExampleSummary() {
|
||||||
// internally).
|
// internally).
|
||||||
metric := &dto.Metric{}
|
metric := &dto.Metric{}
|
||||||
temps.Write(metric)
|
temps.Write(metric)
|
||||||
|
// We remove CreatedTimestamp just to make sure the assert below works.
|
||||||
|
metric.Summary.CreatedTimestamp = nil
|
||||||
|
|
||||||
printlnNormalized(metric)
|
printlnNormalized(metric)
|
||||||
|
|
||||||
|
@ -355,6 +357,11 @@ func ExampleSummaryVec() {
|
||||||
if err != nil || len(metricFamilies) != 1 {
|
if err != nil || len(metricFamilies) != 1 {
|
||||||
panic("unexpected behavior of custom test registry")
|
panic("unexpected behavior of custom test registry")
|
||||||
}
|
}
|
||||||
|
// We remove CreatedTimestamp just to make sure the assert below works.
|
||||||
|
for _, m := range metricFamilies[0].Metric {
|
||||||
|
m.Summary.CreatedTimestamp = nil
|
||||||
|
}
|
||||||
|
|
||||||
printlnNormalized(metricFamilies[0])
|
printlnNormalized(metricFamilies[0])
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
|
@ -405,6 +412,9 @@ func ExampleHistogram() {
|
||||||
// internally).
|
// internally).
|
||||||
metric := &dto.Metric{}
|
metric := &dto.Metric{}
|
||||||
temps.Write(metric)
|
temps.Write(metric)
|
||||||
|
// We remove CreatedTimestamp just to make sure the assert below works.
|
||||||
|
metric.Histogram.CreatedTimestamp = nil
|
||||||
|
|
||||||
printlnNormalized(metric)
|
printlnNormalized(metric)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
|
|
|
@ -469,6 +469,8 @@ func TestHistogramExemplar(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNativeHistogram(t *testing.T) {
|
func TestNativeHistogram(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
nowFn := func() time.Time { return now }
|
||||||
scenarios := []struct {
|
scenarios := []struct {
|
||||||
name string
|
name string
|
||||||
observations []float64 // With simulated interval of 1m.
|
observations []float64 // With simulated interval of 1m.
|
||||||
|
@ -499,17 +501,19 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
{CumulativeCount: proto.Uint64(3), UpperBound: proto.Float64(5)},
|
{CumulativeCount: proto.Uint64(3), UpperBound: proto.Float64(5)},
|
||||||
{CumulativeCount: proto.Uint64(3), UpperBound: proto.Float64(10)},
|
{CumulativeCount: proto.Uint64(3), UpperBound: proto.Float64(10)},
|
||||||
},
|
},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no observations",
|
name: "no observations",
|
||||||
factor: 1.1,
|
factor: 1.1,
|
||||||
want: &dto.Histogram{
|
want: &dto.Histogram{
|
||||||
SampleCount: proto.Uint64(0),
|
SampleCount: proto.Uint64(0),
|
||||||
SampleSum: proto.Float64(0),
|
SampleSum: proto.Float64(0),
|
||||||
Schema: proto.Int32(3),
|
Schema: proto.Int32(3),
|
||||||
ZeroThreshold: proto.Float64(2.938735877055719e-39),
|
ZeroThreshold: proto.Float64(2.938735877055719e-39),
|
||||||
ZeroCount: proto.Uint64(0),
|
ZeroCount: proto.Uint64(0),
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -525,6 +529,7 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(0)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(0)},
|
||||||
},
|
},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -542,7 +547,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
{Offset: proto.Int32(7), Length: proto.Uint32(1)},
|
{Offset: proto.Int32(7), Length: proto.Uint32(1)},
|
||||||
{Offset: proto.Int32(4), Length: proto.Uint32(1)},
|
{Offset: proto.Int32(4), Length: proto.Uint32(1)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, 0, 0},
|
PositiveDelta: []int64{1, 0, 0},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -558,7 +564,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -581,7 +588,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(-2), Length: proto.Uint32(6)},
|
{Offset: proto.Int32(-2), Length: proto.Uint32(6)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{2, 0, 0, 2, -1, -2},
|
PositiveDelta: []int64{2, 0, 0, 2, -1, -2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -602,7 +610,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(-1), Length: proto.Uint32(4)},
|
{Offset: proto.Int32(-1), Length: proto.Uint32(4)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{2, 2, 3, -6},
|
PositiveDelta: []int64{2, 2, 3, -6},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -618,7 +627,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
NegativeSpan: []*dto.BucketSpan{
|
NegativeSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
NegativeDelta: []int64{1, -1, 2, -2, 2},
|
NegativeDelta: []int64{1, -1, 2, -2, 2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -638,7 +648,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -659,7 +670,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(4), Length: proto.Uint32(1)},
|
{Offset: proto.Int32(4), Length: proto.Uint32(1)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{2},
|
PositiveDelta: []int64{2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -675,7 +687,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -692,7 +705,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
{Offset: proto.Int32(4092), Length: proto.Uint32(1)},
|
{Offset: proto.Int32(4092), Length: proto.Uint32(1)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, -1, 2, -2, 2, -1},
|
PositiveDelta: []int64{1, -1, 2, -2, 2, -1},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -712,7 +726,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -729,7 +744,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
PositiveDelta: []int64{1, -1, 2, -2, 2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -746,7 +762,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, 2, -1, -2, 1},
|
PositiveDelta: []int64{1, 2, -1, -2, 1},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -764,7 +781,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(1), Length: proto.Uint32(7)},
|
{Offset: proto.Int32(1), Length: proto.Uint32(7)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, 1, -2, 2, -2, 0, 1},
|
PositiveDelta: []int64{1, 1, -2, 2, -2, 0, 1},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -782,7 +800,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(2), Length: proto.Uint32(7)},
|
{Offset: proto.Int32(2), Length: proto.Uint32(7)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{2, -2, 2, -2, 0, 1, 0},
|
PositiveDelta: []int64{2, -2, 2, -2, 0, 1, 0},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -801,7 +820,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, 0},
|
PositiveDelta: []int64{1, 0},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -818,7 +838,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
NegativeSpan: []*dto.BucketSpan{
|
NegativeSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
NegativeDelta: []int64{1, -1, 2, -2, 2},
|
NegativeDelta: []int64{1, -1, 2, -2, 2},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -835,7 +856,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
NegativeSpan: []*dto.BucketSpan{
|
NegativeSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
{Offset: proto.Int32(0), Length: proto.Uint32(5)},
|
||||||
},
|
},
|
||||||
NegativeDelta: []int64{1, 2, -1, -2, 1},
|
NegativeDelta: []int64{1, 2, -1, -2, 1},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -853,7 +875,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
NegativeSpan: []*dto.BucketSpan{
|
NegativeSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(1), Length: proto.Uint32(7)},
|
{Offset: proto.Int32(1), Length: proto.Uint32(7)},
|
||||||
},
|
},
|
||||||
NegativeDelta: []int64{1, 1, -2, 2, -2, 0, 1},
|
NegativeDelta: []int64{1, 1, -2, 2, -2, 0, 1},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -871,7 +894,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
NegativeSpan: []*dto.BucketSpan{
|
NegativeSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(2), Length: proto.Uint32(7)},
|
{Offset: proto.Int32(2), Length: proto.Uint32(7)},
|
||||||
},
|
},
|
||||||
NegativeDelta: []int64{2, -2, 2, -2, 0, 1, 0},
|
NegativeDelta: []int64{2, -2, 2, -2, 0, 1, 0},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -890,7 +914,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
NegativeSpan: []*dto.BucketSpan{
|
NegativeSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
||||||
},
|
},
|
||||||
NegativeDelta: []int64{1, 0},
|
NegativeDelta: []int64{1, 0},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -908,7 +933,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, 0},
|
PositiveDelta: []int64{1, 0},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -927,7 +953,8 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
PositiveSpan: []*dto.BucketSpan{
|
PositiveSpan: []*dto.BucketSpan{
|
||||||
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
{Offset: proto.Int32(7), Length: proto.Uint32(2)},
|
||||||
},
|
},
|
||||||
PositiveDelta: []int64{1, 0},
|
PositiveDelta: []int64{1, 0},
|
||||||
|
CreatedTimestamp: timestamppb.New(nowFn()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -942,6 +969,7 @@ func TestNativeHistogram(t *testing.T) {
|
||||||
NativeHistogramMaxBucketNumber: s.maxBuckets,
|
NativeHistogramMaxBucketNumber: s.maxBuckets,
|
||||||
NativeHistogramMinResetDuration: s.minResetDuration,
|
NativeHistogramMinResetDuration: s.minResetDuration,
|
||||||
NativeHistogramMaxZeroThreshold: s.maxZeroThreshold,
|
NativeHistogramMaxZeroThreshold: s.maxZeroThreshold,
|
||||||
|
now: nowFn,
|
||||||
})
|
})
|
||||||
ts := time.Now().Add(30 * time.Second)
|
ts := time.Now().Add(30 * time.Second)
|
||||||
now := func() time.Time {
|
now := func() time.Time {
|
||||||
|
|
|
@ -37,6 +37,7 @@ import (
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"github.com/prometheus/common/expfmt"
|
"github.com/prometheus/common/expfmt"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// uncheckedCollector wraps a Collector but its Describe method yields no Desc.
|
// uncheckedCollector wraps a Collector but its Describe method yields no Desc.
|
||||||
|
@ -138,7 +139,8 @@ metric: <
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Counter: &dto.Counter{
|
Counter: &dto.Counter{
|
||||||
Value: proto.Float64(1),
|
Value: proto.Float64(1),
|
||||||
|
CreatedTimestamp: timestamppb.New(time.Now()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -153,7 +155,8 @@ metric: <
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Counter: &dto.Counter{
|
Counter: &dto.Counter{
|
||||||
Value: proto.Float64(1),
|
Value: proto.Float64(1),
|
||||||
|
CreatedTimestamp: timestamppb.New(time.Now()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
@ -43,9 +44,12 @@ func toMetricFamilies(cs ...Collector) []*dto.MetricFamily {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWrap(t *testing.T) {
|
func TestWrap(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
nowFn := func() time.Time { return now }
|
||||||
simpleCnt := NewCounter(CounterOpts{
|
simpleCnt := NewCounter(CounterOpts{
|
||||||
Name: "simpleCnt",
|
Name: "simpleCnt",
|
||||||
Help: "helpSimpleCnt",
|
Help: "helpSimpleCnt",
|
||||||
|
now: nowFn,
|
||||||
})
|
})
|
||||||
simpleCnt.Inc()
|
simpleCnt.Inc()
|
||||||
|
|
||||||
|
@ -58,6 +62,7 @@ func TestWrap(t *testing.T) {
|
||||||
preCnt := NewCounter(CounterOpts{
|
preCnt := NewCounter(CounterOpts{
|
||||||
Name: "pre_simpleCnt",
|
Name: "pre_simpleCnt",
|
||||||
Help: "helpSimpleCnt",
|
Help: "helpSimpleCnt",
|
||||||
|
now: nowFn,
|
||||||
})
|
})
|
||||||
preCnt.Inc()
|
preCnt.Inc()
|
||||||
|
|
||||||
|
@ -65,6 +70,7 @@ func TestWrap(t *testing.T) {
|
||||||
Name: "simpleCnt",
|
Name: "simpleCnt",
|
||||||
Help: "helpSimpleCnt",
|
Help: "helpSimpleCnt",
|
||||||
ConstLabels: Labels{"foo": "bar"},
|
ConstLabels: Labels{"foo": "bar"},
|
||||||
|
now: nowFn,
|
||||||
})
|
})
|
||||||
barLabeledCnt.Inc()
|
barLabeledCnt.Inc()
|
||||||
|
|
||||||
|
@ -72,6 +78,7 @@ func TestWrap(t *testing.T) {
|
||||||
Name: "simpleCnt",
|
Name: "simpleCnt",
|
||||||
Help: "helpSimpleCnt",
|
Help: "helpSimpleCnt",
|
||||||
ConstLabels: Labels{"foo": "baz"},
|
ConstLabels: Labels{"foo": "baz"},
|
||||||
|
now: nowFn,
|
||||||
})
|
})
|
||||||
bazLabeledCnt.Inc()
|
bazLabeledCnt.Inc()
|
||||||
|
|
||||||
|
@ -79,6 +86,7 @@ func TestWrap(t *testing.T) {
|
||||||
Name: "pre_simpleCnt",
|
Name: "pre_simpleCnt",
|
||||||
Help: "helpSimpleCnt",
|
Help: "helpSimpleCnt",
|
||||||
ConstLabels: Labels{"foo": "bar"},
|
ConstLabels: Labels{"foo": "bar"},
|
||||||
|
now: nowFn,
|
||||||
})
|
})
|
||||||
labeledPreCnt.Inc()
|
labeledPreCnt.Inc()
|
||||||
|
|
||||||
|
@ -86,6 +94,7 @@ func TestWrap(t *testing.T) {
|
||||||
Name: "pre_simpleCnt",
|
Name: "pre_simpleCnt",
|
||||||
Help: "helpSimpleCnt",
|
Help: "helpSimpleCnt",
|
||||||
ConstLabels: Labels{"foo": "bar", "dings": "bums"},
|
ConstLabels: Labels{"foo": "bar", "dings": "bums"},
|
||||||
|
now: nowFn,
|
||||||
})
|
})
|
||||||
twiceLabeledPreCnt.Inc()
|
twiceLabeledPreCnt.Inc()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue