Browse Source

Restoring authorship annotation for <rorewillo@yandex-team.ru>. Commit 2 of 2.

rorewillo 3 years ago
parent
commit
7b34adcce0

+ 1 - 1
library/cpp/monlib/encode/json/json.h

@@ -24,6 +24,6 @@ namespace NMonitoring {
                                                int indentation = 0,
                                                int indentation = 0,
                                                TStringBuf metricNameLabel = "name");
                                                TStringBuf metricNameLabel = "name");
 
 
-    void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel = "name"); 
+    void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel = "name");
 
 
 }
 }

+ 15 - 15
library/cpp/monlib/encode/json/json_decoder.cpp

@@ -439,7 +439,7 @@ class TDecoderJson final: public NJson::TJsonCallbacks {
             METRICS_ARRAY,
             METRICS_ARRAY,
 
 
             METRIC_OBJECT,
             METRIC_OBJECT,
-            METRIC_NAME, 
+            METRIC_NAME,
             METRIC_LABELS,
             METRIC_LABELS,
             METRIC_TYPE,
             METRIC_TYPE,
             METRIC_MODE, // TODO: must be deleted
             METRIC_MODE, // TODO: must be deleted
@@ -482,10 +482,10 @@ class TDecoderJson final: public NJson::TJsonCallbacks {
     };
     };
 
 
 public:
 public:
-    TDecoderJson(TStringBuf data, IHaltableMetricConsumer* metricConsumer, TStringBuf metricNameLabel) 
+    TDecoderJson(TStringBuf data, IHaltableMetricConsumer* metricConsumer, TStringBuf metricNameLabel)
         : Data_(data)
         : Data_(data)
         , MetricConsumer_(metricConsumer)
         , MetricConsumer_(metricConsumer)
-        , MetricNameLabel_(metricNameLabel) 
+        , MetricNameLabel_(metricNameLabel)
     {
     {
     }
     }
 
 
