diff options
author | tobo <tobo@yandex-team.ru> | 2022-02-10 16:47:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:27 +0300 |
commit | 7fe839092527589b38f014d854c51565b3c1adfa (patch) | |
tree | 309e97022d3530044b712b8f71318c78faf7856e /library/cpp/monlib/encode/json | |
parent | d0d68c395c10da4cb56a1c845504570a04d7893e (diff) | |
download | ydb-7fe839092527589b38f014d854c51565b3c1adfa.tar.gz |
Restoring authorship annotation for <tobo@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/monlib/encode/json')
-rw-r--r-- | library/cpp/monlib/encode/json/json_decoder.cpp | 68 | ||||
-rw-r--r-- | library/cpp/monlib/encode/json/json_decoder_ut.cpp | 14 | ||||
-rw-r--r-- | library/cpp/monlib/encode/json/json_encoder.cpp | 50 |
3 files changed, 66 insertions, 66 deletions
diff --git a/library/cpp/monlib/encode/json/json_decoder.cpp b/library/cpp/monlib/encode/json/json_decoder.cpp index d44ff5fd28..8777caa021 100644 --- a/library/cpp/monlib/encode/json/json_decoder.cpp +++ b/library/cpp/monlib/encode/json/json_decoder.cpp @@ -172,11 +172,11 @@ private: }; std::pair<double, bool> ParseSpecDouble(TStringBuf string) { - if (string == TStringBuf("nan") || string == TStringBuf("NaN")) { + if (string == TStringBuf("nan") || string == TStringBuf("NaN")) { return {std::numeric_limits<double>::quiet_NaN(), true}; - } else if (string == TStringBuf("inf") || string == TStringBuf("Infinity")) { + } else if (string == TStringBuf("inf") || string == TStringBuf("Infinity")) { return {std::numeric_limits<double>::infinity(), true}; - } else if (string == TStringBuf("-inf") || string == TStringBuf("-Infinity")) { + } else if (string == TStringBuf("-inf") || string == TStringBuf("-Infinity")) { return {-std::numeric_limits<double>::infinity(), true}; } else { return {0, false}; @@ -762,7 +762,7 @@ if (Y_UNLIKELY(!(CONDITION))) { \ break; case TState::METRIC_MODE: - if (value == TStringBuf("deriv")) { + if (value == TStringBuf("deriv")) { LastMetric_.Type = EMetricType::RATE; } State_.ToPrev(); @@ -814,11 +814,11 @@ if (Y_UNLIKELY(!(CONDITION))) { \ bool OnMapKey(const TStringBuf& key) override { switch (State_.Current()) { case TState::ROOT_OBJECT: - if (key == TStringBuf("commonLabels") || key == TStringBuf("labels")) { + if (key == TStringBuf("commonLabels") || key == TStringBuf("labels")) { State_.ToNext(TState::COMMON_LABELS); - } else if (key == TStringBuf("ts")) { + } else if (key == TStringBuf("ts")) { State_.ToNext(TState::COMMON_TS); - } else if (key == TStringBuf("sensors") || key == TStringBuf("metrics")) { + } else if (key == TStringBuf("sensors") || key == TStringBuf("metrics")) { State_.ToNext(TState::METRICS_ARRAY); } break; @@ -829,36 +829,36 @@ if (Y_UNLIKELY(!(CONDITION))) { \ break; case TState::METRIC_OBJECT: - if (key == TStringBuf("labels")) { + if (key == TStringBuf("labels")) { State_.ToNext(TState::METRIC_LABELS); } else if (key == TStringBuf("name")) { State_.ToNext(TState::METRIC_NAME); - } else if (key == TStringBuf("ts")) { + } else if (key == TStringBuf("ts")) { PARSE_ENSURE(!LastMetric_.SeenTimeseries, "mixed timeseries and ts attributes"); LastMetric_.SeenTsOrValue = true; State_.ToNext(TState::METRIC_TS); - } else if (key == TStringBuf("value")) { + } else if (key == TStringBuf("value")) { PARSE_ENSURE(!LastMetric_.SeenTimeseries, "mixed timeseries and value attributes"); LastMetric_.SeenTsOrValue = true; State_.ToNext(TState::METRIC_VALUE); - } else if (key == TStringBuf("timeseries")) { + } else if (key == TStringBuf("timeseries")) { PARSE_ENSURE(!LastMetric_.SeenTsOrValue, "mixed timeseries and ts/value attributes"); LastMetric_.SeenTimeseries = true; State_.ToNext(TState::METRIC_TIMESERIES); - } else if (key == TStringBuf("mode")) { + } else if (key == TStringBuf("mode")) { State_.ToNext(TState::METRIC_MODE); - } else if (key == TStringBuf("kind") || key == TStringBuf("type")) { + } else if (key == TStringBuf("kind") || key == TStringBuf("type")) { State_.ToNext(TState::METRIC_TYPE); - } else if (key == TStringBuf("hist")) { + } else if (key == TStringBuf("hist")) { State_.ToNext(TState::METRIC_HIST); - } else if (key == TStringBuf("summary")) { + } else if (key == TStringBuf("summary")) { State_.ToNext(TState::METRIC_DSUMMARY); - } else if (key == TStringBuf("log_hist")) { + } else if (key == TStringBuf("log_hist")) { State_.ToNext(TState::METRIC_LOG_HIST); - } else if (key == TStringBuf("memOnly")) { + } else if (key == TStringBuf("memOnly")) { // deprecated. Skip it without errors for backward compatibility } else { ErrorMsg_ = TStringBuilder() << "unexpected key \"" << key << "\" in a metric schema"; @@ -867,51 +867,51 @@ if (Y_UNLIKELY(!(CONDITION))) { \ break; case TState::METRIC_TIMESERIES: - if (key == TStringBuf("ts")) { + if (key == TStringBuf("ts")) { State_.ToNext(TState::METRIC_TS); - } else if (key == TStringBuf("value")) { + } else if (key == TStringBuf("value")) { State_.ToNext(TState::METRIC_VALUE); - } else if (key == TStringBuf("hist")) { + } else if (key == TStringBuf("hist")) { State_.ToNext(TState::METRIC_HIST); - } else if (key == TStringBuf("summary")) { + } else if (key == TStringBuf("summary")) { State_.ToNext(TState::METRIC_DSUMMARY); - } else if (key == TStringBuf("log_hist")) { + } else if (key == TStringBuf("log_hist")) { State_.ToNext(TState::METRIC_LOG_HIST); } break; case TState::METRIC_HIST: - if (key == TStringBuf("bounds")) { + if (key == TStringBuf("bounds")) { State_.ToNext(TState::METRIC_HIST_BOUNDS); - } else if (key == TStringBuf("buckets")) { + } else if (key == TStringBuf("buckets")) { State_.ToNext(TState::METRIC_HIST_BUCKETS); - } else if (key == TStringBuf("inf")) { + } else if (key == TStringBuf("inf")) { State_.ToNext(TState::METRIC_HIST_INF); } break; case TState::METRIC_LOG_HIST: - if (key == TStringBuf("base")) { + if (key == TStringBuf("base")) { State_.ToNext(TState::METRIC_LOG_HIST_BASE); - } else if (key == TStringBuf("zeros_count")) { + } else if (key == TStringBuf("zeros_count")) { State_.ToNext(TState::METRIC_LOG_HIST_ZEROS); - } else if (key == TStringBuf("start_power")) { + } else if (key == TStringBuf("start_power")) { State_.ToNext(TState::METRIC_LOG_HIST_START_POWER); - } else if (key == TStringBuf("buckets")) { + } else if (key == TStringBuf("buckets")) { State_.ToNext(TState::METRIC_LOG_HIST_BUCKETS); } break; case TState::METRIC_DSUMMARY: - if (key == TStringBuf("sum")) { + if (key == TStringBuf("sum")) { State_.ToNext(TState::METRIC_DSUMMARY_SUM); - } else if (key == TStringBuf("min")) { + } else if (key == TStringBuf("min")) { State_.ToNext(TState::METRIC_DSUMMARY_MIN); - } else if (key == TStringBuf("max")) { + } else if (key == TStringBuf("max")) { State_.ToNext(TState::METRIC_DSUMMARY_MAX); - } else if (key == TStringBuf("last")) { + } else if (key == TStringBuf("last")) { State_.ToNext(TState::METRIC_DSUMMARY_LAST); - } else if (key == TStringBuf("count")) { + } else if (key == TStringBuf("count")) { State_.ToNext(TState::METRIC_DSUMMARY_COUNT); } diff --git a/library/cpp/monlib/encode/json/json_decoder_ut.cpp b/library/cpp/monlib/encode/json/json_decoder_ut.cpp index 4464e1d26a..6c047f96e5 100644 --- a/library/cpp/monlib/encode/json/json_decoder_ut.cpp +++ b/library/cpp/monlib/encode/json/json_decoder_ut.cpp @@ -15,15 +15,15 @@ enum EJsonPart : ui8 { }; constexpr std::array<TStringBuf, 3> JSON_PARTS = { - TStringBuf(R"("metrics": [{ + TStringBuf(R"("metrics": [{ "labels": { "key": "value" }, "type": "GAUGE", "value": 123 }])"), - TStringBuf(R"("ts": 1)"), + TStringBuf(R"("ts": 1)"), - TStringBuf(R"("commonLabels": { + TStringBuf(R"("commonLabels": { "key1": "value1", "key2": "value2" })"), @@ -52,10 +52,10 @@ void ValidateCommonParts(TCommonParts&& commonParts, bool checkLabels, bool chec if (checkLabels) { auto& labels = commonParts.CommonLabels; UNIT_ASSERT_VALUES_EQUAL(labels.Size(), 2); - UNIT_ASSERT(labels.Has(TStringBuf("key1"))); - UNIT_ASSERT(labels.Has(TStringBuf("key2"))); - UNIT_ASSERT_VALUES_EQUAL(labels.Get(TStringBuf("key1")).value()->Value(), "value1"); - UNIT_ASSERT_VALUES_EQUAL(labels.Get(TStringBuf("key2")).value()->Value(), "value2"); + UNIT_ASSERT(labels.Has(TStringBuf("key1"))); + UNIT_ASSERT(labels.Has(TStringBuf("key2"))); + UNIT_ASSERT_VALUES_EQUAL(labels.Get(TStringBuf("key1")).value()->Value(), "value1"); + UNIT_ASSERT_VALUES_EQUAL(labels.Get(TStringBuf("key2")).value()->Value(), "value2"); } } diff --git a/library/cpp/monlib/encode/json/json_encoder.cpp b/library/cpp/monlib/encode/json/json_encoder.cpp index 20d2bb6283..7a6d6406e7 100644 --- a/library/cpp/monlib/encode/json/json_encoder.cpp +++ b/library/cpp/monlib/encode/json/json_encoder.cpp @@ -36,7 +36,7 @@ namespace NMonitoring { void WriteTime(TInstant time) { if (time != TInstant::Zero()) { - Buf_.WriteKey(TStringBuf("ts")); + Buf_.WriteKey(TStringBuf("ts")); if (Style_ == EJsonStyle::Solomon) { Buf_.WriteULongLong(time.Seconds()); } else { @@ -46,24 +46,24 @@ namespace NMonitoring { } void WriteValue(double value) { - Buf_.WriteKey(TStringBuf("value")); + Buf_.WriteKey(TStringBuf("value")); Buf_.WriteDouble(value); } void WriteValue(i64 value) { - Buf_.WriteKey(TStringBuf("value")); + Buf_.WriteKey(TStringBuf("value")); Buf_.WriteLongLong(value); } void WriteValue(ui64 value) { - Buf_.WriteKey(TStringBuf("value")); + Buf_.WriteKey(TStringBuf("value")); Buf_.WriteULongLong(value); } void WriteValue(IHistogramSnapshot* s) { Y_ENSURE(Style_ == EJsonStyle::Solomon); - Buf_.WriteKey(TStringBuf("hist")); + Buf_.WriteKey(TStringBuf("hist")); Buf_.BeginObject(); if (ui32 count = s->Count()) { bool hasInf = (s->UpperBound(count - 1) == Max<double>()); @@ -71,14 +71,14 @@ namespace NMonitoring { count--; } - Buf_.WriteKey(TStringBuf("bounds")); + Buf_.WriteKey(TStringBuf("bounds")); Buf_.BeginList(); for (ui32 i = 0; i < count; i++) { Buf_.WriteDouble(s->UpperBound(i)); } Buf_.EndList(); - Buf_.WriteKey(TStringBuf("buckets")); + Buf_.WriteKey(TStringBuf("buckets")); Buf_.BeginList(); for (ui32 i = 0; i < count; i++) { Buf_.WriteULongLong(s->Value(i)); @@ -86,7 +86,7 @@ namespace NMonitoring { Buf_.EndList(); if (hasInf) { - Buf_.WriteKey(TStringBuf("inf")); + Buf_.WriteKey(TStringBuf("inf")); Buf_.WriteULongLong(s->Value(count)); } } @@ -96,22 +96,22 @@ namespace NMonitoring { void WriteValue(ISummaryDoubleSnapshot* s) { Y_ENSURE(Style_ == EJsonStyle::Solomon); - Buf_.WriteKey(TStringBuf("summary")); + Buf_.WriteKey(TStringBuf("summary")); Buf_.BeginObject(); - Buf_.WriteKey(TStringBuf("sum")); + Buf_.WriteKey(TStringBuf("sum")); Buf_.WriteDouble(s->GetSum()); - Buf_.WriteKey(TStringBuf("min")); + Buf_.WriteKey(TStringBuf("min")); Buf_.WriteDouble(s->GetMin()); - Buf_.WriteKey(TStringBuf("max")); + Buf_.WriteKey(TStringBuf("max")); Buf_.WriteDouble(s->GetMax()); - Buf_.WriteKey(TStringBuf("last")); + Buf_.WriteKey(TStringBuf("last")); Buf_.WriteDouble(s->GetLast()); - Buf_.WriteKey(TStringBuf("count")); + Buf_.WriteKey(TStringBuf("count")); Buf_.WriteULongLong(s->GetCount()); Buf_.EndObject(); @@ -120,19 +120,19 @@ namespace NMonitoring { void WriteValue(TLogHistogramSnapshot* s) { Y_ENSURE(Style_ == EJsonStyle::Solomon); - Buf_.WriteKey(TStringBuf("log_hist")); + Buf_.WriteKey(TStringBuf("log_hist")); Buf_.BeginObject(); - Buf_.WriteKey(TStringBuf("base")); + Buf_.WriteKey(TStringBuf("base")); Buf_.WriteDouble(s->Base()); - Buf_.WriteKey(TStringBuf("zeros_count")); + Buf_.WriteKey(TStringBuf("zeros_count")); Buf_.WriteULongLong(s->ZerosCount()); - Buf_.WriteKey(TStringBuf("start_power")); + Buf_.WriteKey(TStringBuf("start_power")); Buf_.WriteInt(s->StartPower()); - Buf_.WriteKey(TStringBuf("buckets")); + Buf_.WriteKey(TStringBuf("buckets")); Buf_.BeginList(); for (size_t i = 0; i < s->Count(); ++i) { Buf_.WriteDouble(s->Bucket(i)); @@ -239,7 +239,7 @@ namespace NMonitoring { { } - ~TEncoderJson() override { + ~TEncoderJson() override { Close(); } @@ -303,7 +303,7 @@ namespace NMonitoring { Buf_.WriteKey(TStringBuf(Style_ == EJsonStyle::Solomon ? "commonLabels" : "labels")); } else if (State_ == TEncoderState::EState::METRIC) { State_ = TEncoderState::EState::METRIC_LABELS; - Buf_.WriteKey(TStringBuf("labels")); + Buf_.WriteKey(TStringBuf("labels")); } else { State_.ThrowInvalid("expected METRIC or ROOT"); } @@ -381,7 +381,7 @@ namespace NMonitoring { "mixed metric value types in one metric"); if (!TimeSeries_) { - Buf_.WriteKey(TStringBuf("timeseries")); + Buf_.WriteKey(TStringBuf("timeseries")); Buf_.BeginList(); Buf_.BeginObject(); Y_ENSURE(LastPoint_.GetTime() != TInstant::Zero(), @@ -426,7 +426,7 @@ namespace NMonitoring { MetricsMergingMode_ = EMetricsMergingMode::MERGE_METRICS; } - ~TBufferedJsonEncoder() override { + ~TBufferedJsonEncoder() override { Close(); } @@ -490,7 +490,7 @@ namespace NMonitoring { WriteMetricType(metric.MetricType); - Buf_.WriteKey(TStringBuf("labels")); + Buf_.WriteKey(TStringBuf("labels")); WriteLabels(metric.Labels, false); metric.TimeSeries.SortByTs(); @@ -499,7 +499,7 @@ namespace NMonitoring { WriteTime(point.GetTime()); WriteValue(metric.TimeSeries.GetValueType(), point.GetValue()); } else if (metric.TimeSeries.Size() > 1) { - Buf_.WriteKey(TStringBuf("timeseries")); + Buf_.WriteKey(TStringBuf("timeseries")); Buf_.BeginList(); metric.TimeSeries.ForEach([this](TInstant time, EMetricValueType type, TMetricValue value) { Buf_.BeginObject(); |