diff options
author | Maxim Yurchuk <maxim-yurchuk@ydb.tech> | 2025-05-21 16:06:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-21 19:06:07 +0300 |
commit | 2e9d17608ab249a797773aa9170ee109bbe92131 (patch) | |
tree | a45624235891f73017d49ec936ce367dc6b9b728 /library/cpp | |
parent | 9ffb002de0fc457af277ed13c0c57e1325eeefe4 (diff) | |
download | ydb-2e9d17608ab249a797773aa9170ee109bbe92131.tar.gz |
Sync main with rightlib (#18558)
Diffstat (limited to 'library/cpp')
4 files changed, 9 insertions, 108 deletions
diff --git a/library/cpp/bucket_quoter/bucket_quoter.h b/library/cpp/bucket_quoter/bucket_quoter.h index ce2d96b65d8..f8396b7b7e6 100644 --- a/library/cpp/bucket_quoter/bucket_quoter.h +++ b/library/cpp/bucket_quoter/bucket_quoter.h @@ -172,8 +172,8 @@ public: i64 UseAndFill(ui64 tokens) { TGuard<Lock> g(BucketMutex); - FillBucket(); UseNoLock(tokens); + FillBucket(); return Bucket; } diff --git a/library/cpp/lwtrace/mon/mon_lwtrace.cpp b/library/cpp/lwtrace/mon/mon_lwtrace.cpp index 2593845e487..09d56560c4b 100644 --- a/library/cpp/lwtrace/mon/mon_lwtrace.cpp +++ b/library/cpp/lwtrace/mon/mon_lwtrace.cpp @@ -301,7 +301,7 @@ public: } } catch (...) { ythrow yexception() - << EncodeHtmlPcdata(CurrentExceptionMessage()) + << CurrentExceptionMessage() << " while parsing track log query: " << Text; } @@ -1853,7 +1853,7 @@ public: try { Os << src->GetStartTime().ToStringUpToSeconds(); } catch (...) { - Os << "error: " << EncodeHtmlPcdata(CurrentExceptionMessage()); + Os << "error: " << CurrentExceptionMessage(); } Os << "</td>" << "<td><div class=\"dropdown\">" @@ -3827,11 +3827,11 @@ public: if (request.GetParams().Get("error") == "text") { // Text error reply is helpful for ajax requests out << NMonitoring::HTTPOKTEXT; - out << EncodeHtmlPcdata(CurrentExceptionMessage()); + out << CurrentExceptionMessage(); } else { WWW_HTML(out) { out << "<h2>Error</h2><pre>" - << EncodeHtmlPcdata(CurrentExceptionMessage()) + << CurrentExceptionMessage() << Endl; } } diff --git a/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp b/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp index 0c6c23c466c..66c0f55b436 100644 --- a/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp +++ b/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp @@ -109,11 +109,13 @@ namespace NMonitoring { Y_ENSURE(!name.empty(), "trying to write metric with empty name"); char ch = name[0]; - if (!NPrometheus::IsValidMetricNameStart(ch)) { + if (NPrometheus::IsValidMetricNameStart(ch)) { + Out_->Write(ch); + } else { Out_->Write('_'); } - for (size_t i = 0, len = name.length(); i < len; i++) { + for (size_t i = 1, len = name.length(); i < len; i++) { ch = name[i]; if (NPrometheus::IsValidMetricNameContinuation(ch)) { Out_->Write(ch); diff --git a/library/cpp/monlib/encode/prometheus/prometheus_encoder_ut.cpp b/library/cpp/monlib/encode/prometheus/prometheus_encoder_ut.cpp index fe4bbcaf0a1..fd9debb060e 100644 --- a/library/cpp/monlib/encode/prometheus/prometheus_encoder_ut.cpp +++ b/library/cpp/monlib/encode/prometheus/prometheus_encoder_ut.cpp @@ -411,105 +411,4 @@ two{labels="l2", project="solomon", } 42 1500000000000 )"); } - - Y_UNIT_TEST(FirstCharacterShouldNotBeReplaced) { - auto result = EncodeToString([](IMetricEncoder* e) { - e->OnStreamBegin(); - const TVector<std::pair<TString, double>> sensors = { - {"0", 0.0}, - {"50", 50.0}, - {"90", 90.0}, - {"99", 99.0}, - {"100", 100}, - {"012345", 123.45}, - {"abc0123", 123.0}, - {"0123abc", 123.0}, - }; - - for (const auto& [name, value]: sensors) { - e->OnMetricBegin(EMetricType::COUNTER); - { - e->OnLabelsBegin(); - e->OnLabel("sensor", name); - e->OnLabelsEnd(); - } - e->OnDouble(TInstant::Zero(), value); - e->OnMetricEnd(); - } - e->OnStreamEnd(); - }); - - UNIT_ASSERT_STRINGS_EQUAL(result, -R"(# TYPE _0 counter -_0 0 -# TYPE _50 counter -_50 50 -# TYPE _90 counter -_90 90 -# TYPE _99 counter -_99 99 -# TYPE _100 counter -_100 100 -# TYPE _012345 counter -_012345 123.45 -# TYPE abc0123 counter -abc0123 123 -# TYPE _0123abc counter -_0123abc 123 - -)"); - } - - Y_UNIT_TEST(InvalidCharactersShouldBeReplaced) { - auto result = EncodeToString([](IMetricEncoder* e) { - e->OnStreamBegin(); - const TVector<std::pair<TString, double>> sensors = { - {"abc/def", 1.0}, - {"a+-*/=&{}()|bc", 0.1}, - {"0.0", 0.0}, - {"99.9", 99.9}}; - - for (const auto& [name, value]: sensors) { - e->OnMetricBegin(EMetricType::COUNTER); - { - e->OnLabelsBegin(); - e->OnLabel("sensor", name); - e->OnLabelsEnd(); - } - e->OnDouble(TInstant::Zero(), value); - e->OnMetricEnd(); - } - e->OnStreamEnd(); - }); - - UNIT_ASSERT_STRINGS_EQUAL(result, -R"(# TYPE abc_def counter -abc_def 1 -# TYPE a___________bc counter -a___________bc 0.1 -# TYPE _0_0 counter -_0_0 0 -# TYPE _99_9 counter -_99_9 99.9 - -)"); - } - - Y_UNIT_TEST(ShouldNotFailOnMetricWithoutSensorLabel) { - auto result = EncodeToString([](IMetricEncoder* e) { - e->OnStreamBegin(); - e->OnStreamEnd(); - { - e->OnMetricBegin(EMetricType::GAUGE); - { - e->OnLabelsBegin(); - e->OnLabel("name", "cpuUsage"); - e->OnLabelsEnd(); - } - e->OnInt64(TInstant::Zero(), 0); - e->OnMetricEnd(); - } - }); - UNIT_ASSERT_STRINGS_EQUAL(result, "\n"); - } } |