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

[processor/sumologicschema]: allow aggregating attributes with given name patterns #871

Conversation

aboguszewski-sumo
Copy link
Contributor

@aboguszewski-sumo aboguszewski-sumo commented Dec 15, 2022

Updates #866

Done. This is a basic version, which supports only prefixes.

@github-actions github-actions bot added the go label Dec 15, 2022
@aboguszewski-sumo aboguszewski-sumo force-pushed the sumoschema-aggregate-patterns branch 2 times, most recently from e3f56a2 to 0a9adc6 Compare December 19, 2022 12:55
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Dec 19, 2022
@aboguszewski-sumo aboguszewski-sumo force-pushed the sumoschema-aggregate-patterns branch from 0a9adc6 to d3edaff Compare December 19, 2022 12:58
@aboguszewski-sumo aboguszewski-sumo marked this pull request as ready for review December 19, 2022 12:58
@aboguszewski-sumo aboguszewski-sumo requested a review from a team as a code owner December 19, 2022 12:58
Comment on lines 80 to 68

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
}
}
}
}
Copy link
Contributor Author

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.

Comment on lines 52 to 71
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
}
Copy link
Contributor Author

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?

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).

Comment on lines 217 to 145
// 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)
Copy link
Contributor Author

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.

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)

@aboguszewski-sumo aboguszewski-sumo force-pushed the sumoschema-aggregate-patterns branch from d3edaff to a79284d Compare December 19, 2022 13:13
regexes := []*regexp.Regexp{}

for i := 0; i < len(pair.Patterns); i++ {
// We do not support regexes - only wildcards (*). Escape all regex special characters.
Copy link
Contributor

Choose a reason for hiding this comment

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

why not?

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)

Copy link
Contributor Author

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

@aboguszewski-sumo aboguszewski-sumo force-pushed the sumoschema-aggregate-patterns branch 3 times, most recently from 419bfd7 to 95e3f1c Compare December 23, 2022 08:31
@aboguszewski-sumo
Copy link
Contributor Author

PR reworked.
Now only prefixes are supported.

@aboguszewski-sumo aboguszewski-sumo force-pushed the sumoschema-aggregate-patterns branch from 51a384d to c9cfe52 Compare December 23, 2022 09:27
@aboguszewski-sumo aboguszewski-sumo enabled auto-merge (rebase) December 23, 2022 09:30
@aboguszewski-sumo aboguszewski-sumo merged commit 91536ae into SumoLogic:main Dec 23, 2022
@aboguszewski-sumo aboguszewski-sumo deleted the sumoschema-aggregate-patterns branch December 23, 2022 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation go
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants