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

Telemetry processor - Allow multimatch on log body and span name #3229

Merged
merged 7 commits into from
Aug 24, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public static String applyRule(
Matcher matcher = pattern.matcher(name);
StringBuilder sb = new StringBuilder();
int lastEnd = 0;
// As of now we are considering only first match.
if (matcher.find()) {
while (matcher.find()) {
sb.append(name, lastEnd, matcher.start());
int innerLastEnd = matcher.start();
for (int i = 1; i <= groupNamesList.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void multiRuleToAttributesTest() {
LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter);
TestLogRecordData mockLogA =
TestLogRecordData.builder()
.setBody("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz")
.setBody("yyyPassword=123 aba Pass=555 xyx")
jeanbisutti marked this conversation as resolved.
Show resolved Hide resolved
.setAttributes(attributes)
.build();

Expand Down Expand Up @@ -229,7 +229,7 @@ void multiRuleToAttributesTest() {
resultA.getAttributes().get(AttributeKey.stringKey("password2"))))
.isEqualTo("555");
assertThat(resultA.getBody().asString())
.isEqualTo("yyyPassword={password1} aba Pass={password2} xyx Pass=777 zzz");
.isEqualTo("yyyPassword={password1} aba Pass={password2} xyx");
assertThat(
Objects.requireNonNull(
resultB.getAttributes().get(AttributeKey.stringKey("password1"))))
Expand All @@ -241,6 +241,32 @@ void multiRuleToAttributesTest() {
assertThat(resultB.getBody().asString()).isEqualTo("yyyPassword={password1} aba");
}

@Test
void multiMatch() {
config.id = "MultiRuleToAttributes";
config.body = new NameConfig();
ToAttributeConfig toAttributeConfig = new ToAttributeConfig();
toAttributeConfig.rules = new ArrayList<>();
toAttributeConfig.rules.add("Password=(?<x>[^ ]+)");
config.body.toAttributes = toAttributeConfig;
LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter);
TestLogRecordData mockLogA =
TestLogRecordData.builder()
.setBody("yyyPassword=123 aba Password=555 xyx")
.setAttributes(attributes)
.build();

List<LogRecordData> logs = new ArrayList<>();
logs.add(mockLogA);
logExporter.export(logs);

// verify that resulting logs are filtered in the way we want
List<LogRecordData> result = mockExporter.getLogs();
LogRecordData resultA = result.get(0);

assertThat(resultA.getBody().asString()).isEqualTo("yyyPassword={x} aba Password={x} xyx");
}

@Test
void simpleRenameLogTestWithLogProcessor() {
config.id = "SimpleRenameLog";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,9 @@ void multiRuleToAttributesTest() {
assertThat(
Objects.requireNonNull(
resultSpanA.getAttributes().get(AttributeKey.stringKey("password2"))))
.isEqualTo("555");
.isEqualTo("777");
assertThat(resultSpanA.getName())
.isEqualTo("yyyPassword={password1} aba Pass={password2} xyx Pass=777 zzz");
.isEqualTo("yyyPassword={password1} aba Pass={password2} xyx Pass={password2} zzz");
assertThat(
Objects.requireNonNull(
resultSpanB.getAttributes().get(AttributeKey.stringKey("password1"))))
Expand All @@ -383,7 +383,7 @@ void extractAttributesWithIncludeExcludeTest() {
config.exclude.matchType = MatchType.STRICT;
config.exclude.spanNames = Arrays.asList("donot/change");
config.name.toAttributes = new ToAttributeConfig();
config.name.toAttributes.rules = Arrays.asList("(?<operationwebsite>.*?)$");
config.name.toAttributes.rules = Arrays.asList("(?<operationwebsite>.*?)/.*$");
SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter);

Span spanA =
Expand Down Expand Up @@ -439,20 +439,20 @@ void extractAttributesWithIncludeExcludeTest() {
SpanData resultSpanB = result.get(1);
SpanData resultSpanC = result.get(2);
SpanData resultSpanD = result.get(3);
assertThat(resultSpanA.getName()).isEqualTo("{operationwebsite}");
assertThat(resultSpanA.getName()).isEqualTo("{operationwebsite}/test");
assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("operationwebsite")))
.isNotNull();
assertThat(
Objects.requireNonNull(
resultSpanA.getAttributes().get(AttributeKey.stringKey("operationwebsite"))))
.isEqualTo("svcA/test");
assertThat(resultSpanB.getName()).isEqualTo("{operationwebsite}");
.isEqualTo("svcA");
assertThat(resultSpanB.getName()).isEqualTo("{operationwebsite}/test");
assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("operationwebsite")))
.isNotNull();
assertThat(
Objects.requireNonNull(
resultSpanB.getAttributes().get(AttributeKey.stringKey("operationwebsite"))))
.isEqualTo("svcB/test");
.isEqualTo("svcB");
assertThat(resultSpanC.getName()).isEqualTo("svcC");
assertThat(resultSpanD.getName()).isEqualTo("donot/change");
}
Expand Down
Loading