-
Notifications
You must be signed in to change notification settings - Fork 290
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
Adds resource name matching to the trace sampling rules #5900
Changes from all commits
f286bf3
0000e0e
6beca7f
479f3aa
b08c25a
0602486
c642f50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,11 @@ | |
public final class GlobPattern { | ||
|
||
public static Pattern globToRegexPattern(String globPattern) { | ||
if (globPattern == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed now unnecessary checks in these methods |
||
return null; | ||
} | ||
String regex = globToRegex(globPattern); | ||
if (regex == null) { | ||
return null; | ||
} | ||
return Pattern.compile(regex); | ||
} | ||
|
||
private static String globToRegex(String globPattern) { | ||
if ("*".equals(globPattern)) { | ||
return null; | ||
} | ||
StringBuilder sb = new StringBuilder(64); | ||
sb.append('^'); | ||
for (int i = 0; i < globPattern.length(); i++) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package datadog.trace.core.util; | ||
|
||
public interface Matcher { | ||
public boolean matches(String str); | ||
|
||
public boolean matches(CharSequence charSeq); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package datadog.trace.core.util; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public final class Matchers { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add some unit tests here to codify the edge cases? I don't have many concerns about the correctness of the code, but it would be nice to have our edge cases explicitly defined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are ready for another review |
||
private Matchers() {} | ||
|
||
public static final Matcher compileGlob(String glob) { | ||
if (glob == null || glob.equals("*")) { | ||
bm1549 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// DQH - Decided not to an anyMatcher because that's likely to | ||
// cause our call site to go megamorphic | ||
return null; | ||
} else if (isExact(glob)) { | ||
return new ExactMatcher(glob); | ||
} else { | ||
// DQH - not sure about the error handling here | ||
Pattern pattern = GlobPattern.globToRegexPattern(glob); | ||
return pattern == null ? null : new PatternMatcher(pattern); | ||
} | ||
} | ||
|
||
public static boolean matches(Matcher matcher, String str) { | ||
return (matcher == null) || matcher.matches(str); | ||
} | ||
|
||
public static boolean matches(Matcher matcher, CharSequence charSeq) { | ||
return (matcher == null) || matcher.matches(charSeq); | ||
} | ||
|
||
static boolean isExact(String glob) { | ||
return (glob.indexOf('*') == -1) && (glob.indexOf('?') == -1); | ||
} | ||
|
||
static final class ExactMatcher implements Matcher { | ||
private final String exact; | ||
|
||
ExactMatcher(String exact) { | ||
this.exact = exact; | ||
} | ||
|
||
@Override | ||
public boolean matches(String str) { | ||
return exact.equals(str); | ||
} | ||
|
||
@Override | ||
public boolean matches(CharSequence charSeq) { | ||
return exact.contentEquals(charSeq); | ||
} | ||
} | ||
|
||
static final class PatternMatcher implements Matcher { | ||
private final Pattern pattern; | ||
|
||
PatternMatcher(Pattern pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
@Override | ||
public boolean matches(CharSequence charSeq) { | ||
return pattern.matcher(charSeq).matches(); | ||
} | ||
|
||
@Override | ||
public boolean matches(String str) { | ||
return pattern.matcher(str).matches(); | ||
} | ||
} | ||
} |
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.
Nice clean up!