-
Notifications
You must be signed in to change notification settings - Fork 39
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
[processor/sumologicschema]: allow aggregating attributes with given name patterns #871
[processor/sumologicschema]: allow aggregating attributes with given name patterns #871
Conversation
e3f56a2
to
0a9adc6
Compare
0a9adc6
to
d3edaff
Compare
|
||
for j := 0; j < resourceLogs.ScopeLogs().Len(); j++ { | ||
scopeLogs := resourceLogs.ScopeLogs().At(j) | ||
for k := 0; k < scopeLogs.LogRecords().Len(); k++ { | ||
err := proc.aggregateAttributes(scopeLogs.LogRecords().At(k).Attributes()) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk what is the exact purpose for this feature, but maybe by default we can only modify resource attributes and log/metric/span-level attributes should be configurable.
func pairToAggregation(pair *aggregationPair) (*aggregation, error) { | ||
regexes := []*regexp.Regexp{} | ||
|
||
for i := 0; i < len(pair.Patterns); i++ { | ||
// We do not support regexes - only wildcards (*). Escape all regex special characters. | ||
regexStr := regexp.QuoteMeta(pair.Patterns[i]) | ||
|
||
// Replace all wildcards (after escaping they are "\*") with grouped regex wildcard ("(.*)") | ||
regexStrWithWildcard := strings.Replace(regexStr, "\\*", "(.*)", -1) | ||
|
||
regex, err := regexp.Compile(regexStrWithWildcard) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
regexes = append(regexes, regex) | ||
} | ||
|
||
return &aggregation{attribute: pair.Attribute, patternRegexes: regexes}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not check for exact matches, for example if user specifies pattern pod_*
, we will match strings like opod_123
. We should probably discard that, shouldn't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should check for exact matches. Also see my comment here: #866 (comment).
// Join all substrings caught by wildcards into one string, | ||
// this string will be the name of this key in the new map. | ||
// TODO: Potential name conflict to resolve, eg.: | ||
// pod_*_bar_* matches pod_foo_bar_baz | ||
// pod2_*_bar_* matches pod2_foo_bar_baz | ||
// both will be renamed to foo_baz | ||
name := strings.Join(match[1:], "_") | ||
names = append(names, name) | ||
val := pcommon.NewValueEmpty() | ||
value.CopyTo(val) | ||
attrs = append(attrs, val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the comment. This seems to be a general problem with naming, which I'm not sure how to solve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment here: #866 (comment)
d3edaff
to
a79284d
Compare
regexes := []*regexp.Regexp{} | ||
|
||
for i := 0; i < len(pair.Patterns); i++ { | ||
// We do not support regexes - only wildcards (*). Escape all regex special characters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either support regexes and require a named capture group, or only support prefixes. See: #866 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a problem with naming in that case. But yes, now that I think about it, we can just force the user to specify at least one capture group
419bfd7
to
95e3f1c
Compare
PR reworked. |
95e3f1c
to
51a384d
Compare
51a384d
to
c9cfe52
Compare
Updates #866
Done. This is a basic version, which supports only prefixes.