Skip to content

Commit

Permalink
[SDK] Increase metric name maximum length from 63 to 255 characters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Aug 31, 2023
1 parent 7196ec3 commit f52ec6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
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

1 comment on commit f52ec6c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: f52ec6c Previous: 7196ec3 Ratio
BM_BaselineBuffer/2 10700979.232788086 ns/iter 3273980.8559417725 ns/iter 3.27
BM_LockFreeBuffer/2 4130812.9017798817 ns/iter 1335993.0515289307 ns/iter 3.09

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.