kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [kudu] branch master updated: metrics: expose 'total_sum' and 'total_count' values for MeanGauge metrics
Date Tue, 24 Dec 2019 05:00:32 GMT
This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new bf3586f  metrics: expose 'total_sum' and 'total_count' values for MeanGauge metrics
bf3586f is described below

commit bf3586f2a59e8fd845c092bba8a91537c410231d
Author: zhangyifan27 <chinazhangyifan@163.com>
AuthorDate: Fri Dec 20 18:30:21 2019 +0800

    metrics: expose 'total_sum' and 'total_count' values for MeanGauge metrics
    
    Change-Id: Id28f693140da79d466af57fd26064a3653ea2995
    Reviewed-on: http://gerrit.cloudera.org:8080/14937
    Reviewed-by: Adar Dembo <adar@cloudera.com>
    Tested-by: Adar Dembo <adar@cloudera.com>
---
 src/kudu/util/metrics-test.cc | 28 ++++++++++++++++++++++++++++
 src/kudu/util/metrics.cc      |  5 +++++
 2 files changed, 33 insertions(+)

diff --git a/src/kudu/util/metrics-test.cc b/src/kudu/util/metrics-test.cc
index 081f294..24ea4d0 100644
--- a/src/kudu/util/metrics-test.cc
+++ b/src/kudu/util/metrics-test.cc
@@ -207,6 +207,34 @@ TEST_F(MetricsTest, SimpleMeanGaugeMergeTest) {
   ASSERT_EQ(4, average_usage_for_merge->value());
 }
 
+TEST_F(MetricsTest, TestMeanGaugeJsonPrint) {
+  scoped_refptr<MeanGauge> test_meangauge =
+    METRIC_test_mean_gauge.InstantiateMeanGauge(entity_);
+  const double kTotalSum = 5.0;
+  const double kTotalCount = 2.0;
+  test_meangauge->set_value(kTotalSum, kTotalCount);
+
+  std::ostringstream out;
+  JsonWriter writer(&out, JsonWriter::PRETTY);
+  CHECK_OK(entity_->WriteAsJson(&writer, MetricJsonOptions()));
+
+  JsonReader reader(out.str());
+  ASSERT_OK(reader.Init());
+  vector<const rapidjson::Value*> metrics;
+  ASSERT_OK(reader.ExtractObjectArray(reader.root(), "metrics", &metrics));
+  ASSERT_EQ(1, metrics.size());
+
+  double total_sum;
+  ASSERT_OK(reader.ExtractDouble(metrics[0], "total_sum", &total_sum));
+  double total_count;
+  ASSERT_OK(reader.ExtractDouble(metrics[0], "total_count", &total_count));
+  double value;
+  ASSERT_OK(reader.ExtractDouble(metrics[0], "value", &value));
+  ASSERT_EQ(total_sum, kTotalSum);
+  ASSERT_EQ(total_count, kTotalCount);
+  ASSERT_EQ(value, kTotalSum/kTotalCount);
+}
+
 METRIC_DEFINE_gauge_uint64(test_entity, test_gauge, "Test uint64 Gauge",
                            MetricUnit::kBytes, "Description of Test Gauge",
                            kudu::MetricLevel::kInfo);
diff --git a/src/kudu/util/metrics.cc b/src/kudu/util/metrics.cc
index 9628447..2ad5eed 100644
--- a/src/kudu/util/metrics.cc
+++ b/src/kudu/util/metrics.cc
@@ -843,6 +843,11 @@ void MeanGauge::MergeFrom(const scoped_refptr<Metric>& other)
{
 
 void MeanGauge::WriteValue(JsonWriter* writer) const {
   writer->Double(value());
+
+  writer->String("total_sum");
+  writer->Double(total_sum());
+  writer->String("total_count");
+  writer->Double(total_count());
 }
 
 //


Mime
View raw message