Export single ith test histogram generation functions (#11911)
* Export single ith test histogram generation functions Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> * Do not set counter reset hint for non-gauge histograms individually Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> * Apply suggestions from code review Co-authored-by: Ganesh Vernekar <ganeshvern@gmail.com> Signed-off-by: George Krajcsovits <krajorama@users.noreply.github.com> --------- Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com> Signed-off-by: George Krajcsovits <krajorama@users.noreply.github.com> Co-authored-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
parent
e023d896f2
commit
1f0cc09579
136
tsdb/head.go
136
tsdb/head.go
|
@ -2040,106 +2040,90 @@ func (h *Head) updateWALReplayStatusRead(current int) {
|
||||||
|
|
||||||
func GenerateTestHistograms(n int) (r []*histogram.Histogram) {
|
func GenerateTestHistograms(n int) (r []*histogram.Histogram) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
h := histogram.Histogram{
|
h := GenerateTestHistogram(i)
|
||||||
Count: 10 + uint64(i*8),
|
|
||||||
ZeroCount: 2 + uint64(i),
|
|
||||||
ZeroThreshold: 0.001,
|
|
||||||
Sum: 18.4 * float64(i+1),
|
|
||||||
Schema: 1,
|
|
||||||
PositiveSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
PositiveBuckets: []int64{int64(i + 1), 1, -1, 0},
|
|
||||||
NegativeSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
NegativeBuckets: []int64{int64(i + 1), 1, -1, 0},
|
|
||||||
}
|
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
h.CounterResetHint = histogram.NotCounterReset
|
h.CounterResetHint = histogram.NotCounterReset
|
||||||
}
|
}
|
||||||
r = append(r, &h)
|
r = append(r, h)
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates a test histogram, it is up to the user to set any known counter reset hint.
|
||||||
|
func GenerateTestHistogram(i int) *histogram.Histogram {
|
||||||
|
return &histogram.Histogram{
|
||||||
|
Count: 10 + uint64(i*8),
|
||||||
|
ZeroCount: 2 + uint64(i),
|
||||||
|
ZeroThreshold: 0.001,
|
||||||
|
Sum: 18.4 * float64(i+1),
|
||||||
|
Schema: 1,
|
||||||
|
PositiveSpans: []histogram.Span{
|
||||||
|
{Offset: 0, Length: 2},
|
||||||
|
{Offset: 1, Length: 2},
|
||||||
|
},
|
||||||
|
PositiveBuckets: []int64{int64(i + 1), 1, -1, 0},
|
||||||
|
NegativeSpans: []histogram.Span{
|
||||||
|
{Offset: 0, Length: 2},
|
||||||
|
{Offset: 1, Length: 2},
|
||||||
|
},
|
||||||
|
NegativeBuckets: []int64{int64(i + 1), 1, -1, 0},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GenerateTestGaugeHistograms(n int) (r []*histogram.Histogram) {
|
func GenerateTestGaugeHistograms(n int) (r []*histogram.Histogram) {
|
||||||
for x := 0; x < n; x++ {
|
for x := 0; x < n; x++ {
|
||||||
i := rand.Intn(n)
|
r = append(r, GenerateTestGaugeHistogram(rand.Intn(n)))
|
||||||
r = append(r, &histogram.Histogram{
|
|
||||||
CounterResetHint: histogram.GaugeType,
|
|
||||||
Count: 10 + uint64(i*8),
|
|
||||||
ZeroCount: 2 + uint64(i),
|
|
||||||
ZeroThreshold: 0.001,
|
|
||||||
Sum: 18.4 * float64(i+1),
|
|
||||||
Schema: 1,
|
|
||||||
PositiveSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
PositiveBuckets: []int64{int64(i + 1), 1, -1, 0},
|
|
||||||
NegativeSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
NegativeBuckets: []int64{int64(i + 1), 1, -1, 0},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateTestGaugeHistogram(i int) *histogram.Histogram {
|
||||||
|
h := GenerateTestHistogram(i)
|
||||||
|
h.CounterResetHint = histogram.GaugeType
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
func GenerateTestFloatHistograms(n int) (r []*histogram.FloatHistogram) {
|
func GenerateTestFloatHistograms(n int) (r []*histogram.FloatHistogram) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
h := histogram.FloatHistogram{
|
h := GenerateTestFloatHistogram(i)
|
||||||
Count: 10 + float64(i*8),
|
|
||||||
ZeroCount: 2 + float64(i),
|
|
||||||
ZeroThreshold: 0.001,
|
|
||||||
Sum: 18.4 * float64(i+1),
|
|
||||||
Schema: 1,
|
|
||||||
PositiveSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
PositiveBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
|
|
||||||
NegativeSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
NegativeBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
|
|
||||||
}
|
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
h.CounterResetHint = histogram.NotCounterReset
|
h.CounterResetHint = histogram.NotCounterReset
|
||||||
}
|
}
|
||||||
r = append(r, &h)
|
r = append(r, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates a test float histogram, it is up to the user to set any known counter reset hint.
|
||||||
|
func GenerateTestFloatHistogram(i int) *histogram.FloatHistogram {
|
||||||
|
return &histogram.FloatHistogram{
|
||||||
|
Count: 10 + float64(i*8),
|
||||||
|
ZeroCount: 2 + float64(i),
|
||||||
|
ZeroThreshold: 0.001,
|
||||||
|
Sum: 18.4 * float64(i+1),
|
||||||
|
Schema: 1,
|
||||||
|
PositiveSpans: []histogram.Span{
|
||||||
|
{Offset: 0, Length: 2},
|
||||||
|
{Offset: 1, Length: 2},
|
||||||
|
},
|
||||||
|
PositiveBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
|
||||||
|
NegativeSpans: []histogram.Span{
|
||||||
|
{Offset: 0, Length: 2},
|
||||||
|
{Offset: 1, Length: 2},
|
||||||
|
},
|
||||||
|
NegativeBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GenerateTestGaugeFloatHistograms(n int) (r []*histogram.FloatHistogram) {
|
func GenerateTestGaugeFloatHistograms(n int) (r []*histogram.FloatHistogram) {
|
||||||
for x := 0; x < n; x++ {
|
for x := 0; x < n; x++ {
|
||||||
i := rand.Intn(n)
|
r = append(r, GenerateTestGaugeFloatHistogram(rand.Intn(n)))
|
||||||
r = append(r, &histogram.FloatHistogram{
|
|
||||||
CounterResetHint: histogram.GaugeType,
|
|
||||||
Count: 10 + float64(i*8),
|
|
||||||
ZeroCount: 2 + float64(i),
|
|
||||||
ZeroThreshold: 0.001,
|
|
||||||
Sum: 18.4 * float64(i+1),
|
|
||||||
Schema: 1,
|
|
||||||
PositiveSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
PositiveBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
|
|
||||||
NegativeSpans: []histogram.Span{
|
|
||||||
{Offset: 0, Length: 2},
|
|
||||||
{Offset: 1, Length: 2},
|
|
||||||
},
|
|
||||||
NegativeBuckets: []float64{float64(i + 1), float64(i + 2), float64(i + 1), float64(i + 1)},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateTestGaugeFloatHistogram(i int) *histogram.FloatHistogram {
|
||||||
|
h := GenerateTestFloatHistogram(i)
|
||||||
|
h.CounterResetHint = histogram.GaugeType
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue