diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-02 17:05:42 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-02 17:05:42 +0300 |
commit | b93c9c23c9b51d4a1bfd26a5b400186315e89976 (patch) | |
tree | 093f23b182af1176526148dae1fb5abc5e008194 /library/cpp/monlib/encode | |
parent | c768b09694655b942cfd5bc66db6c8c2ece24f75 (diff) | |
download | ydb-b93c9c23c9b51d4a1bfd26a5b400186315e89976.tar.gz |
intermediate changes
ref:8868513666cce733c1c659c7f2d683ffab1150dd
Diffstat (limited to 'library/cpp/monlib/encode')
-rw-r--r-- | library/cpp/monlib/encode/buffered/string_pool.h | 8 | ||||
-rw-r--r-- | library/cpp/monlib/encode/format.cpp | 2 | ||||
-rw-r--r-- | library/cpp/monlib/encode/format_ut.cpp | 4 | ||||
-rw-r--r-- | library/cpp/monlib/encode/prometheus/CMakeLists.txt | 1 | ||||
-rw-r--r-- | library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp | 14 |
5 files changed, 26 insertions, 3 deletions
diff --git a/library/cpp/monlib/encode/buffered/string_pool.h b/library/cpp/monlib/encode/buffered/string_pool.h index 7630cee353..b7ab01d2a1 100644 --- a/library/cpp/monlib/encode/buffered/string_pool.h +++ b/library/cpp/monlib/encode/buffered/string_pool.h @@ -33,7 +33,10 @@ namespace NMonitoring { TStringPoolBuilder& Build(); TStringBuf Get(ui32 index) const { - Y_ENSURE(IsBuilt_, "Pool must be sorted first"); + if (RequiresSorting_) { + Y_ENSURE(IsBuilt_, "Pool must be sorted first"); + } + return StrVector_.at(index).first; } @@ -43,7 +46,8 @@ namespace NMonitoring { template <typename TConsumer> void ForEach(TConsumer&& c) { - Y_ENSURE(IsBuilt_, "Pool must be sorted first"); + Y_ENSURE(IsBuilt_, "Pool must be built first"); + for (const auto& value : StrVector_) { c(value.first, value.second->Index, value.second->Frequency); } diff --git a/library/cpp/monlib/encode/format.cpp b/library/cpp/monlib/encode/format.cpp index 400ce5a643..3a7f8f6dee 100644 --- a/library/cpp/monlib/encode/format.cpp +++ b/library/cpp/monlib/encode/format.cpp @@ -49,7 +49,7 @@ namespace NMonitoring { EFormat result{EFormat::UNKNOWN}; for (const auto& it : StringSplitter(value).Split(',').SkipEmpty()) { - TStringBuf token = StripString(it.Token()); + TStringBuf token = StripString(it.Token()).Before(';'); result = FormatFromHttpMedia(token); if (result != EFormat::UNKNOWN) { diff --git a/library/cpp/monlib/encode/format_ut.cpp b/library/cpp/monlib/encode/format_ut.cpp index 22a0e30c03..644a36ee53 100644 --- a/library/cpp/monlib/encode/format_ut.cpp +++ b/library/cpp/monlib/encode/format_ut.cpp @@ -61,6 +61,10 @@ Y_UNIT_TEST_SUITE(TFormatTest) { UNIT_ASSERT_EQUAL( FormatFromAcceptHeader("text/plain"), EFormat::PROMETHEUS); + + UNIT_ASSERT_EQUAL( + FormatFromAcceptHeader("application/openmetrics-text;version=0.0.1;q=0.75,text/plain;version=0.0.4"), + EFormat::PROMETHEUS); } Y_UNIT_TEST(FormatToStrFromStr) { diff --git a/library/cpp/monlib/encode/prometheus/CMakeLists.txt b/library/cpp/monlib/encode/prometheus/CMakeLists.txt index a0a682bb2a..662ee84590 100644 --- a/library/cpp/monlib/encode/prometheus/CMakeLists.txt +++ b/library/cpp/monlib/encode/prometheus/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries(monlib-encode-prometheus PUBLIC contrib-libs-cxxsupp yutil cpp-monlib-encode + monlib-encode-buffered ) target_sources(monlib-encode-prometheus PRIVATE ${CMAKE_SOURCE_DIR}/library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp diff --git a/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp b/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp index 15efeb8c03..f3015c48bc 100644 --- a/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp +++ b/library/cpp/monlib/encode/prometheus/prometheus_encoder.cpp @@ -2,6 +2,7 @@ #include "prometheus_model.h" #include <library/cpp/monlib/encode/encoder_state.h> +#include <library/cpp/monlib/encode/buffered/string_pool.h> #include <library/cpp/monlib/metrics/labels.h> #include <library/cpp/monlib/metrics/metric_value.h> @@ -311,6 +312,16 @@ namespace NMonitoring { } } + void OnLabel(ui32 name, ui32 value) override { + OnLabel(LabelNamesPool_.Get(name), LabelValuesPool_.Get(value)); + } + + std::pair<ui32, ui32> PrepareLabel(TStringBuf name, TStringBuf value) override { + auto nameLabel = LabelNamesPool_.PutIfAbsent(name); + auto valueLabel = LabelValuesPool_.PutIfAbsent(value); + return std::make_pair(nameLabel->Index, valueLabel->Index); + } + void OnDouble(TInstant time, double value) override { State_.Expect(TEncoderState::EState::METRIC); MetricState_.Time = time; @@ -403,6 +414,9 @@ namespace NMonitoring { TInstant CommonTime_ = TInstant::Zero(); TLabels CommonLabels_; TMetricState MetricState_; + + TStringPoolBuilder LabelNamesPool_; + TStringPoolBuilder LabelValuesPool_; }; } |