Skip to content

Commit

Permalink
[WIP] Add optional tag slice to matching config
Browse files Browse the repository at this point in the history
  • Loading branch information
kentzeng12 committed May 28, 2024
1 parent 75a402a commit 3c57ffe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
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 include in rollup ID if seen in metric ID
IncludeTagKeys [][]byte

//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
6 changes: 6 additions & 0 deletions src/metrics/matcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 @@ -114,6 +115,11 @@ func (cfg *Configuration) NewOptions(
NameAndTagsFn: m3.NameAndTags,
SortedTagIteratorFn: sortedTagIteratorFn,
}
includeTagKeys := make([][]byte, 0, len(cfg.IncludeTagKeys))
for i, includeTagKey := range cfg.IncludeTagKeys {
includeTagKeys[i] = []byte(includeTagKey)
}
tagsFilterOptions.IncludeTagKeys = includeTagKeys

isRollupIDFn := func(name []byte, tags []byte) bool {
return m3.IsRollupID(name, tags, sortedTagIteratorPool)
Expand Down
19 changes: 14 additions & 5 deletions src/metrics/rules/active_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,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
)

switch rollupOp.Type {
Expand All @@ -535,6 +536,7 @@ func (as *activeRuleSet) matchRollupTarget(
//
// For include rules, every rule has to have a corresponding match. This means we return
// early whenever there's a missing match and increment matchRuleIdx whenever there is a match.
TagIteration:
for hasMoreTags := sortedTagIter.Next(); hasMoreTags; hasMoreTags = sortedTagIter.Next() {
tagName, tagVal := sortedTagIter.Current()
// nolint:gosimple
Expand All @@ -559,6 +561,13 @@ func (as *activeRuleSet) matchRollupTarget(
continue
}

for _, includeTagName := range includeTagNames {
if bytes.Compare(tagName, includeTagName) == 0 && targetOpts.generateRollupID {
tagPairs = append(tagPairs, metricid.TagPair{Name: tagName, Value: tagVal})
continue TagIteration
}
}

// 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

0 comments on commit 3c57ffe

Please sign in to comment.