From cfa4ea53cc6a7355aedef68529bf80a81bed850b Mon Sep 17 00:00:00 2001 From: fayzal-g Date: Tue, 17 Jan 2023 15:42:19 +0000 Subject: [PATCH 1/3] Correctly update chunksRemoved and chunks metrics Signed-off-by: fayzal-g --- tsdb/head_wal.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tsdb/head_wal.go b/tsdb/head_wal.go index 708541364..f2ef4c1e0 100644 --- a/tsdb/head_wal.go +++ b/tsdb/head_wal.go @@ -498,6 +498,12 @@ func (h *Head) resetSeriesWithMMappedChunks(mSeries *memSeries, mmc, oooMmc []*m h.metrics.chunksCreated.Add(float64(len(mmc) + len(oooMmc))) h.metrics.chunksRemoved.Add(float64(len(mSeries.mmappedChunks))) h.metrics.chunks.Add(float64(len(mmc) + len(oooMmc) - len(mSeries.mmappedChunks))) + + if mSeries.ooo != nil { + h.metrics.chunksRemoved.Add(float64(len(mSeries.ooo.oooMmappedChunks))) + h.metrics.chunks.Sub(float64(len(mSeries.ooo.oooMmappedChunks))) + } + mSeries.mmappedChunks = mmc if len(oooMmc) == 0 { mSeries.ooo = nil From e023d896f2d79b1a48bbd345429c6b496cf46cc8 Mon Sep 17 00:00:00 2001 From: Charles Korn Date: Tue, 31 Jan 2023 19:04:17 +1100 Subject: [PATCH 2/3] Correct statement in docs about query results returning either floats or histograms but not both. (#11880) * Correct statement in docs about query results returning either floats or histograms but not both. * Move documentation for range and instant vectors under their corresponding headings. Signed-off-by: Charles Korn --- docs/querying/api.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/querying/api.md b/docs/querying/api.md index 53d12052c..f2182a205 100644 --- a/docs/querying/api.md +++ b/docs/querying/api.md @@ -449,9 +449,7 @@ raw numbers. The keys `"histogram"` and `"histograms"` only show up if the experimental native histograms are present in the response. Their placeholder `` -is explained in detail in its own section below. Any one object will only have -the `"value"`/`"values"` key or the `"histogram"`/`"histograms"` key, but not -both. +is explained in detail in its own section below. ### Range vectors @@ -469,6 +467,9 @@ Range vectors are returned as result type `matrix`. The corresponding ] ``` +Each series could have the `"values"` key, or the `"histograms"` key, or both. +For a given timestamp, there will only be one sample of either float or histogram type. + ### Instant vectors Instant vectors are returned as result type `vector`. The corresponding @@ -485,6 +486,8 @@ Instant vectors are returned as result type `vector`. The corresponding ] ``` +Each series could have the `"value"` key, or the `"histogram"` key, but not both. + ### Scalars Scalar results are returned as result type `scalar`. The corresponding From 1f0cc09579b7d04bbcb2b9746b7040da55791d48 Mon Sep 17 00:00:00 2001 From: George Krajcsovits Date: Wed, 1 Feb 2023 11:53:38 +0100 Subject: [PATCH 3/3] Export single ith test histogram generation functions (#11911) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Export single ith test histogram generation functions Signed-off-by: György Krajcsovits * Do not set counter reset hint for non-gauge histograms individually Signed-off-by: György Krajcsovits * Apply suggestions from code review Co-authored-by: Ganesh Vernekar Signed-off-by: George Krajcsovits --------- Signed-off-by: György Krajcsovits Signed-off-by: George Krajcsovits Co-authored-by: Ganesh Vernekar --- tsdb/head.go | 136 +++++++++++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 76 deletions(-) diff --git a/tsdb/head.go b/tsdb/head.go index 1ef88be36..728b3c9d3 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -2040,106 +2040,90 @@ func (h *Head) updateWALReplayStatusRead(current int) { func GenerateTestHistograms(n int) (r []*histogram.Histogram) { for i := 0; i < n; i++ { - h := 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}, - } + h := GenerateTestHistogram(i) if i > 0 { h.CounterResetHint = histogram.NotCounterReset } - r = append(r, &h) + r = append(r, h) } 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) { for x := 0; x < n; x++ { - i := 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}, - }) + r = append(r, GenerateTestGaugeHistogram(rand.Intn(n))) } return r } +func GenerateTestGaugeHistogram(i int) *histogram.Histogram { + h := GenerateTestHistogram(i) + h.CounterResetHint = histogram.GaugeType + return h +} + func GenerateTestFloatHistograms(n int) (r []*histogram.FloatHistogram) { for i := 0; i < n; i++ { - h := 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)}, - } + h := GenerateTestFloatHistogram(i) if i > 0 { h.CounterResetHint = histogram.NotCounterReset } - r = append(r, &h) + r = append(r, h) } - 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) { for x := 0; x < n; x++ { - i := 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)}, - }) + r = append(r, GenerateTestGaugeFloatHistogram(rand.Intn(n))) } - return r } + +func GenerateTestGaugeFloatHistogram(i int) *histogram.FloatHistogram { + h := GenerateTestFloatHistogram(i) + h.CounterResetHint = histogram.GaugeType + return h +}