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

[SDK] Allow metric instrument names to contain / characters #2310

Merged
merged 2 commits into from
Sep 14, 2023
Merged
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
12 changes: 7 additions & 5 deletions sdk/src/metrics/instrument_metadata_validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace sdk
{
namespace metrics
{
// instrument-name = ALPHA 0*254 ("_" / "." / "-" / ALPHA / DIGIT)
const std::string kInstrumentNamePattern = "[a-zA-Z][-_.a-zA-Z0-9]{0,254}";
// instrument-name = ALPHA 0*254 ("_" / "." / "-" / "/" / ALPHA / DIGIT)
const std::string kInstrumentNamePattern = "[a-zA-Z][-_./a-zA-Z0-9]{0,254}";
//
const std::string kInstrumentUnitPattern = "[\x01-\x7F]{0,63}";
// instrument-unit = It can have a maximum length of 63 ASCII chars
Expand Down Expand Up @@ -49,9 +49,11 @@ bool InstrumentMetaDataValidator::ValidateName(nostd::string_view name) const
{
return false;
}
// subsequent chars should be either of alphabets, digits, underscore, minus, dot
return !std::any_of(std::next(name.begin()), name.end(),
[](char c) { return !isalnum(c) && c != '-' && c != '_' && c != '.'; });
// subsequent chars should be either of alphabets, digits, underscore,
// minus, dot, slash
return !std::any_of(std::next(name.begin()), name.end(), [](char c) {
return !isalnum(c) && (c != '-') && (c != '_') && (c != '.') && (c != '/');
});
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions sdk/test/metrics/instrument_metadata_validator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ TEST(InstrumentMetadataValidator, TestName)
"123€AAA€BBB", // unicode characters
"/\\sdsd", // string starting with special character
"***sSSs", // string starting with special character
"a\\broken\\path", // contains backward slash
CreateVeryLargeString(25) + "X", // total 256 characters
CreateVeryLargeString(26), // string much bigger than 255 characters
};
Expand All @@ -37,6 +38,7 @@ TEST(InstrumentMetadataValidator, TestName)
"s123", // starting with char, followed by numbers
"dsdsdsd_-.", // string , and valid nonalphanumeric
"d1234_-sDSDs.sdsd344", // combination of all valid characters
"a/path/to/some/metric", // contains forward slash
CreateVeryLargeString(5) + "ABCERTYG", // total 63 characters
CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 characters
CreateVeryLargeString(24) + "ABCDEFGHI", // total 254 characters
Expand Down