-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5900 from DataDog/dougqh/resource-sampling
Resource name matching
- Loading branch information
Showing
10 changed files
with
216 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
dd-trace-core/src/main/java/datadog/trace/core/util/Matcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
69 changes: 69 additions & 0 deletions
69
dd-trace-core/src/main/java/datadog/trace/core/util/Matchers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
private Matchers() {} | ||
|
||
public static final Matcher compileGlob(String glob) { | ||
if (glob == null || glob.equals("*")) { | ||
// 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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.