@@ -725,12 +725,12 @@ if (Y_UNLIKELY(!(CONDITION))) {                  \
                 LastMetric_.Labels.Add(LastLabelName_, TString{value});
                 LastMetric_.Labels.Add(LastLabelName_, TString{value});
                 break;
                 break;
 
 
-            case TState::METRIC_NAME: 
-                PARSE_ENSURE(!value.empty(), "empty metric name"); 
-                LastMetric_.Labels.Add(MetricNameLabel_, TString{value}); 
-                State_.ToPrev(); 
-                break; 
- 
+            case TState::METRIC_NAME:
+                PARSE_ENSURE(!value.empty(), "empty metric name");
+                LastMetric_.Labels.Add(MetricNameLabel_, TString{value});
+                State_.ToPrev();
+                break;
+
             case TState::COMMON_TS:
             case TState::COMMON_TS:
                 MetricConsumer_->OnCommonTime(TInstant::ParseIso8601(value));
                 MetricConsumer_->OnCommonTime(TInstant::ParseIso8601(value));
                 State_.ToPrev();
                 State_.ToPrev();
@@ -831,8 +831,8 @@ if (Y_UNLIKELY(!(CONDITION))) {                  \
             case TState::METRIC_OBJECT:
             case TState::METRIC_OBJECT:
                 if (key == TStringBuf("labels")) {
                 if (key == TStringBuf("labels")) {
                     State_.ToNext(TState::METRIC_LABELS);
                     State_.ToNext(TState::METRIC_LABELS);
-                } else if (key == TStringBuf("name")) { 
-                    State_.ToNext(TState::METRIC_NAME); 
+                } else if (key == TStringBuf("name")) {
+                    State_.ToNext(TState::METRIC_NAME);
                 } else if (key == TStringBuf("ts")) {
                 } else if (key == TStringBuf("ts")) {
                     PARSE_ENSURE(!LastMetric_.SeenTimeseries,
                     PARSE_ENSURE(!LastMetric_.SeenTimeseries,
                              "mixed timeseries and ts attributes");
                              "mixed timeseries and ts attributes");
@@ -1129,7 +1129,7 @@ if (Y_UNLIKELY(!(CONDITION))) {                  \
 private:
 private:
     TStringBuf Data_;
     TStringBuf Data_;
     IHaltableMetricConsumer* MetricConsumer_;
     IHaltableMetricConsumer* MetricConsumer_;
-    TString MetricNameLabel_; 
+    TString MetricNameLabel_;
     TState State_;
     TState State_;
     TString LastLabelName_;
     TString LastLabelName_;
     TMetricCollector LastMetric_;
     TMetricCollector LastMetric_;
@@ -1139,11 +1139,11 @@ private:
 
 
 } // namespace
 } // namespace
 
 
-void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel) { 
+void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel) {
     TCommonPartsCollector commonPartsCollector;
     TCommonPartsCollector commonPartsCollector;
     {
     {
         TMemoryInput memIn(data);
         TMemoryInput memIn(data);
-        TDecoderJson decoder(data, &commonPartsCollector, metricNameLabel); 
+        TDecoderJson decoder(data, &commonPartsCollector, metricNameLabel);
         // no need to check a return value. If there is an error, a TJsonDecodeError is thrown
         // no need to check a return value. If there is an error, a TJsonDecodeError is thrown
         NJson::ReadJson(&memIn, &decoder);
         NJson::ReadJson(&memIn, &decoder);
     }
     }
@@ -1151,7 +1151,7 @@ void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel)
     TCommonPartsProxy commonPartsProxy(std::move(commonPartsCollector.CommonParts()), c);
     TCommonPartsProxy commonPartsProxy(std::move(commonPartsCollector.CommonParts()), c);
     {
     {
         TMemoryInput memIn(data);
         TMemoryInput memIn(data);
-        TDecoderJson decoder(data, &commonPartsProxy, metricNameLabel); 
+        TDecoderJson decoder(data, &commonPartsProxy, metricNameLabel);
         // no need to check a return value. If there is an error, a TJsonDecodeError is thrown
         // no need to check a return value. If there is an error, a TJsonDecodeError is thrown
         NJson::ReadJson(&memIn, &decoder);
         NJson::ReadJson(&memIn, &decoder);
     }
     }

+ 2 - 2
library/cpp/monlib/encode/json/json_decoder_ut.cpp

@@ -73,10 +73,10 @@ void ValidateMetrics(const TVector<TMetricData>& metrics) {
     UNIT_ASSERT_VALUES_EQUAL((*m.Values)[0].GetValue().AsDouble(), 123);
     UNIT_ASSERT_VALUES_EQUAL((*m.Values)[0].GetValue().AsDouble(), 123);
 }
 }
 
 
-void CheckCommonPartsCollector(TString data, bool shouldBeStopped, bool checkLabels = true, bool checkTs = true, TStringBuf metricNameLabel = "name") { 
+void CheckCommonPartsCollector(TString data, bool shouldBeStopped, bool checkLabels = true, bool checkTs = true, TStringBuf metricNameLabel = "name") {
     TCommonPartsCollector commonPartsCollector;
     TCommonPartsCollector commonPartsCollector;
     TMemoryInput memIn(data);
     TMemoryInput memIn(data);
-    TDecoderJson decoder(data, &commonPartsCollector, metricNameLabel); 
+    TDecoderJson decoder(data, &commonPartsCollector, metricNameLabel);
 
 
     bool isOk{false};
     bool isOk{false};
     UNIT_ASSERT_NO_EXCEPTION(isOk = NJson::ReadJson(&memIn, &decoder));
     UNIT_ASSERT_NO_EXCEPTION(isOk = NJson::ReadJson(&memIn, &decoder));

+ 23 - 23
library/cpp/monlib/encode/json/json_ut.cpp

@@ -1264,27 +1264,27 @@ Y_UNIT_TEST_SUITE(TJsonTest) {
         UNIT_ASSERT_EXCEPTION(DecodeJson(input, e.Get()), yexception);
         UNIT_ASSERT_EXCEPTION(DecodeJson(input, e.Get()), yexception);
     }
     }
 
 
-    Y_UNIT_TEST(DecodeNamedMetrics) { 
-        NProto::TMultiSamplesList samples; 
-        { 
-            IMetricEncoderPtr e = EncoderProtobuf(&samples); 
- 
-            TString metricsJson = NResource::Find("/named_metrics.json"); 
-            DecodeJson(metricsJson, e.Get(), "sensor"); 
-        } 
- 
-        UNIT_ASSERT_VALUES_EQUAL(samples.SamplesSize(), 2); 
-        { 
-            const NProto::TMultiSample& s = samples.GetSamples(0); 
-            UNIT_ASSERT_VALUES_EQUAL(s.LabelsSize(), 1); 
-            AssertLabelEqual(s.GetLabels(0), "sensor", "Memory"); 
-        } 
-        { 
-            const NProto::TMultiSample& s = samples.GetSamples(1); 
-            UNIT_ASSERT_VALUES_EQUAL(s.LabelsSize(), 2); 
-            AssertLabelEqual(s.GetLabels(0), "sensor", "QueueSize"); 
-            AssertLabelEqual(s.GetLabels(1), "export", "Oxygen"); 
-        } 
-    } 
- 
+    Y_UNIT_TEST(DecodeNamedMetrics) {
+        NProto::TMultiSamplesList samples;
+        {
+            IMetricEncoderPtr e = EncoderProtobuf(&samples);
+
+            TString metricsJson = NResource::Find("/named_metrics.json");
+            DecodeJson(metricsJson, e.Get(), "sensor");
+        }
+
+        UNIT_ASSERT_VALUES_EQUAL(samples.SamplesSize(), 2);
+        {
+            const NProto::TMultiSample& s = samples.GetSamples(0);
+            UNIT_ASSERT_VALUES_EQUAL(s.LabelsSize(), 1);
+            AssertLabelEqual(s.GetLabels(0), "sensor", "Memory");
+        }
+        {
+            const NProto::TMultiSample& s = samples.GetSamples(1);
+            UNIT_ASSERT_VALUES_EQUAL(s.LabelsSize(), 2);
+            AssertLabelEqual(s.GetLabels(0), "sensor", "QueueSize");
+            AssertLabelEqual(s.GetLabels(1), "export", "Oxygen");
+        }
+    }
+
 }
 }

