Browse Source

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

rorewillo 3 years ago
parent
commit
708f3525ba

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

@@ -24,6 +24,6 @@ namespace NMonitoring {
                                                int indentation = 0,
                                                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,
 
             METRIC_OBJECT,
-            METRIC_NAME,
+            METRIC_NAME, 
             METRIC_LABELS,
             METRIC_TYPE,
             METRIC_MODE, // TODO: must be deleted
@@ -482,10 +482,10 @@ class TDecoderJson final: public NJson::TJsonCallbacks {
     };
 
 public:
-    TDecoderJson(TStringBuf data, IHaltableMetricConsumer* metricConsumer, TStringBuf metricNameLabel)
+    TDecoderJson(TStringBuf data, IHaltableMetricConsumer* metricConsumer, TStringBuf metricNameLabel) 
         : Data_(data)
         , MetricConsumer_(metricConsumer)
-        , MetricNameLabel_(metricNameLabel)
+        , MetricNameLabel_(metricNameLabel) 
     {
     }
 
@@ -725,12 +725,12 @@ if (Y_UNLIKELY(!(CONDITION))) {                  \
                 LastMetric_.Labels.Add(LastLabelName_, TString{value});
                 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:
                 MetricConsumer_->OnCommonTime(TInstant::ParseIso8601(value));
                 State_.ToPrev();
@@ -831,8 +831,8 @@ if (Y_UNLIKELY(!(CONDITION))) {                  \
             case TState::METRIC_OBJECT:
                 if (key == TStringBuf("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")) {
                     PARSE_ENSURE(!LastMetric_.SeenTimeseries,
                              "mixed timeseries and ts attributes");
@@ -1129,7 +1129,7 @@ if (Y_UNLIKELY(!(CONDITION))) {                  \
 private:
     TStringBuf Data_;
     IHaltableMetricConsumer* MetricConsumer_;
-    TString MetricNameLabel_;
+    TString MetricNameLabel_; 
     TState State_;
     TString LastLabelName_;
     TMetricCollector LastMetric_;
@@ -1139,11 +1139,11 @@ private:
 
 } // namespace
 
-void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel) {
+void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel) { 
     TCommonPartsCollector commonPartsCollector;
     {
         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
         NJson::ReadJson(&memIn, &decoder);
     }
@@ -1151,7 +1151,7 @@ void DecodeJson(TStringBuf data, IMetricConsumer* c, TStringBuf metricNameLabel)
     TCommonPartsProxy commonPartsProxy(std::move(commonPartsCollector.CommonParts()), c);
     {
         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
         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);
 }
 
-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;
     TMemoryInput memIn(data);
-    TDecoderJson decoder(data, &commonPartsCollector, metricNameLabel);
+    TDecoderJson decoder(data, &commonPartsCollector, metricNameLabel); 
 
     bool isOk{false};
     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);
     }
 
-    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
     sensors.json /sensors.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
     crash.json /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) {
                 Y_PARSER_ENSURE(labels.count(MetricNameLabel_) == 0,
                     "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_->OnLabel(MetricNameLabel_, TString(name)); // TODO: remove this string allocation