-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* undo non-test related removals from #218 * fix bug * add additional "sample" test * clang-format * glob.{h,cpp} * class SpanSampler, without using or testing it * small (premature?) optimization * TODO: AMEND * checkpoint: added span rules to Tracer, but not elsewhere * checkpoint: add span rules to SpanBuffer, but don't use them * checkpoint: written but untested * test rule parsing * obnoxious compiler * test rule matching * test span sampling * clang-format * test environment variables * repo-level documentation * attempt at fixing doc links * describe glob in the repo-level docs * unit tests catch bugs! * a little const correctness * code comment typo * temporary files are temporary * review: trim some docs and add an example * review: describe globs more concretely * review: make a future diff smaller
- Loading branch information
Showing
23 changed files
with
1,253 additions
and
38 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
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,59 @@ | ||
#include "glob.h" | ||
|
||
#include <cstdint> | ||
|
||
namespace datadog { | ||
namespace opentracing { | ||
|
||
bool glob_match(ot::string_view pattern, ot::string_view subject) { | ||
// This is a backtracking implementation of the glob matching algorithm. | ||
// The glob pattern language supports `*` and `?`, but no escape sequences. | ||
// | ||
// Based off of a Go example in <https://research.swtch.com/glob> accessed | ||
// February 3, 2022. | ||
|
||
using Index = std::size_t; | ||
Index p = 0; // [p]attern index | ||
Index s = 0; // [s]ubject index | ||
Index next_p = 0; // next [p]attern index | ||
Index next_s = 0; // next [s]ubject index | ||
|
||
while (p < pattern.size() || s < subject.size()) { | ||
if (p < pattern.size()) { | ||
const char pattern_char = pattern[p]; | ||
switch (pattern_char) { | ||
case '*': | ||
// Try to match at `s`. If that doesn't work out, restart at | ||
// `s + 1` next. | ||
next_p = p; | ||
next_s = s + 1; | ||
++p; | ||
continue; | ||
case '?': | ||
if (s < subject.size()) { | ||
++p; | ||
++s; | ||
continue; | ||
} | ||
break; | ||
default: | ||
if (s < subject.size() && subject[s] == pattern_char) { | ||
++p; | ||
++s; | ||
continue; | ||
} | ||
} | ||
} | ||
// Mismatch. Maybe restart. | ||
if (0 < next_s && next_s <= subject.size()) { | ||
p = next_p; | ||
s = next_s; | ||
continue; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace opentracing | ||
} // namespace datadog |
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,30 @@ | ||
#ifndef DD_OPENTRACING_GLOB_H | ||
#define DD_OPENTRACING_GLOB_H | ||
|
||
// This component provides a string matching function, `glob_match`, that | ||
// returns whether a specified string matches a specified pattern, where the | ||
// pattern language is the following: | ||
// | ||
// - "*" matches any contiguous substring, including the empty string. | ||
// - "?" matches exactly one instance of any character. | ||
// - Other characters match exactly one instance of themselves. | ||
// | ||
// The patterns are here called "glob patterns," though they are different from | ||
// the patterns used in Unix shells. | ||
|
||
#include <opentracing/string_view.h> | ||
|
||
namespace ot = opentracing; | ||
|
||
namespace datadog { | ||
namespace opentracing { | ||
|
||
// Return whether the specified `subject` matches the specified glob `pattern`, | ||
// i.e. whether `subject` is a member of the set of strings represented by the | ||
// glob `pattern`. | ||
bool glob_match(ot::string_view pattern, ot::string_view subject); | ||
|
||
} // namespace opentracing | ||
} // namespace datadog | ||
|
||
#endif |
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.