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

Add IncludeTags to R2 Rollup Options #4270

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
5 changes: 4 additions & 1 deletion src/metrics/filters/tags_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ type TagsFilterOptions struct {
// Name of the name tag.
NameTagKey []byte

// Function to extract name and tags from an id.
// Name of tags to automatically include in the rollup metric, if seen in the original metric.
IncludeTagKeys map[uint64]struct{}

//Function to extract name and tags from an id.
NameAndTagsFn id.NameAndTagsFn

// Function to create a new sorted tag iterator from id tags.
Expand Down
13 changes: 13 additions & 0 deletions src/metrics/matcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"github.com/m3db/m3/src/x/clock"
"github.com/m3db/m3/src/x/instrument"
"github.com/m3db/m3/src/x/pool"

murmur3 "github.com/m3db/stackmurmur3/v2"
)

// Configuration is config used to create a Matcher.
Expand All @@ -46,6 +48,7 @@ type Configuration struct {
NamespaceTag string `yaml:"namespaceTag" validate:"nonzero"`
DefaultNamespace string `yaml:"defaultNamespace" validate:"nonzero"`
NameTagKey string `yaml:"nameTagKey" validate:"nonzero"`
IncludeTagKeys []string `yaml:"includeTagKeys"`
MatchRangePast *time.Duration `yaml:"matchRangePast"`
SortedTagIteratorPool pool.ObjectPoolConfiguration `yaml:"sortedTagIteratorPool"`
}
Expand Down Expand Up @@ -111,6 +114,7 @@ func (cfg *Configuration) NewOptions(
}
tagsFilterOptions := filters.TagsFilterOptions{
NameTagKey: []byte(cfg.NameTagKey),
IncludeTagKeys: createIncludeTagKeysMap(cfg.IncludeTagKeys),
NameAndTagsFn: m3.NameAndTags,
SortedTagIteratorFn: sortedTagIteratorFn,
}
Expand Down Expand Up @@ -147,3 +151,12 @@ func (cfg *Configuration) NewOptions(

return opts, nil
}

func createIncludeTagKeysMap(includeTagKeys []string) map[uint64]struct{} {
includeTagKeysMap := make(map[uint64]struct{}, len(includeTagKeys))
for _, includeTagKey := range includeTagKeys {
hashKey := murmur3.Sum64([]byte(includeTagKey))
includeTagKeysMap[hashKey] = struct{}{}
}
return includeTagKeysMap
}
27 changes: 21 additions & 6 deletions src/metrics/rules/active_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"github.com/m3db/m3/src/metrics/rules/view"
"github.com/m3db/m3/src/query/models"
xerrors "github.com/m3db/m3/src/x/errors"

murmur3 "github.com/m3db/stackmurmur3/v2"
)

type activeRuleSet struct {
Expand Down Expand Up @@ -522,11 +524,12 @@ func (as *activeRuleSet) matchRollupTarget(
}

var (
rollupTags = rollupOp.Tags
sortedTagIter = matchOpts.SortedTagIteratorFn(sortedTagPairBytes)
matchTagIdx = 0
nameTagName = as.tagsFilterOpts.NameTagKey
nameTagValue []byte
rollupTags = rollupOp.Tags
sortedTagIter = matchOpts.SortedTagIteratorFn(sortedTagPairBytes)
matchTagIdx = 0
nameTagName = as.tagsFilterOpts.NameTagKey
nameTagValue []byte
includeTagNames = as.tagsFilterOpts.IncludeTagKeys
kentzeng12 marked this conversation as resolved.
Show resolved Hide resolved
)

switch rollupOp.Type {
Expand All @@ -543,9 +546,15 @@ func (as *activeRuleSet) matchRollupTarget(
nameTagValue = tagVal
}

// If we've matched all tags, no need to process.
_, matchedIncludeTag := includeTagNames[murmur3.Sum64(tagName)]

// If we've matched all tags, no need to process the rollup rules.
// We don't break out of the for loop, because we may still need to find the name tag.
// We also still need to add any remaining include tags.
if matchTagIdx >= len(rollupTags) {
if targetOpts.generateRollupID && matchedIncludeTag {
tagPairs = append(tagPairs, metricid.TagPair{Name: tagName, Value: tagVal})
}
continue
}

Expand All @@ -559,6 +568,12 @@ func (as *activeRuleSet) matchRollupTarget(
continue
}

// The current tag didn't match the rollup tag, but we still want to add the include tag to the rollup id.
if targetOpts.generateRollupID && matchedIncludeTag {
tagPairs = append(tagPairs, metricid.TagPair{Name: tagName, Value: tagVal})
continue
}

// If one of the target tags is not found in the ID, this is considered a non-match so return immediately.
if res > 0 {
return nil, false, nil
Expand Down
Loading