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

optimize selector to string #6076

Merged
merged 1 commit into from
Jan 31, 2023
Merged
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
18 changes: 4 additions & 14 deletions pkg/replicate/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import (
"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/compact"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/store/storepb"
)

// BlockFilter is block filter that filters out compacted and unselected blocks.
type BlockFilter struct {
logger log.Logger
labelSelector labels.Selector
labelSelectorStr string
resolutionLevels map[compact.ResolutionLevel]struct{}
compactionLevels map[int]struct{}
blockIDs []ulid.ULID
Expand All @@ -55,6 +57,7 @@ func NewBlockFilter(

return &BlockFilter{
labelSelector: labelSelector,
labelSelectorStr: storepb.PromMatchersToString(labelSelector...),
logger: logger,
resolutionLevels: allowedResolutions,
compactionLevels: allowedCompactions,
Expand Down Expand Up @@ -83,20 +86,7 @@ func (bf *BlockFilter) Filter(b *metadata.Meta) bool {

labelMatch := bf.labelSelector.Matches(blockLabels)
if !labelMatch {
selStr := "{"

for i, m := range bf.labelSelector {
if i != 0 {
selStr += ","
}

selStr += m.String()
}

selStr += "}"

level.Debug(bf.logger).Log("msg", "filtering block", "reason", "labels don't match", "block_labels", blockLabels.String(), "selector", selStr)

level.Debug(bf.logger).Log("msg", "filtering block", "reason", "labels don't match", "block_labels", blockLabels.String(), "selector", bf.labelSelectorStr)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding A comment ,where it describes that if the labelMatch value is 'False' we return False can be helpful

Also , can't we return the labelMatch itself?? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code you quoted says"labels don't match".

It's not readable to return the labelMatch directly because the matcher type is an enum, not a string.

return false
}

Expand Down