Repository: kudu Updated Branches: refs/heads/master 2aa1b883c -> 9f93e97a6
Make metrics name matching case-insensitive Some metrics have mixed-case name, for example handler_latency_kudu_tserver_TabletCopyService_BeginTabletCopySession Previously, filtered metrics like /metrics?metrics=copy would omit this metric since "Copy" doesn't match "copy". This fixes it so the above metric would be returned. Change-Id: I49d76f969873c532e7cd297bee6fde13c98c68e7 Reviewed-on: http://gerrit.cloudera.org:8080/9462 Reviewed-by: Adar Dembo <a...@cloudera.com> Tested-by: Kudu Jenkins Project: http://git-wip-us.apache.org/repos/asf/kudu/repo Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/d5b3b519 Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/d5b3b519 Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/d5b3b519 Branch: refs/heads/master Commit: d5b3b5196407402efd86ba7ffee5a890d23fe0d2 Parents: 2aa1b88 Author: Will Berkeley <wdberke...@apache.org> Authored: Wed Feb 28 13:21:28 2018 -0800 Committer: Will Berkeley <wdberke...@gmail.com> Committed: Tue Mar 6 20:21:50 2018 +0000 ---------------------------------------------------------------------- src/kudu/util/metrics-test.cc | 10 ++++++++++ src/kudu/util/metrics.cc | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kudu/blob/d5b3b519/src/kudu/util/metrics-test.cc ---------------------------------------------------------------------- diff --git a/src/kudu/util/metrics-test.cc b/src/kudu/util/metrics-test.cc index 246397d..f8776aa 100644 --- a/src/kudu/util/metrics-test.cc +++ b/src/kudu/util/metrics-test.cc @@ -206,10 +206,20 @@ TEST_F(MetricsTest, JsonPrintTest) { ASSERT_OK(reader.ExtractString(attributes, "test_attr", &attr_value)); ASSERT_EQ("attr_val", attr_value); + // Verify that metric filtering matches on substrings. + out.str(""); + ASSERT_OK(entity_->WriteAsJson(&writer, { "test count" }, MetricJsonOptions())); + ASSERT_STR_CONTAINS(METRIC_test_counter.name(), out.str()); + // Verify that, if we filter for a metric that isn't in this entity, we get no result. out.str(""); ASSERT_OK(entity_->WriteAsJson(&writer, { "not_a_matching_metric" }, MetricJsonOptions())); ASSERT_EQ("", out.str()); + + // Verify that filtering is case-insensitive. + out.str(""); + ASSERT_OK(entity_->WriteAsJson(&writer, { "mY teST coUNteR" }, MetricJsonOptions())); + ASSERT_STR_CONTAINS(METRIC_test_counter.name(), out.str()); } // Test that metrics are retired when they are no longer referenced. http://git-wip-us.apache.org/repos/asf/kudu/blob/d5b3b519/src/kudu/util/metrics.cc ---------------------------------------------------------------------- diff --git a/src/kudu/util/metrics.cc b/src/kudu/util/metrics.cc index 218b08e..4e6afa9 100644 --- a/src/kudu/util/metrics.cc +++ b/src/kudu/util/metrics.cc @@ -31,6 +31,7 @@ #include "kudu/util/hdr_histogram.h" #include "kudu/util/histogram.pb.h" #include "kudu/util/status.h" +#include "kudu/util/string_case.h" DEFINE_int32(metrics_retirement_age_ms, 120 * 1000, "The minimum number of milliseconds a metric will be kept for after it is " @@ -187,11 +188,16 @@ namespace { bool MatchMetricInList(const string& metric_name, const vector<string>& match_params) { + string metric_name_uc; + ToUpperCase(metric_name, &metric_name_uc); + for (const string& param : match_params) { // Handle wildcard. if (param == "*") return true; - // The parameter is a substring match of the metric name. - if (metric_name.find(param) != std::string::npos) { + // The parameter is a case-insensitive substring match of the metric name. + string param_uc; + ToUpperCase(param, ¶m_uc); + if (metric_name_uc.find(param_uc) != std::string::npos) { return true; } }