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] Increase metric name maximum length from 63 to 255 characters #2284

Merged
merged 1 commit into from
Aug 31, 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
1 change: 0 additions & 1 deletion sdk/include/opentelemetry/sdk/metrics/meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class Meter final : public opentelemetry::metrics::Meter
std::unique_ptr<AsyncWritableMetricStorage> RegisterAsyncMetricStorage(
InstrumentDescriptor &instrument_descriptor);
opentelemetry::common::SpinLockMutex storage_lock_;
const InstrumentMetaDataValidator instrument_metadata_validator;

static nostd::shared_ptr<opentelemetry::metrics::ObservableInstrument>
GetNoopObservableInsrument()
Expand Down
8 changes: 4 additions & 4 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*62 ("_" / "." / "-" / ALPHA / DIGIT)
const std::string kInstrumentNamePattern = "[a-zA-Z][-_.a-zA-Z0-9]{0,62}";
// 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 All @@ -38,8 +38,8 @@ bool InstrumentMetaDataValidator::ValidateName(nostd::string_view name) const
#if OPENTELEMETRY_HAVE_WORKING_REGEX
return std::regex_match(name.data(), name_reg_key_);
#else
const size_t kMaxSize = 63;
// size atmost 63 chars
const size_t kMaxSize = 255;
// size atmost 255 chars
if (name.size() > kMaxSize)
{
return false;
Expand Down
27 changes: 15 additions & 12 deletions sdk/test/metrics/instrument_metadata_validator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,28 @@ TEST(InstrumentMetadataValidator, TestName)
{
opentelemetry::sdk::metrics::InstrumentMetaDataValidator validator;
std::vector<std::string> invalid_names = {
"", // empty string
"1sdf", // string starting with number
"123€AAA€BBB", // unicode characters
"/\\sdsd", // string starting with special character
"***sSSs", // string starting with special character
CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 charactes
CreateVeryLargeString(7), // string much bigger than 63 chars
"", // empty string
"1sdf", // string starting with number
"123€AAA€BBB", // unicode characters
"/\\sdsd", // string starting with special character
"***sSSs", // string starting with special character
CreateVeryLargeString(25) + "X", // total 256 characters
CreateVeryLargeString(26), // string much bigger than 255 characters
};
for (auto const &str : invalid_names)
{
EXPECT_FALSE(validator.ValidateName(str));
}

std::vector<std::string> valid_names = {
"T", // single char string
"s123", // starting with char, followed by numbers
"dsdsdsd_-.", // string , and valid nonalphanumeric
"d1234_-sDSDs.sdsd344", // combination of all valid characters
CreateVeryLargeString(5) + "ABCERTYG", // total 63 charactes
"T", // single char string
"s123", // starting with char, followed by numbers
"dsdsdsd_-.", // string , and valid nonalphanumeric
"d1234_-sDSDs.sdsd344", // combination of all valid characters
CreateVeryLargeString(5) + "ABCERTYG", // total 63 characters
CreateVeryLargeString(5) + "ABCERTYGJ", // total 64 characters
CreateVeryLargeString(24) + "ABCDEFGHI", // total 254 characters
CreateVeryLargeString(25), // total 255 characters
};
for (auto const &str : valid_names)
{
Expand Down