diff options
| author | kgershov <[email protected]> | 2026-04-06 16:46:20 +0300 |
|---|---|---|
| committer | kgershov <[email protected]> | 2026-04-06 17:08:32 +0300 |
| commit | ee9a12d94efbb3b7bb3e5395fa0b01f724c4d215 (patch) | |
| tree | 7468ea854b171ac0cc66f3b3c09bea56c0d81eda /library/cpp/monlib/encode/spack/spack_v1_encoder.cpp | |
| parent | f86fc7fae5939cfb2fc83a842cd8043cffcbb9a3 (diff) | |
[library/cpp/monlib] add v3 spack encode/decode
commit_hash:91ce0e2023d29ef78fadeaded314ea236f316b8e
Diffstat (limited to 'library/cpp/monlib/encode/spack/spack_v1_encoder.cpp')
| -rw-r--r-- | library/cpp/monlib/encode/spack/spack_v1_encoder.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/library/cpp/monlib/encode/spack/spack_v1_encoder.cpp b/library/cpp/monlib/encode/spack/spack_v1_encoder.cpp index 70c5bba5512..ac9934b0593 100644 --- a/library/cpp/monlib/encode/spack/spack_v1_encoder.cpp +++ b/library/cpp/monlib/encode/spack/spack_v1_encoder.cpp @@ -31,7 +31,7 @@ namespace NMonitoring { , TimePrecision_(timePrecision) , Compression_(compression) , Version_(version) - , MetricName_(Version_ >= SV1_02 ? LabelNamesPool_.PutIfAbsent(metricNameLabel) : nullptr) + , MetricName_(Version_ == SV1_02 ? LabelNamesPool_.PutIfAbsent(metricNameLabel) : nullptr) { MetricsMergingMode_ = mergingMode; @@ -96,10 +96,15 @@ namespace NMonitoring { header.Version = Version_; header.TimePrecision = EncodeTimePrecision(TimePrecision_); header.Compression = EncodeCompression(Compression_); - header.LabelNamesSize = static_cast<ui32>( - LabelNamesPool_.BytesSize() + LabelNamesPool_.Count()); - header.LabelValuesSize = static_cast<ui32>( - LabelValuesPool_.BytesSize() + LabelValuesPool_.Count()); + if (Version_ == SV1_03) { + header.LabelNamesSize = static_cast<ui32>(LabelNamesPool_.Count()); + header.LabelValuesSize = static_cast<ui32>(LabelValuesPool_.Count()); + } else { + header.LabelNamesSize = static_cast<ui32>( + LabelNamesPool_.BytesSize() + LabelNamesPool_.Count()); + header.LabelValuesSize = static_cast<ui32>( + LabelValuesPool_.BytesSize() + LabelValuesPool_.Count()); + } header.MetricCount = Metrics_.size(); header.PointsCount = pointsCount; Out_->Write(&header, sizeof(header)); @@ -111,13 +116,21 @@ namespace NMonitoring { } // (2) write string pools - auto strPoolWrite = [this](TStringBuf str, ui32, ui32) { - Out_->Write(str); - Out_->Write('\0'); - }; - - LabelNamesPool_.ForEach(strPoolWrite); - LabelValuesPool_.ForEach(strPoolWrite); + if (Version_ == SV1_03) { + auto strPoolWrite = [this](TStringBuf str, ui32, ui32) { + WriteVarUInt32(Out_, static_cast<ui32>(str.size())); + Out_->Write(str); + }; + LabelNamesPool_.ForEach(strPoolWrite); + LabelValuesPool_.ForEach(strPoolWrite); + } else { + auto strPoolWrite = [this](TStringBuf str, ui32, ui32) { + Out_->Write(str); + Out_->Write('\0'); + }; + LabelNamesPool_.ForEach(strPoolWrite); + LabelValuesPool_.ForEach(strPoolWrite); + } // (3) write common time WriteTime(CommonTime_); @@ -137,7 +150,7 @@ namespace NMonitoring { Out_->Write(&flagsByte, sizeof(flagsByte)); // v1.2 format addition — metric name - if (Version_ >= SV1_02) { + if (Version_ == SV1_02) { const auto it = FindIf(metric.Labels, [&](const auto& l) { return l.Key == MetricName_; }); @@ -319,4 +332,13 @@ namespace NMonitoring { Y_ENSURE(!metricNameLabel.empty(), "metricNameLabel can't be empty"); return MakeHolder<TEncoderSpackV1>(out, timePrecision, compression, mergingMode, SV1_02, metricNameLabel); } + + IMetricEncoderPtr EncoderSpackV13( + IOutputStream* out, + ETimePrecision timePrecision, + ECompression compression, + EMetricsMergingMode mergingMode + ) { + return MakeHolder<TEncoderSpackV1>(out, timePrecision, compression, mergingMode, SV1_03, ""); + } } |
