Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,45 @@
package datadog.trace.core.tagprocessor;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;

import datadog.query.QueryObfuscator;

@Fork(2)
@Warmup(iterations=2)
@Measurement(iterations=3)
@Threads(8)
public class QueryObfuscatorBenchmark {
static final QueryObfuscator obfuscator = new QueryObfuscator(null);

static final String NO_REDACT = "foo=bar";
static final String SIMPLE_REDACT = "app_key=1111";
static final String LARGE_REDACT = repeat("app_key=1111&application_key=2222&token=0894-4832", '&', 4096);

static final String repeat(String repeat, char separator, int length) {
StringBuilder builder = new StringBuilder(length);
builder.append(repeat);
while ( builder.length() + repeat.length() + 1 < length ) {
builder.append(separator).append(repeat);
}
return builder.toString();
}

@Benchmark
public String noRedact() {
return obfuscator.obfuscate(NO_REDACT);
}

@Benchmark
public String simpleRedact() {
return obfuscator.obfuscate(SIMPLE_REDACT);
}

@Benchmark
public String largeRedact() {
return obfuscator.obfuscate(LARGE_REDACT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public QueryObfuscator(String regex) {

private String obfuscate(String query) {
if (pattern != null) {
Matcher matcher = pattern.matcher(query);
while (matcher.find()) {
query = Strings.replace(query, matcher.group(), "<redacted>");
}
java.util.regex.Matcher matcher = pattern.matcher(query);
return matcher.replaceAll("<redacted>");
Comment on lines +52 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Nice, but how about to put a comment here that we are using JUL matcher, not Google one for performance reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was actually a mistake, my IDE didn't pick up RE2 and auto-completed the wrong thing. Now, I need to double check everything. Ugh, that's what I get for rushing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might just scrap this PR, since I now have a better solution nearly ready to go.

}
return query;
}
Expand Down
Loading