+ 22 - 22
library/cpp/monlib/encode/json/ut/named_metrics.json

@@ -1,22 +1,22 @@
-{ 
-  "labels": { 
-    "project": "solomon", 
-    "cluster": "prod-sas", 
-    "service": "stockpile" 
-  }, 
-  "metrics": [ 
-    { 
-      "type": "DGAUGE", 
-      "name": "Memory", 
-      "value": 1 
-    }, 
-    { 
-      "type": "DGAUGE", 
-      "name": "QueueSize", 
-      "labels": { 
-        "export": "Oxygen" 
-      }, 
-      "value": 10 
-    } 
-  ] 
-} 
+{
+  "labels": {
+    "project": "solomon",
+    "cluster": "prod-sas",
+    "service": "stockpile"
+  },
+  "metrics": [
+    {
+      "type": "DGAUGE",
+      "name": "Memory",
+      "value": 1
+    },
+    {
+      "type": "DGAUGE",
+      "name": "QueueSize",
+      "labels": {
+        "export": "Oxygen"
+      },
+      "value": 10
+    }
+  ]
+}

+ 1 - 1
library/cpp/monlib/encode/json/ut/ya.make

@@ -25,7 +25,7 @@ RESOURCE(
     int_gauge.json /int_gauge.json
     int_gauge.json /int_gauge.json
     sensors.json /sensors.json
     sensors.json /sensors.json
     metrics.json /metrics.json
     metrics.json /metrics.json
-    named_metrics.json /named_metrics.json 
+    named_metrics.json /named_metrics.json
     test_decode_to_encode.json /test_decode_to_encode.json
     test_decode_to_encode.json /test_decode_to_encode.json
     crash.json /crash.json
     crash.json /crash.json
     hist_crash.json /hist_crash.json
     hist_crash.json /hist_crash.json

+ 1 - 1
library/cpp/monlib/encode/prometheus/prometheus_decoder.cpp

@@ -518,7 +518,7 @@ namespace NMonitoring {
             void ConsumeLabels(TStringBuf name, const TLabelsMap& labels) {
             void ConsumeLabels(TStringBuf name, const TLabelsMap& labels) {
                 Y_PARSER_ENSURE(labels.count(MetricNameLabel_) == 0,
                 Y_PARSER_ENSURE(labels.count(MetricNameLabel_) == 0,
                     "label name '" << MetricNameLabel_ <<
                     "label name '" << MetricNameLabel_ <<
-                    "' is reserved, but is used with metric: " << name << LabelsToStr(labels)); 
+                    "' is reserved, but is used with metric: " << name << LabelsToStr(labels));
 
 
                 Consumer_->OnLabelsBegin();
                 Consumer_->OnLabelsBegin();
                 Consumer_->OnLabel(MetricNameLabel_, TString(name)); // TODO: remove this string allocation
                 Consumer_->OnLabel(MetricNameLabel_, TString(name)); // TODO: remove this string allocation