From 2f42763052598963629636553b67bed63d55bfa5 Mon Sep 17 00:00:00 2001 From: Magiceses Date: Fri, 17 Jan 2025 13:55:24 +0800 Subject: [PATCH] Make group a/b minPenalty to be configurable Change-Id: If991daccf49d03cc116a7e0413e023ea4cb45643 Signed-off-by: Magiceses --- pkg/dedup/iter.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/dedup/iter.go b/pkg/dedup/iter.go index e3b3fe8f0f..0cf4133b9d 100644 --- a/pkg/dedup/iter.go +++ b/pkg/dedup/iter.go @@ -5,6 +5,8 @@ package dedup import ( "math" + "os" + "strconv" "github.com/prometheus/prometheus/model/histogram" "github.com/prometheus/prometheus/model/labels" @@ -15,6 +17,22 @@ import ( "github.com/thanos-io/thanos/pkg/store/storepb" ) +var minPenalty int64 + +func init() { + var err error + // Enable minPenalty for deduplication if the environment variable is set. + minPenaltyEnv, existing := os.LookupEnv("THANOS_MIN_DEDUP_PENALTY") + if !existing { + minPenaltyEnv = "0" + } + + minPenalty, err = strconv.ParseInt(minPenaltyEnv, 10, 0) + if err != nil || minPenalty < 0 { + minPenalty = 0 + } +} + type dedupSeriesSet struct { set storage.SeriesSet isCounter bool @@ -318,7 +336,7 @@ func (it *dedupSeriesIterator) Next() chunkenc.ValueType { if it.bval != chunkenc.ValNone { it.lastT = it.b.AtT() it.lastIter = it.b - it.penB = 0 + it.penB = minPenalty } return it.bval } @@ -326,7 +344,7 @@ func (it *dedupSeriesIterator) Next() chunkenc.ValueType { it.useA = true it.lastT = it.a.AtT() it.lastIter = it.a - it.penA = 0 + it.penA = minPenalty return it.aval } // General case where both iterators still have data. We pick the one @@ -353,7 +371,7 @@ func (it *dedupSeriesIterator) Next() chunkenc.ValueType { } else { it.penB = initialPenalty } - it.penA = 0 + it.penA = minPenalty it.lastT = ta it.lastIter = it.a @@ -364,7 +382,7 @@ func (it *dedupSeriesIterator) Next() chunkenc.ValueType { } else { it.penA = initialPenalty } - it.penB = 0 + it.penB = minPenalty it.lastT = tb it.lastIter = it.b return it.bval