aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/encode/buffered
diff options
context:
space:
mode:
authormsherbakov <msherbakov@yandex-team.ru>2022-02-10 16:49:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:17 +0300
commita0ffafe83b7d6229709a32fa942c71d672ac989c (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/monlib/encode/buffered
parentc224a621661ddd69699f9476922eb316607ef57e (diff)
downloadydb-a0ffafe83b7d6229709a32fa942c71d672ac989c.tar.gz
Restoring authorship annotation for <msherbakov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib/encode/buffered')
-rw-r--r--library/cpp/monlib/encode/buffered/buffered_encoder_base.cpp92
-rw-r--r--library/cpp/monlib/encode/buffered/buffered_encoder_base.h148
-rw-r--r--library/cpp/monlib/encode/buffered/string_pool.cpp28
-rw-r--r--library/cpp/monlib/encode/buffered/string_pool.h36
-rw-r--r--library/cpp/monlib/encode/buffered/string_pool_ut.cpp12
-rw-r--r--library/cpp/monlib/encode/buffered/ut/ya.make14
-rw-r--r--library/cpp/monlib/encode/buffered/ya.make24
7 files changed, 177 insertions, 177 deletions
diff --git a/library/cpp/monlib/encode/buffered/buffered_encoder_base.cpp b/library/cpp/monlib/encode/buffered/buffered_encoder_base.cpp
index 022e025fa7..87c832d642 100644
--- a/library/cpp/monlib/encode/buffered/buffered_encoder_base.cpp
+++ b/library/cpp/monlib/encode/buffered/buffered_encoder_base.cpp
@@ -1,29 +1,29 @@
-#include "buffered_encoder_base.h"
-
+#include "buffered_encoder_base.h"
+
#include <util/string/join.h>
#include <util/string/builder.h>
-namespace NMonitoring {
-
-void TBufferedEncoderBase::OnStreamBegin() {
+namespace NMonitoring {
+
+void TBufferedEncoderBase::OnStreamBegin() {
State_.Expect(TEncoderState::EState::ROOT);
-}
-
-void TBufferedEncoderBase::OnStreamEnd() {
+}
+
+void TBufferedEncoderBase::OnStreamEnd() {
State_.Expect(TEncoderState::EState::ROOT);
-}
-
-void TBufferedEncoderBase::OnCommonTime(TInstant time) {
+}
+
+void TBufferedEncoderBase::OnCommonTime(TInstant time) {
State_.Expect(TEncoderState::EState::ROOT);
- CommonTime_ = time;
-}
-
+ CommonTime_ = time;
+}
+
void TBufferedEncoderBase::OnMetricBegin(EMetricType type) {
State_.Switch(TEncoderState::EState::ROOT, TEncoderState::EState::METRIC);
Metrics_.emplace_back();
Metrics_.back().MetricType = type;
-}
-
+}
+
void TBufferedEncoderBase::OnMetricEnd() {
State_.Switch(TEncoderState::EState::METRIC, TEncoderState::EState::ROOT);
@@ -41,7 +41,7 @@ void TBufferedEncoderBase::OnMetricEnd() {
auto& existing = Metrics_[it->second].TimeSeries;
Y_ENSURE(existing.GetValueType() == metric.TimeSeries.GetValueType(),
- "Time series point type mismatch: expected " << existing.GetValueType()
+ "Time series point type mismatch: expected " << existing.GetValueType()
<< " but found " << metric.TimeSeries.GetValueType()
<< ", labels '" << FormatLabels(metric.Labels) << "'");
@@ -54,41 +54,41 @@ void TBufferedEncoderBase::OnMetricEnd() {
case EMetricsMergingMode::DEFAULT:
break;
}
-}
-
-void TBufferedEncoderBase::OnLabelsBegin() {
+}
+
+void TBufferedEncoderBase::OnLabelsBegin() {
if (State_ == TEncoderState::EState::METRIC) {
State_ = TEncoderState::EState::METRIC_LABELS;
} else if (State_ == TEncoderState::EState::ROOT) {
State_ = TEncoderState::EState::COMMON_LABELS;
- } else {
+ } else {
State_.ThrowInvalid("expected METRIC or ROOT");
- }
-}
-
-void TBufferedEncoderBase::OnLabelsEnd() {
+ }
+}
+
+void TBufferedEncoderBase::OnLabelsEnd() {
if (State_ == TEncoderState::EState::METRIC_LABELS) {
State_ = TEncoderState::EState::METRIC;
} else if (State_ == TEncoderState::EState::COMMON_LABELS) {
State_ = TEncoderState::EState::ROOT;
- } else {
- State_.ThrowInvalid("expected LABELS or COMMON_LABELS");
- }
-}
-
+ } else {
+ State_.ThrowInvalid("expected LABELS or COMMON_LABELS");
+ }
+}
+
void TBufferedEncoderBase::OnLabel(TStringBuf name, TStringBuf value) {
- TPooledLabels* labels;
+ TPooledLabels* labels;
if (State_ == TEncoderState::EState::METRIC_LABELS) {
labels = &Metrics_.back().Labels;
} else if (State_ == TEncoderState::EState::COMMON_LABELS) {
- labels = &CommonLabels_;
- } else {
- State_.ThrowInvalid("expected LABELS or COMMON_LABELS");
- }
-
- labels->emplace_back(LabelNamesPool_.PutIfAbsent(name), LabelValuesPool_.PutIfAbsent(value));
-}
-
+ labels = &CommonLabels_;
+ } else {
+ State_.ThrowInvalid("expected LABELS or COMMON_LABELS");
+ }
+
+ labels->emplace_back(LabelNamesPool_.PutIfAbsent(name), LabelValuesPool_.PutIfAbsent(value));
+}
+
void TBufferedEncoderBase::OnLabel(ui32 name, ui32 value) {
TPooledLabels* labels;
if (State_ == TEncoderState::EState::METRIC_LABELS) {
@@ -108,24 +108,24 @@ std::pair<ui32, ui32> TBufferedEncoderBase::PrepareLabel(TStringBuf name, TStrin
return std::make_pair(nameLabel->Index, valueLabel->Index);
}
-void TBufferedEncoderBase::OnDouble(TInstant time, double value) {
+void TBufferedEncoderBase::OnDouble(TInstant time, double value) {
State_.Expect(TEncoderState::EState::METRIC);
TMetric& metric = Metrics_.back();
metric.TimeSeries.Add(time, value);
-}
-
+}
+
void TBufferedEncoderBase::OnInt64(TInstant time, i64 value) {
State_.Expect(TEncoderState::EState::METRIC);
TMetric& metric = Metrics_.back();
metric.TimeSeries.Add(time, value);
}
-void TBufferedEncoderBase::OnUint64(TInstant time, ui64 value) {
+void TBufferedEncoderBase::OnUint64(TInstant time, ui64 value) {
State_.Expect(TEncoderState::EState::METRIC);
TMetric& metric = Metrics_.back();
metric.TimeSeries.Add(time, value);
-}
-
+}
+
void TBufferedEncoderBase::OnHistogram(TInstant time, IHistogramSnapshotPtr s) {
State_.Expect(TEncoderState::EState::METRIC);
TMetric& metric = Metrics_.back();
@@ -167,4 +167,4 @@ TString TBufferedEncoderBase::FormatLabels(const TPooledLabels& labels) const {
return TStringBuilder() << "{" << JoinSeq(", ", formattedLabels) << "}";
}
-} // namespace NMonitoring
+} // namespace NMonitoring
diff --git a/library/cpp/monlib/encode/buffered/buffered_encoder_base.h b/library/cpp/monlib/encode/buffered/buffered_encoder_base.h
index 38f63eac1d..fe3714e58f 100644
--- a/library/cpp/monlib/encode/buffered/buffered_encoder_base.h
+++ b/library/cpp/monlib/encode/buffered/buffered_encoder_base.h
@@ -1,100 +1,100 @@
-#pragma once
-
-#include "string_pool.h"
-
+#pragma once
+
+#include "string_pool.h"
+
#include <library/cpp/monlib/encode/encoder.h>
#include <library/cpp/monlib/encode/encoder_state.h>
#include <library/cpp/monlib/encode/format.h>
#include <library/cpp/monlib/metrics/metric_value.h>
-
-#include <util/datetime/base.h>
-#include <util/digest/numeric.h>
-
-
-namespace NMonitoring {
-
+
+#include <util/datetime/base.h>
+#include <util/digest/numeric.h>
+
+
+namespace NMonitoring {
+
class TBufferedEncoderBase : public IMetricEncoder {
-public:
- void OnStreamBegin() override;
- void OnStreamEnd() override;
-
- void OnCommonTime(TInstant time) override;
-
+public:
+ void OnStreamBegin() override;
+ void OnStreamEnd() override;
+
+ void OnCommonTime(TInstant time) override;
+
void OnMetricBegin(EMetricType type) override;
void OnMetricEnd() override;
-
- void OnLabelsBegin() override;
- void OnLabelsEnd() override;
+
+ void OnLabelsBegin() override;
+ void OnLabelsEnd() override;
void OnLabel(TStringBuf name, TStringBuf value) override;
void OnLabel(ui32 name, ui32 value) override;
std::pair<ui32, ui32> PrepareLabel(TStringBuf name, TStringBuf value) override;
-
- void OnDouble(TInstant time, double value) override;
+
+ void OnDouble(TInstant time, double value) override;
void OnInt64(TInstant time, i64 value) override;
- void OnUint64(TInstant time, ui64 value) override;
-
+ void OnUint64(TInstant time, ui64 value) override;
+
void OnHistogram(TInstant time, IHistogramSnapshotPtr snapshot) override;
void OnSummaryDouble(TInstant time, ISummaryDoubleSnapshotPtr snapshot) override;
void OnLogHistogram(TInstant, TLogHistogramSnapshotPtr) override;
-protected:
- using TPooledStr = TStringPoolBuilder::TValue;
-
- struct TPooledLabel {
- TPooledLabel(const TPooledStr* key, const TPooledStr* value)
- : Key{key}
- , Value{value}
- {
- }
-
- bool operator==(const TPooledLabel& other) const {
- return std::tie(Key, Value) == std::tie(other.Key, other.Value);
- }
-
- bool operator!=(const TPooledLabel& other) const {
- return !(*this == other);
- }
-
- const TPooledStr* Key;
- const TPooledStr* Value;
- };
-
- using TPooledLabels = TVector<TPooledLabel>;
-
- struct TPooledLabelsHash {
- size_t operator()(const TPooledLabels& val) const {
- size_t hash{0};
-
- for (auto v : val) {
- hash = CombineHashes<size_t>(hash, reinterpret_cast<size_t>(v.Key));
- hash = CombineHashes<size_t>(hash, reinterpret_cast<size_t>(v.Value));
- }
-
- return hash;
- }
- };
-
+protected:
+ using TPooledStr = TStringPoolBuilder::TValue;
+
+ struct TPooledLabel {
+ TPooledLabel(const TPooledStr* key, const TPooledStr* value)
+ : Key{key}
+ , Value{value}
+ {
+ }
+
+ bool operator==(const TPooledLabel& other) const {
+ return std::tie(Key, Value) == std::tie(other.Key, other.Value);
+ }
+
+ bool operator!=(const TPooledLabel& other) const {
+ return !(*this == other);
+ }
+
+ const TPooledStr* Key;
+ const TPooledStr* Value;
+ };
+
+ using TPooledLabels = TVector<TPooledLabel>;
+
+ struct TPooledLabelsHash {
+ size_t operator()(const TPooledLabels& val) const {
+ size_t hash{0};
+
+ for (auto v : val) {
+ hash = CombineHashes<size_t>(hash, reinterpret_cast<size_t>(v.Key));
+ hash = CombineHashes<size_t>(hash, reinterpret_cast<size_t>(v.Value));
+ }
+
+ return hash;
+ }
+ };
+
using TMetricMap = THashMap<TPooledLabels, size_t, TPooledLabelsHash>;
-
+
struct TMetric {
EMetricType MetricType = EMetricType::UNKNOWN;
- TPooledLabels Labels;
+ TPooledLabels Labels;
TMetricTimeSeries TimeSeries;
- };
-
+ };
+
protected:
TString FormatLabels(const TPooledLabels& labels) const;
protected:
- TEncoderState State_;
-
- TStringPoolBuilder LabelNamesPool_;
- TStringPoolBuilder LabelValuesPool_;
- TInstant CommonTime_ = TInstant::Zero();
- TPooledLabels CommonLabels_;
+ TEncoderState State_;
+
+ TStringPoolBuilder LabelNamesPool_;
+ TStringPoolBuilder LabelValuesPool_;
+ TInstant CommonTime_ = TInstant::Zero();
+ TPooledLabels CommonLabels_;
TVector<TMetric> Metrics_;
TMetricMap MetricMap_;
EMetricsMergingMode MetricsMergingMode_ = EMetricsMergingMode::DEFAULT;
-};
-
-}
+};
+
+}
diff --git a/library/cpp/monlib/encode/buffered/string_pool.cpp b/library/cpp/monlib/encode/buffered/string_pool.cpp
index 3c274f27f7..b4c7988ba3 100644
--- a/library/cpp/monlib/encode/buffered/string_pool.cpp
+++ b/library/cpp/monlib/encode/buffered/string_pool.cpp
@@ -5,16 +5,16 @@ namespace NMonitoring {
// TStringPoolBuilder
////////////////////////////////////////////////////////////////////////////////
const TStringPoolBuilder::TValue* TStringPoolBuilder::PutIfAbsent(TStringBuf str) {
- Y_ENSURE(!IsBuilt_, "Cannot add more values after string has been built");
+ Y_ENSURE(!IsBuilt_, "Cannot add more values after string has been built");
- auto [it, isInserted] = StrMap_.try_emplace(str, Max<ui32>(), 0);
- if (isInserted) {
+ auto [it, isInserted] = StrMap_.try_emplace(str, Max<ui32>(), 0);
+ if (isInserted) {
BytesSize_ += str.size();
it->second.Index = StrVector_.size();
StrVector_.emplace_back(it->first, &it->second);
}
-
- TValue* value = &it->second;
+
+ TValue* value = &it->second;
++value->Frequency;
return value;
}
@@ -23,12 +23,12 @@ namespace NMonitoring {
return StrVector_.at(index).second;
}
- TStringPoolBuilder& TStringPoolBuilder::Build() {
- if (RequiresSorting_) {
- // sort in reversed order
- std::sort(StrVector_.begin(), StrVector_.end(), [](auto& a, auto& b) {
- return a.second->Frequency > b.second->Frequency;
- });
+ TStringPoolBuilder& TStringPoolBuilder::Build() {
+ if (RequiresSorting_) {
+ // sort in reversed order
+ std::sort(StrVector_.begin(), StrVector_.end(), [](auto& a, auto& b) {
+ return a.second->Frequency > b.second->Frequency;
+ });
ui32 i = 0;
for (auto& value : StrVector_) {
@@ -36,9 +36,9 @@ namespace NMonitoring {
}
}
- IsBuilt_ = true;
-
- return *this;
+ IsBuilt_ = true;
+
+ return *this;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/monlib/encode/buffered/string_pool.h b/library/cpp/monlib/encode/buffered/string_pool.h
index 39fab1673f..00e5644608 100644
--- a/library/cpp/monlib/encode/buffered/string_pool.h
+++ b/library/cpp/monlib/encode/buffered/string_pool.h
@@ -9,13 +9,13 @@ namespace NMonitoring {
////////////////////////////////////////////////////////////////////////////////
class TStringPoolBuilder {
public:
- struct TValue: TNonCopyable {
- TValue(ui32 idx, ui32 freq)
- : Index{idx}
- , Frequency{freq}
- {
- }
-
+ struct TValue: TNonCopyable {
+ TValue(ui32 idx, ui32 freq)
+ : Index{idx}
+ , Frequency{freq}
+ {
+ }
+
ui32 Index;
ui32 Frequency;
};
@@ -24,16 +24,16 @@ namespace NMonitoring {
const TValue* PutIfAbsent(TStringBuf str);
const TValue* GetByIndex(ui32 index) const;
- /// Determines whether pool must be sorted by value frequencies
- TStringPoolBuilder& SetSorted(bool sorted) {
- RequiresSorting_ = sorted;
- return *this;
- }
+ /// Determines whether pool must be sorted by value frequencies
+ TStringPoolBuilder& SetSorted(bool sorted) {
+ RequiresSorting_ = sorted;
+ return *this;
+ }
+
+ TStringPoolBuilder& Build();
- TStringPoolBuilder& Build();
-
TStringBuf Get(ui32 index) const {
- Y_ENSURE(IsBuilt_, "Pool must be sorted first");
+ Y_ENSURE(IsBuilt_, "Pool must be sorted first");
return StrVector_.at(index).first;
}
@@ -43,7 +43,7 @@ namespace NMonitoring {
template <typename TConsumer>
void ForEach(TConsumer&& c) {
- Y_ENSURE(IsBuilt_, "Pool must be sorted first");
+ Y_ENSURE(IsBuilt_, "Pool must be sorted first");
for (const auto& value : StrVector_) {
c(value.first, value.second->Index, value.second->Frequency);
}
@@ -60,8 +60,8 @@ namespace NMonitoring {
private:
THashMap<TString, TValue> StrMap_;
TVector<std::pair<TStringBuf, TValue*>> StrVector_;
- bool RequiresSorting_ = false;
- bool IsBuilt_ = false;
+ bool RequiresSorting_ = false;
+ bool IsBuilt_ = false;
size_t BytesSize_ = 0;
};
diff --git a/library/cpp/monlib/encode/buffered/string_pool_ut.cpp b/library/cpp/monlib/encode/buffered/string_pool_ut.cpp
index e597b0c23d..9fc3421d0b 100644
--- a/library/cpp/monlib/encode/buffered/string_pool_ut.cpp
+++ b/library/cpp/monlib/encode/buffered/string_pool_ut.cpp
@@ -7,8 +7,8 @@ using namespace NMonitoring;
Y_UNIT_TEST_SUITE(TStringPoolTest) {
Y_UNIT_TEST(PutIfAbsent) {
TStringPoolBuilder strPool;
- strPool.SetSorted(true);
-
+ strPool.SetSorted(true);
+
auto* h1 = strPool.PutIfAbsent("one");
auto* h2 = strPool.PutIfAbsent("two");
auto* h3 = strPool.PutIfAbsent("two");
@@ -27,15 +27,15 @@ Y_UNIT_TEST_SUITE(TStringPoolTest) {
Y_UNIT_TEST(SortByFrequency) {
TStringPoolBuilder strPool;
- strPool.SetSorted(true);
-
+ strPool.SetSorted(true);
+
auto* h1 = strPool.PutIfAbsent("one");
auto* h2 = strPool.PutIfAbsent("two");
auto* h3 = strPool.PutIfAbsent("two");
UNIT_ASSERT(h1 != h2);
UNIT_ASSERT(h2 == h3);
- strPool.Build();
+ strPool.Build();
UNIT_ASSERT_VALUES_EQUAL(h1->Frequency, 1);
UNIT_ASSERT_VALUES_EQUAL(h1->Index, 1);
@@ -61,7 +61,7 @@ Y_UNIT_TEST_SUITE(TStringPoolTest) {
UNIT_ASSERT_VALUES_EQUAL(strPool.BytesSize(), 11);
UNIT_ASSERT_VALUES_EQUAL(strPool.Count(), 3);
- strPool.Build();
+ strPool.Build();
TVector<TString> strings;
TVector<ui32> indexes;
diff --git a/library/cpp/monlib/encode/buffered/ut/ya.make b/library/cpp/monlib/encode/buffered/ut/ya.make
index 3020c035d5..2157ac1490 100644
--- a/library/cpp/monlib/encode/buffered/ut/ya.make
+++ b/library/cpp/monlib/encode/buffered/ut/ya.make
@@ -1,12 +1,12 @@
UNITTEST_FOR(library/cpp/monlib/encode/buffered)
-
+
OWNER(
g:solomon
jamel
)
-
-SRCS(
- string_pool_ut.cpp
-)
-
-END()
+
+SRCS(
+ string_pool_ut.cpp
+)
+
+END()
diff --git a/library/cpp/monlib/encode/buffered/ya.make b/library/cpp/monlib/encode/buffered/ya.make
index ae749f5a16..81b6a78b93 100644
--- a/library/cpp/monlib/encode/buffered/ya.make
+++ b/library/cpp/monlib/encode/buffered/ya.make
@@ -1,19 +1,19 @@
-LIBRARY()
-
+LIBRARY()
+
OWNER(
g:solomon
jamel
msherbakov
)
-
-SRCS(
- buffered_encoder_base.cpp
- string_pool.cpp
-)
-
-PEERDIR(
+
+SRCS(
+ buffered_encoder_base.cpp
+ string_pool.cpp
+)
+
+PEERDIR(
library/cpp/monlib/encode
library/cpp/monlib/metrics
-)
-
-END()
+)
+
+END()