Skip to content

Commit

Permalink
refactor tools: changed check of valid retention and compaction lvls …
Browse files Browse the repository at this point in the history
…to use map

Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
  • Loading branch information
FUSAKLA committed May 28, 2020
1 parent 2dfc46d commit 76810cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
34 changes: 14 additions & 20 deletions pkg/replicate/scheme.go
Expand Up @@ -29,8 +29,8 @@ import (
type BlockFilter struct {
logger log.Logger
labelSelector labels.Selector
resolutionLevels []compact.ResolutionLevel
compactionLevels []int
resolutionLevels map[compact.ResolutionLevel]struct{}
compactionLevels map[int]struct{}
}

// NewBlockFilter returns block filter.
Expand All @@ -40,11 +40,19 @@ func NewBlockFilter(
resolutionLevels []compact.ResolutionLevel,
compactionLevels []int,
) *BlockFilter {
allowedResolutions := make(map[compact.ResolutionLevel]struct{})
for _, resolutionLevel := range resolutionLevels {
allowedResolutions[resolutionLevel] = struct{}{}
}
allowedCompactions := make(map[int]struct{})
for _, compactionLevel := range compactionLevels {
allowedCompactions[compactionLevel] = struct{}{}
}
return &BlockFilter{
labelSelector: labelSelector,
logger: logger,
resolutionLevels: resolutionLevels,
compactionLevels: compactionLevels,
resolutionLevels: allowedResolutions,
compactionLevels: allowedCompactions,
}
}

Expand Down Expand Up @@ -77,27 +85,13 @@ func (bf *BlockFilter) Filter(b *metadata.Meta) bool {
}

gotResolution := compact.ResolutionLevel(b.Thanos.Downsample.Resolution)
resolutionMatch := false
for _, allowedResolution := range bf.resolutionLevels {
if gotResolution == allowedResolution {
resolutionMatch = true
break
}
}
if !resolutionMatch {
if _, ok := bf.resolutionLevels[gotResolution]; !ok {
level.Debug(bf.logger).Log("msg", "filtering block", "reason", "resolution doesn't match allowed resolutions", "got_resolution", gotResolution, "allowed_resolutions", bf.resolutionLevels)
return false
}

gotCompactionLevel := b.BlockMeta.Compaction.Level
compactionMatch := false
for _, allowedCompactionLevel := range bf.compactionLevels {
if gotCompactionLevel == allowedCompactionLevel {
compactionMatch = true
break
}
}
if !compactionMatch {
if _, ok := bf.compactionLevels[gotCompactionLevel]; !ok {
level.Debug(bf.logger).Log("msg", "filtering block", "reason", "compaction level doesn't match allowed levels", "got_compaction_level", gotCompactionLevel, "allowed_compaction_levels", bf.compactionLevels)
return false
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/replicate/scheme_test.go
Expand Up @@ -311,7 +311,7 @@ func TestReplicationSchemeAll(t *testing.T) {
selector = c.selector
}

filter := NewBlockFilter(logger, selector, compact.ResolutionLevelRaw, 1).Filter
filter := NewBlockFilter(logger, selector, []compact.ResolutionLevel{compact.ResolutionLevelRaw}, []int{1}).Filter
fetcher, err := block.NewMetaFetcher(logger, 32, objstore.WithNoopInstr(originBucket), "", nil, nil, nil)
testutil.Ok(t, err)

Expand Down

0 comments on commit 76810cf

Please sign in to comment.