You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2025/08/19 16:06:24 UTC

(kudu) branch master updated: [metrics] proper metric name in warning message

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


The following commit(s) were added to refs/heads/master by this push:
     new b89ee8ae5 [metrics] proper metric name in warning message
b89ee8ae5 is described below

commit b89ee8ae58c258de8ad387d5824469cb45c660aa
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Mon Aug 18 12:51:02 2025 -0700

    [metrics] proper metric name in warning message
    
    This patch fixes a typo in WriteMetricsPrometheus() if printing a
    warning message.  I also took the liberty of adding extra DCHECK()
    assertions to make sure names and descriptions of metric prototypes
    aren't null.
    
    This changelist doesn't contain any functional modifications.
    
    Change-Id: I60dc827486b029973cea82a00af92b415c5d78ac
    Reviewed-on: http://gerrit.cloudera.org:8080/23306
    Reviewed-by: Marton Greber <gr...@gmail.com>
    Tested-by: Marton Greber <gr...@gmail.com>
---
 src/kudu/util/metrics.cc | 10 +++++-----
 src/kudu/util/metrics.h  |  6 +++++-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/kudu/util/metrics.cc b/src/kudu/util/metrics.cc
index b2b33c2ed..91f1fc5da 100644
--- a/src/kudu/util/metrics.cc
+++ b/src/kudu/util/metrics.cc
@@ -73,10 +73,10 @@ void WriteMetricsToJson(JsonWriter* writer,
 void WriteMetricsPrometheus(PrometheusWriter* writer,
                             const MetricEntity::MetricMap& metrics,
                             const string& prefix) {
-  for (const auto& [name, val] : metrics) {
+  for (const auto& [_, val] : metrics) {
     WARN_NOT_OK(val->WriteAsPrometheus(writer, prefix),
                 Substitute("unable to write '$0' ($1) in Prometheus format",
-                           name, val->prototype()->description()));
+                           val->prototype()->name(), val->prototype()->description()));
   }
 }
 
@@ -288,8 +288,8 @@ int MetricLevelNumeric(MetricLevel level) {
 Status MetricEntity::GetMetricsAndAttrs(const MetricFilters& filters,
                                         MetricMap* metrics,
                                         AttributeMap* attrs) const {
-  CHECK(metrics);
-  CHECK(attrs);
+  DCHECK(metrics);
+  DCHECK(attrs);
 
   // Filter the 'type'.
   if (!filters.entity_types.empty() && !MatchNameInList(prototype_->name(), filters.entity_types)) {
@@ -791,7 +791,7 @@ scoped_refptr<MetricEntity> MetricRegistry::FindOrCreateEntity(
 std::atomic<int64_t> Metric::g_epoch_;
 
 Metric::Metric(const MetricPrototype* prototype)
-    : prototype_(prototype),
+    : prototype_(DCHECK_NOTNULL(prototype)),
       m_epoch_(current_epoch()) {
 }
 
diff --git a/src/kudu/util/metrics.h b/src/kudu/util/metrics.h
index 9212a9039..adcfb23cf 100644
--- a/src/kudu/util/metrics.h
+++ b/src/kudu/util/metrics.h
@@ -569,6 +569,10 @@ class MetricPrototype {
         description_(description),
         level_(level),
         flags_(flags) {
+      DCHECK(entity_type);
+      DCHECK(name);
+      DCHECK(label);
+      DCHECK(description);
     }
 
     const char* const entity_type_;
@@ -750,7 +754,7 @@ class MetricEntity : public RefCountedThreadSafe<MetricEntity> {
 
   mutable simple_spinlock lock_;
 
-  // Map from metric name to Metric object. Protected by lock_.
+  // Map from metric prototype pointer to Metric object. Protected by lock_.
   MetricMap metric_map_;
 
   // The key/value attributes. Protected by lock_.