This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kudu.git
commit 93006dce92cb8c7cf716a87312d3cc9493c62d2b Author: zhangyifan27 <[email protected]> AuthorDate: Thu May 14 19:15:20 2020 +0800 [metrics] fix MeanGauge::snapshot() MeanGauge::snapshot() will always return a metric whose total_sum/total_count is ‘0' because there is a bug in the method, that leads to wrong values when MeanGauge metrics merged. Change-Id: I15f5e0705759a4bdd513089885aaaea4f5332ce1 Reviewed-on: http://gerrit.cloudera.org:8080/15916 Reviewed-by: Andrew Wong <[email protected]> Tested-by: Andrew Wong <[email protected]> --- src/kudu/util/metrics-test.cc | 12 ++++++++++++ src/kudu/util/metrics.cc | 1 + 2 files changed, 13 insertions(+) diff --git a/src/kudu/util/metrics-test.cc b/src/kudu/util/metrics-test.cc index 136ba72..5664a4f 100644 --- a/src/kudu/util/metrics-test.cc +++ b/src/kudu/util/metrics-test.cc @@ -186,6 +186,18 @@ TEST_F(MetricsTest, SimpleMeanGaugeTest) { ASSERT_EQ(2.5, average_usage->value()); } +TEST_F(MetricsTest, SimpleMeanGaugeSnapshotTest) { + scoped_refptr<MeanGauge> average_usage = + METRIC_test_mean_gauge.InstantiateMeanGauge(entity_); + scoped_refptr<MeanGauge> old_metric = + down_cast<MeanGauge*>(average_usage->snapshot().get()); + ASSERT_EQ(0, old_metric->value()); + average_usage->set_value(10.0, 2.0); + scoped_refptr<MeanGauge> new_metric = + down_cast<MeanGauge*>(average_usage->snapshot().get()); + ASSERT_EQ(5, new_metric->value()); +} + TEST_F(MetricsTest, SimpleMeanGaugeMergeTest) { scoped_refptr<MeanGauge> average_usage = METRIC_test_mean_gauge.InstantiateMeanGauge(entity_); diff --git a/src/kudu/util/metrics.cc b/src/kudu/util/metrics.cc index a48f870..39bc450 100644 --- a/src/kudu/util/metrics.cc +++ b/src/kudu/util/metrics.cc @@ -800,6 +800,7 @@ void StringGauge::WriteValue(JsonWriter* writer) const { scoped_refptr<Metric> MeanGauge::snapshot() const { std::lock_guard<simple_spinlock> l(lock_); auto p = new MeanGauge(down_cast<const GaugePrototype<double>*>(prototype_)); + p->set_value(total_sum_, total_count_); p->m_epoch_.store(m_epoch_); p->invalid_for_merge_ = invalid_for_merge_; p->retire_time_ = retire_time_;
