Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query: Make group a/b minPenalty to be configurable #8061

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions pkg/dedup/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package dedup

import (
"math"
"os"
"strconv"

"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/model/labels"
Expand All @@ -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
Expand Down Expand Up @@ -318,15 +336,15 @@ 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
}
if it.bval == chunkenc.ValNone {
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
Expand All @@ -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

Expand All @@ -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
Expand Down
Loading