diff options
author | Sergey Polovko <sergey@polovko.me> | 2022-02-10 16:47:03 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:03 +0300 |
commit | 2e714b5ebd40a1f4cc31c27f1ad6e49ca6d895f5 (patch) | |
tree | b83306b6e37edeea782e9eed673d89286c4fef35 /library/cpp/monlib/encode/protobuf | |
parent | 3e0b762a82514bac89c1dd6ea7211e381d8aa248 (diff) | |
download | ydb-2e714b5ebd40a1f4cc31c27f1ad6e49ca6d895f5.tar.gz |
Restoring authorship annotation for Sergey Polovko <sergey@polovko.me>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib/encode/protobuf')
-rw-r--r-- | library/cpp/monlib/encode/protobuf/protobuf.h | 32 | ||||
-rw-r--r-- | library/cpp/monlib/encode/protobuf/protobuf_encoder.cpp | 396 | ||||
-rw-r--r-- | library/cpp/monlib/encode/protobuf/protos/samples.proto | 138 | ||||
-rw-r--r-- | library/cpp/monlib/encode/protobuf/protos/ya.make | 16 | ||||
-rw-r--r-- | library/cpp/monlib/encode/protobuf/ya.make | 26 |
5 files changed, 304 insertions, 304 deletions
diff --git a/library/cpp/monlib/encode/protobuf/protobuf.h b/library/cpp/monlib/encode/protobuf/protobuf.h index 219b94bee4..3f82cbdd84 100644 --- a/library/cpp/monlib/encode/protobuf/protobuf.h +++ b/library/cpp/monlib/encode/protobuf/protobuf.h @@ -1,16 +1,16 @@ -#pragma once - -#include <library/cpp/monlib/encode/encoder.h> - -#include <library/cpp/monlib/encode/protobuf/protos/samples.pb.h> - -namespace NMonitoring { - namespace NProto { - class TSingleSamplesList; - class TMultiSamplesList; - } - - IMetricEncoderPtr EncoderProtobuf(NProto::TSingleSamplesList* samples); - IMetricEncoderPtr EncoderProtobuf(NProto::TMultiSamplesList* samples); - -} +#pragma once + +#include <library/cpp/monlib/encode/encoder.h> + +#include <library/cpp/monlib/encode/protobuf/protos/samples.pb.h> + +namespace NMonitoring { + namespace NProto { + class TSingleSamplesList; + class TMultiSamplesList; + } + + IMetricEncoderPtr EncoderProtobuf(NProto::TSingleSamplesList* samples); + IMetricEncoderPtr EncoderProtobuf(NProto::TMultiSamplesList* samples); + +} diff --git a/library/cpp/monlib/encode/protobuf/protobuf_encoder.cpp b/library/cpp/monlib/encode/protobuf/protobuf_encoder.cpp index 57fbbba605..2d11b9d5ba 100644 --- a/library/cpp/monlib/encode/protobuf/protobuf_encoder.cpp +++ b/library/cpp/monlib/encode/protobuf/protobuf_encoder.cpp @@ -1,42 +1,42 @@ -#include "protobuf.h" - -#include <util/datetime/base.h> - -namespace NMonitoring { - namespace { - NProto::EMetricType ConvertMetricType(EMetricType type) { - switch (type) { - case EMetricType::GAUGE: - return NProto::GAUGE; - case EMetricType::COUNTER: - return NProto::COUNTER; - case EMetricType::RATE: - return NProto::RATE; - case EMetricType::IGAUGE: - return NProto::IGAUGE; - case EMetricType::HIST: +#include "protobuf.h" + +#include <util/datetime/base.h> + +namespace NMonitoring { + namespace { + NProto::EMetricType ConvertMetricType(EMetricType type) { + switch (type) { + case EMetricType::GAUGE: + return NProto::GAUGE; + case EMetricType::COUNTER: + return NProto::COUNTER; + case EMetricType::RATE: + return NProto::RATE; + case EMetricType::IGAUGE: + return NProto::IGAUGE; + case EMetricType::HIST: return NProto::HISTOGRAM; - case EMetricType::HIST_RATE: + case EMetricType::HIST_RATE: return NProto::HIST_RATE; - case EMetricType::DSUMMARY: + case EMetricType::DSUMMARY: return NProto::DSUMMARY; case EMetricType::LOGHIST: return NProto::LOGHISTOGRAM; - case EMetricType::UNKNOWN: - return NProto::UNKNOWN; - } - } - - void FillHistogram( - const IHistogramSnapshot& snapshot, - NProto::THistogram* histogram) - { - for (ui32 i = 0; i < snapshot.Count(); i++) { - histogram->AddBounds(snapshot.UpperBound(i)); - histogram->AddValues(snapshot.Value(i)); - } - } - + case EMetricType::UNKNOWN: + return NProto::UNKNOWN; + } + } + + void FillHistogram( + const IHistogramSnapshot& snapshot, + NProto::THistogram* histogram) + { + for (ui32 i = 0; i < snapshot.Count(); i++) { + histogram->AddBounds(snapshot.UpperBound(i)); + histogram->AddValues(snapshot.Value(i)); + } + } + void FillSummaryDouble(const ISummaryDoubleSnapshot& snapshot, NProto::TSummaryDouble* summary) { summary->SetSum(snapshot.GetSum()); summary->SetMin(snapshot.GetMin()); @@ -54,195 +54,195 @@ namespace NMonitoring { } } - /////////////////////////////////////////////////////////////////////////////// - // TSingleamplesEncoder - /////////////////////////////////////////////////////////////////////////////// - class TSingleSamplesEncoder final: public IMetricEncoder { - public: - TSingleSamplesEncoder(NProto::TSingleSamplesList* samples) - : Samples_(samples) - , Sample_(nullptr) - { - } - - private: - void OnStreamBegin() override { - } - void OnStreamEnd() override { - } - - void OnCommonTime(TInstant time) override { - Samples_->SetCommonTime(time.MilliSeconds()); - } - - void OnMetricBegin(EMetricType type) override { - Sample_ = Samples_->AddSamples(); - Sample_->SetMetricType(ConvertMetricType(type)); - } - - void OnMetricEnd() override { - Sample_ = nullptr; - } - - void OnLabelsBegin() override { - } - void OnLabelsEnd() override { - } - - void OnLabel(TStringBuf name, TStringBuf value) override { - NProto::TLabel* label = (Sample_ == nullptr) - ? Samples_->AddCommonLabels() - : Sample_->AddLabels(); + /////////////////////////////////////////////////////////////////////////////// + // TSingleamplesEncoder + /////////////////////////////////////////////////////////////////////////////// + class TSingleSamplesEncoder final: public IMetricEncoder { + public: + TSingleSamplesEncoder(NProto::TSingleSamplesList* samples) + : Samples_(samples) + , Sample_(nullptr) + { + } + + private: + void OnStreamBegin() override { + } + void OnStreamEnd() override { + } + + void OnCommonTime(TInstant time) override { + Samples_->SetCommonTime(time.MilliSeconds()); + } + + void OnMetricBegin(EMetricType type) override { + Sample_ = Samples_->AddSamples(); + Sample_->SetMetricType(ConvertMetricType(type)); + } + + void OnMetricEnd() override { + Sample_ = nullptr; + } + + void OnLabelsBegin() override { + } + void OnLabelsEnd() override { + } + + void OnLabel(TStringBuf name, TStringBuf value) override { + NProto::TLabel* label = (Sample_ == nullptr) + ? Samples_->AddCommonLabels() + : Sample_->AddLabels(); label->SetName(TString{name}); label->SetValue(TString{value}); - } - - void OnDouble(TInstant time, double value) override { - Y_ENSURE(Sample_, "metric not started"); - Sample_->SetTime(time.MilliSeconds()); - Sample_->SetFloat64(value); - } - - void OnInt64(TInstant time, i64 value) override { - Y_ENSURE(Sample_, "metric not started"); - Sample_->SetTime(time.MilliSeconds()); - Sample_->SetInt64(value); - } - - void OnUint64(TInstant time, ui64 value) override { - Y_ENSURE(Sample_, "metric not started"); - Sample_->SetTime(time.MilliSeconds()); - Sample_->SetUint64(value); - } - - void OnHistogram(TInstant time, IHistogramSnapshotPtr snapshot) override { - Y_ENSURE(Sample_, "metric not started"); - Sample_->SetTime(time.MilliSeconds()); - FillHistogram(*snapshot, Sample_->MutableHistogram()); - } - + } + + void OnDouble(TInstant time, double value) override { + Y_ENSURE(Sample_, "metric not started"); + Sample_->SetTime(time.MilliSeconds()); + Sample_->SetFloat64(value); + } + + void OnInt64(TInstant time, i64 value) override { + Y_ENSURE(Sample_, "metric not started"); + Sample_->SetTime(time.MilliSeconds()); + Sample_->SetInt64(value); + } + + void OnUint64(TInstant time, ui64 value) override { + Y_ENSURE(Sample_, "metric not started"); + Sample_->SetTime(time.MilliSeconds()); + Sample_->SetUint64(value); + } + + void OnHistogram(TInstant time, IHistogramSnapshotPtr snapshot) override { + Y_ENSURE(Sample_, "metric not started"); + Sample_->SetTime(time.MilliSeconds()); + FillHistogram(*snapshot, Sample_->MutableHistogram()); + } + void OnSummaryDouble(TInstant time, ISummaryDoubleSnapshotPtr snapshot) override { - Y_ENSURE(Sample_, "metric not started"); + Y_ENSURE(Sample_, "metric not started"); Sample_->SetTime(time.MilliSeconds()); FillSummaryDouble(*snapshot, Sample_->MutableSummaryDouble()); } void OnLogHistogram(TInstant time, TLogHistogramSnapshotPtr snapshot) override { - Y_ENSURE(Sample_, "metric not started"); + Y_ENSURE(Sample_, "metric not started"); Sample_->SetTime(time.MilliSeconds()); FillLogHistogram(*snapshot, Sample_->MutableLogHistogram()); } - void Close() override { - } - - private: - NProto::TSingleSamplesList* Samples_; - NProto::TSingleSample* Sample_; - }; - - /////////////////////////////////////////////////////////////////////////////// - // TMultiSamplesEncoder - /////////////////////////////////////////////////////////////////////////////// - class TMultiSamplesEncoder final: public IMetricEncoder { - public: - TMultiSamplesEncoder(NProto::TMultiSamplesList* samples) - : Samples_(samples) - , Sample_(nullptr) - { - } - - private: - void OnStreamBegin() override { - } - void OnStreamEnd() override { - } - - void OnCommonTime(TInstant time) override { - Samples_->SetCommonTime(time.MilliSeconds()); - } - - void OnMetricBegin(EMetricType type) override { - Sample_ = Samples_->AddSamples(); - Sample_->SetMetricType(ConvertMetricType(type)); - } - - void OnMetricEnd() override { - Sample_ = nullptr; - } - - void OnLabelsBegin() override { - } - void OnLabelsEnd() override { - } - - void OnLabel(TStringBuf name, TStringBuf value) override { - NProto::TLabel* label = (Sample_ == nullptr) - ? Samples_->AddCommonLabels() - : Sample_->AddLabels(); - + void Close() override { + } + + private: + NProto::TSingleSamplesList* Samples_; + NProto::TSingleSample* Sample_; + }; + + /////////////////////////////////////////////////////////////////////////////// + // TMultiSamplesEncoder + /////////////////////////////////////////////////////////////////////////////// + class TMultiSamplesEncoder final: public IMetricEncoder { + public: + TMultiSamplesEncoder(NProto::TMultiSamplesList* samples) + : Samples_(samples) + , Sample_(nullptr) + { + } + + private: + void OnStreamBegin() override { + } + void OnStreamEnd() override { + } + + void OnCommonTime(TInstant time) override { + Samples_->SetCommonTime(time.MilliSeconds()); + } + + void OnMetricBegin(EMetricType type) override { + Sample_ = Samples_->AddSamples(); + Sample_->SetMetricType(ConvertMetricType(type)); + } + + void OnMetricEnd() override { + Sample_ = nullptr; + } + + void OnLabelsBegin() override { + } + void OnLabelsEnd() override { + } + + void OnLabel(TStringBuf name, TStringBuf value) override { + NProto::TLabel* label = (Sample_ == nullptr) + ? Samples_->AddCommonLabels() + : Sample_->AddLabels(); + label->SetName(TString{name}); label->SetValue(TString{value}); - } - - void OnDouble(TInstant time, double value) override { - Y_ENSURE(Sample_, "metric not started"); - NProto::TPoint* point = Sample_->AddPoints(); - point->SetTime(time.MilliSeconds()); - point->SetFloat64(value); - } - - void OnInt64(TInstant time, i64 value) override { - Y_ENSURE(Sample_, "metric not started"); - NProto::TPoint* point = Sample_->AddPoints(); - point->SetTime(time.MilliSeconds()); - point->SetInt64(value); - } - - void OnUint64(TInstant time, ui64 value) override { - Y_ENSURE(Sample_, "metric not started"); - NProto::TPoint* point = Sample_->AddPoints(); - point->SetTime(time.MilliSeconds()); - point->SetUint64(value); - } - - void OnHistogram(TInstant time, IHistogramSnapshotPtr snapshot) override { - Y_ENSURE(Sample_, "metric not started"); - NProto::TPoint* point = Sample_->AddPoints(); - point->SetTime(time.MilliSeconds()); - FillHistogram(*snapshot, point->MutableHistogram()); - } - + } + + void OnDouble(TInstant time, double value) override { + Y_ENSURE(Sample_, "metric not started"); + NProto::TPoint* point = Sample_->AddPoints(); + point->SetTime(time.MilliSeconds()); + point->SetFloat64(value); + } + + void OnInt64(TInstant time, i64 value) override { + Y_ENSURE(Sample_, "metric not started"); + NProto::TPoint* point = Sample_->AddPoints(); + point->SetTime(time.MilliSeconds()); + point->SetInt64(value); + } + + void OnUint64(TInstant time, ui64 value) override { + Y_ENSURE(Sample_, "metric not started"); + NProto::TPoint* point = Sample_->AddPoints(); + point->SetTime(time.MilliSeconds()); + point->SetUint64(value); + } + + void OnHistogram(TInstant time, IHistogramSnapshotPtr snapshot) override { + Y_ENSURE(Sample_, "metric not started"); + NProto::TPoint* point = Sample_->AddPoints(); + point->SetTime(time.MilliSeconds()); + FillHistogram(*snapshot, point->MutableHistogram()); + } + void OnSummaryDouble(TInstant time, ISummaryDoubleSnapshotPtr snapshot) override { - Y_ENSURE(Sample_, "metric not started"); + Y_ENSURE(Sample_, "metric not started"); NProto::TPoint* point = Sample_->AddPoints(); point->SetTime(time.MilliSeconds()); FillSummaryDouble(*snapshot, point->MutableSummaryDouble()); } void OnLogHistogram(TInstant time, TLogHistogramSnapshotPtr snapshot) override { - Y_ENSURE(Sample_, "metric not started"); + Y_ENSURE(Sample_, "metric not started"); NProto::TPoint* point = Sample_->AddPoints(); point->SetTime(time.MilliSeconds()); FillLogHistogram(*snapshot, point->MutableLogHistogram()); } - void Close() override { - } - - private: - NProto::TMultiSamplesList* Samples_; - NProto::TMultiSample* Sample_; - }; - - } - - IMetricEncoderPtr EncoderProtobuf(NProto::TSingleSamplesList* samples) { + void Close() override { + } + + private: + NProto::TMultiSamplesList* Samples_; + NProto::TMultiSample* Sample_; + }; + + } + + IMetricEncoderPtr EncoderProtobuf(NProto::TSingleSamplesList* samples) { return MakeHolder<TSingleSamplesEncoder>(samples); - } - - IMetricEncoderPtr EncoderProtobuf(NProto::TMultiSamplesList* samples) { + } + + IMetricEncoderPtr EncoderProtobuf(NProto::TMultiSamplesList* samples) { return MakeHolder<TMultiSamplesEncoder>(samples); - } - -} + } + +} diff --git a/library/cpp/monlib/encode/protobuf/protos/samples.proto b/library/cpp/monlib/encode/protobuf/protos/samples.proto index d5f0c6403e..371f4181d2 100644 --- a/library/cpp/monlib/encode/protobuf/protos/samples.proto +++ b/library/cpp/monlib/encode/protobuf/protos/samples.proto @@ -1,33 +1,33 @@ -syntax = 'proto3'; - -package NMonitoring.NProto; - -option java_package = "ru.yandex.solomon.protos"; -option java_multiple_files = true; -option cc_enable_arenas = true; - -message TLabel { - string Name = 1; - string Value = 2; -} - -enum EMetricType { - UNKNOWN = 0; - GAUGE = 1; - IGAUGE = 2; - COUNTER = 3; - RATE = 4; - HISTOGRAM = 5; +syntax = 'proto3'; + +package NMonitoring.NProto; + +option java_package = "ru.yandex.solomon.protos"; +option java_multiple_files = true; +option cc_enable_arenas = true; + +message TLabel { + string Name = 1; + string Value = 2; +} + +enum EMetricType { + UNKNOWN = 0; + GAUGE = 1; + IGAUGE = 2; + COUNTER = 3; + RATE = 4; + HISTOGRAM = 5; HIST_RATE = 6; DSUMMARY = 7; LOGHISTOGRAM = 8; -} - -message THistogram { - repeated double Bounds = 1; // upper bounds of each bucket - repeated uint64 Values = 2; // values stored in each bucket -} - +} + +message THistogram { + repeated double Bounds = 1; // upper bounds of each bucket + repeated uint64 Values = 2; // values stored in each bucket +} + message TLogHistogram { double Base = 1; uint64 ZerosCount = 2; @@ -43,49 +43,49 @@ message TSummaryDouble { uint64 Count = 5; } -// see TSingleSample -message TPoint { - uint64 Time = 1; - oneof Value { - sfixed64 Int64 = 2; - fixed64 Uint64 = 3; - double Float64 = 4; - THistogram Histogram = 5; +// see TSingleSample +message TPoint { + uint64 Time = 1; + oneof Value { + sfixed64 Int64 = 2; + fixed64 Uint64 = 3; + double Float64 = 4; + THistogram Histogram = 5; TSummaryDouble SummaryDouble = 6; TLogHistogram LogHistogram = 7; - } -} - -message TSingleSample { - repeated TLabel Labels = 1; - EMetricType MetricType = 2; - - // inlined TPoint - uint64 Time = 3; - oneof Value { - sfixed64 Int64 = 4; - fixed64 Uint64 = 5; - double Float64 = 6; - THistogram Histogram = 7; + } +} + +message TSingleSample { + repeated TLabel Labels = 1; + EMetricType MetricType = 2; + + // inlined TPoint + uint64 Time = 3; + oneof Value { + sfixed64 Int64 = 4; + fixed64 Uint64 = 5; + double Float64 = 6; + THistogram Histogram = 7; TSummaryDouble SummaryDouble = 8; TLogHistogram LogHistogram = 9; - } -} - -message TMultiSample { - repeated TLabel Labels = 1; - EMetricType MetricType = 2; - repeated TPoint Points = 3; -} - -message TSingleSamplesList { - uint64 CommonTime = 1; - repeated TLabel CommonLabels = 2; - repeated TSingleSample Samples = 3; -} - -message TMultiSamplesList { - uint64 CommonTime = 1; - repeated TLabel CommonLabels = 2; - repeated TMultiSample Samples = 3; -} + } +} + +message TMultiSample { + repeated TLabel Labels = 1; + EMetricType MetricType = 2; + repeated TPoint Points = 3; +} + +message TSingleSamplesList { + uint64 CommonTime = 1; + repeated TLabel CommonLabels = 2; + repeated TSingleSample Samples = 3; +} + +message TMultiSamplesList { + uint64 CommonTime = 1; + repeated TLabel CommonLabels = 2; + repeated TMultiSample Samples = 3; +} diff --git a/library/cpp/monlib/encode/protobuf/protos/ya.make b/library/cpp/monlib/encode/protobuf/protos/ya.make index 29a87a0b21..88ff3ddf88 100644 --- a/library/cpp/monlib/encode/protobuf/protos/ya.make +++ b/library/cpp/monlib/encode/protobuf/protos/ya.make @@ -1,14 +1,14 @@ -PROTO_LIBRARY() - +PROTO_LIBRARY() + OWNER( jamel g:solomon ) - -SRCS( - samples.proto -) - + +SRCS( + samples.proto +) + EXCLUDE_TAGS(GO_PROTO) -END() +END() diff --git a/library/cpp/monlib/encode/protobuf/ya.make b/library/cpp/monlib/encode/protobuf/ya.make index fd575ef731..9354958b6f 100644 --- a/library/cpp/monlib/encode/protobuf/ya.make +++ b/library/cpp/monlib/encode/protobuf/ya.make @@ -1,17 +1,17 @@ -LIBRARY() - +LIBRARY() + OWNER( jamel g:solomon ) - -SRCS( - protobuf_encoder.cpp -) - -PEERDIR( - library/cpp/monlib/encode - library/cpp/monlib/encode/protobuf/protos -) - -END() + +SRCS( + protobuf_encoder.cpp +) + +PEERDIR( + library/cpp/monlib/encode + library/cpp/monlib/encode/protobuf/protos +) + +END() |