diff options
author | iuraskvortsov <iuraskvortsov@yandex-team.ru> | 2022-03-28 14:05:44 +0300 |
---|---|---|
committer | iuraskvortsov <iuraskvortsov@yandex-team.ru> | 2022-03-28 14:05:44 +0300 |
commit | a748735498ab31a176f1e8566e0e5c6da8610de8 (patch) | |
tree | 277ace72995f9cb901822147b56e9e1629828928 | |
parent | 89eb355d724e60dcfa56e662bffccd4dea3402c1 (diff) | |
download | ydb-a748735498ab31a176f1e8566e0e5c6da8610de8.tar.gz |
MSI-1102 Unistat for UA
ref:ac6385bada68d413b4f372ca0afea6a30a85f7d3
-rw-r--r-- | library/cpp/monlib/encode/format.h | 1 | ||||
-rw-r--r-- | library/cpp/monlib/encode/unistat/unistat.h | 4 | ||||
-rw-r--r-- | library/cpp/monlib/encode/unistat/unistat_decoder.cpp | 18 | ||||
-rw-r--r-- | library/cpp/monlib/encode/unistat/unistat_ut.cpp | 15 | ||||
-rw-r--r-- | library/cpp/monlib/service/pages/mon_page.h | 1 |
5 files changed, 29 insertions, 10 deletions
diff --git a/library/cpp/monlib/encode/format.h b/library/cpp/monlib/encode/format.h index 495d42d786..7c916eaa28 100644 --- a/library/cpp/monlib/encode/format.h +++ b/library/cpp/monlib/encode/format.h @@ -9,6 +9,7 @@ namespace NMonitoring { constexpr TStringBuf PROTOBUF = "application/x-solomon-pb"; constexpr TStringBuf SPACK = "application/x-solomon-spack"; constexpr TStringBuf PROMETHEUS = "text/plain"; + constexpr TStringBuf UNISTAT = "text/json"; } namespace NFormatContentEncoding { diff --git a/library/cpp/monlib/encode/unistat/unistat.h b/library/cpp/monlib/encode/unistat/unistat.h index 1c43b7fa1b..300fb6270f 100644 --- a/library/cpp/monlib/encode/unistat/unistat.h +++ b/library/cpp/monlib/encode/unistat/unistat.h @@ -6,8 +6,8 @@ namespace NMonitoring { /// Decodes unistat-style metrics /// https://wiki.yandex-team.ru/golovan/stat-handle - void DecodeUnistat(TStringBuf data, class IMetricConsumer* c, TInstant ts = TInstant::Zero()); + void DecodeUnistat(TStringBuf data, class IMetricConsumer* c, TStringBuf metricNameLabel = "sensor", TInstant ts = TInstant::Zero()); /// Assumes consumer's stream is open by the caller - void DecodeUnistatToStream(TStringBuf data, class IMetricConsumer* c, TInstant = TInstant::Zero()); + void DecodeUnistatToStream(TStringBuf data, class IMetricConsumer* c, TStringBuf metricNameLabel = "sensor", TInstant ts = TInstant::Zero()); } diff --git a/library/cpp/monlib/encode/unistat/unistat_decoder.cpp b/library/cpp/monlib/encode/unistat/unistat_decoder.cpp index b2344b0905..8c34dbefc0 100644 --- a/library/cpp/monlib/encode/unistat/unistat_decoder.cpp +++ b/library/cpp/monlib/encode/unistat/unistat_decoder.cpp @@ -86,9 +86,10 @@ namespace NMonitoring { class TDecoderUnistat { private: public: - explicit TDecoderUnistat(IMetricConsumer* consumer, IInputStream* is, TInstant ts) - : Consumer_{consumer} - , Timestamp_{ts} { + explicit TDecoderUnistat(IMetricConsumer* consumer, IInputStream* is, TStringBuf metricNameLabel, TInstant ts) + : Consumer_{consumer}, + MetricNameLabel(metricNameLabel), + Timestamp_{ts} { ReadJsonTree(is, &Json_, /* throw */ true); } @@ -193,7 +194,7 @@ namespace NMonitoring { Consumer_->OnMetricBegin(MetricContext_.Type); Consumer_->OnLabelsBegin(); - Consumer_->OnLabel("sensor", TString{MetricContext_.Name}); + Consumer_->OnLabel(MetricNameLabel, TString{MetricContext_.Name}); for (auto&& l : MetricContext_.Labels) { Consumer_->OnLabel(l.Name(), l.Value()); } @@ -225,6 +226,7 @@ namespace NMonitoring { private: IMetricConsumer* Consumer_; NJson::TJsonValue Json_; + TStringBuf MetricNameLabel; TInstant Timestamp_; struct { @@ -239,15 +241,15 @@ namespace NMonitoring { } - void DecodeUnistat(TStringBuf data, IMetricConsumer* c, TInstant ts) { + void DecodeUnistat(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel, TInstant ts) { c->OnStreamBegin(); - DecodeUnistatToStream(data, c, ts); + DecodeUnistatToStream(data, c, metricNameLabel, ts); c->OnStreamEnd(); } - void DecodeUnistatToStream(TStringBuf data, IMetricConsumer* c, TInstant ts) { + void DecodeUnistatToStream(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel, TInstant ts) { TMemoryInput in{data.data(), data.size()}; - TDecoderUnistat decoder(c, &in, ts); + TDecoderUnistat decoder(c, &in, metricNameLabel, ts); decoder.Decode(); } } diff --git a/library/cpp/monlib/encode/unistat/unistat_ut.cpp b/library/cpp/monlib/encode/unistat/unistat_ut.cpp index dbbc238bf3..04c84d30f6 100644 --- a/library/cpp/monlib/encode/unistat/unistat_ut.cpp +++ b/library/cpp/monlib/encode/unistat/unistat_ut.cpp @@ -8,6 +8,21 @@ using namespace NMonitoring; Y_UNIT_TEST_SUITE(TUnistatDecoderTest) { + Y_UNIT_TEST(MetricNameLabel) { + constexpr auto input = TStringBuf(R"([["something_axxx", 42]])"); + + NProto::TMultiSamplesList samples; + auto encoder = EncoderProtobuf(&samples); + + DecodeUnistat(input, encoder.Get(), "metric_name_label"); + + UNIT_ASSERT_VALUES_EQUAL(samples.SamplesSize(), 1); + auto sample = samples.GetSamples(0); + + auto label = sample.GetLabels(0); + UNIT_ASSERT_VALUES_EQUAL(label.GetName(), "metric_name_label"); + } + Y_UNIT_TEST(ScalarMetric) { constexpr auto input = TStringBuf(R"([["something_axxx", 42]])"); diff --git a/library/cpp/monlib/service/pages/mon_page.h b/library/cpp/monlib/service/pages/mon_page.h index e396612bb0..136647e5be 100644 --- a/library/cpp/monlib/service/pages/mon_page.h +++ b/library/cpp/monlib/service/pages/mon_page.h @@ -13,6 +13,7 @@ namespace NMonitoring { static const char HTTPOKJSON[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/json\r\nConnection: Close\r\n\r\n"; static const char HTTPOKSPACK[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/x-solomon-spack\r\nConnection: Close\r\n\r\n"; static const char HTTPOKPROMETHEUS[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/plain\r\nConnection: Close\r\n\r\n"; + static const char HTTPOKUNISTAT[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/json\r\nConnection: Close\r\n\r\n"; static const char HTTPOKJAVASCRIPT[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/javascript\r\nConnection: Close\r\n\r\n"; static const char HTTPOKCSS[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/css\r\nConnection: Close\r\n\r\n"; static const char HTTPNOCONTENT[] = "HTTP/1.1 204 No content\r\nConnection: Close\r\n\r\n"; |