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 2024/04/02 23:39:05 UTC
(kudu) 02/02: KUDU-3561 skip tablet entities in Prometheus format
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 dd4e37b445da7f367746fb83d92e21b8dc3d8eb8
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Sun Mar 31 21:05:36 2024 -0700
KUDU-3561 skip tablet entities in Prometheus format
Currently, the Prometheus metrics writer outputs only server-level
metrics. Prior to this patch, the Prometheus metrics writer would
output a warning message for every tablet it encounters while iterating
through all the existing metric entities.
This patch addresses the issue: the tablet entries are now silently
skipped, as they should.
I also added a TODO for KUDU-3563 to output tablet-level metrics
in Prometheus format as well.
Change-Id: I618bbc2caab7a8d9812eeaeb67ac42b0293b0654
Reviewed-on: http://gerrit.cloudera.org:8080/21226
Reviewed-by: Mahesh Reddy <mr...@cloudera.com>
Reviewed-by: Abhishek Chennaka <ac...@cloudera.com>
Tested-by: Alexey Serbin <al...@apache.org>
---
src/kudu/util/metrics.cc | 51 +++++++++++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 20 deletions(-)
diff --git a/src/kudu/util/metrics.cc b/src/kudu/util/metrics.cc
index dfcea6db1..0f1590de5 100644
--- a/src/kudu/util/metrics.cc
+++ b/src/kudu/util/metrics.cc
@@ -405,15 +405,25 @@ Status MetricEntity::WriteAsJson(JsonWriter* writer, const MetricJsonOptions& op
}
Status MetricEntity::WriteAsPrometheus(PrometheusWriter* writer) const {
- MetricMap metrics;
- AttributeMap attrs;
+ static const string kIdMaster = "kudu.master";
+ static const string kIdTabletServer = "kudu.tabletserver";
+
+ if (strcmp(prototype_->name(), "server") != 0) {
+ // Only server-level metrics are emitted in Prometheus format as of now,
+ // non-server metric entities are currently silently skipped.
+ //
+ // TODO(KUDU-3563): output tablet-level metrics in Prometheus format as well
+ return Status::OK();
+ }
+
+ // Empty filters result in getting all the metrics for this MetricEntity.
+ //
+ // TODO(aserbin): instead of hard-coding, pass MetricFilters as a parameter
MetricFilters filters;
filters.entity_level = "debug";
- const string master_prefix = "kudu_master_";
- const string tserver_prefix = "kudu_tserver_";
- const string master_server = "kudu.master";
- const string tablet_server = "kudu.tabletserver";
- // Empty filters results in getting all the metrics for this MetricEntity.
+
+ MetricMap metrics;
+ AttributeMap attrs;
const auto s = GetMetricsAndAttrs(filters, &metrics, &attrs);
if (s.IsNotFound()) {
// Status::NotFound is returned when this entity has been filtered, treat it
@@ -421,21 +431,22 @@ Status MetricEntity::WriteAsPrometheus(PrometheusWriter* writer) const {
return Status::OK();
}
RETURN_NOT_OK(s);
- // Only emit server level metrics
- if (strcmp(prototype_->name(), "server") == 0) {
- if (id_ == master_server) {
- // attach kudu_master_ as prefix to metrics
- WriteMetricsPrometheus(writer, metrics, master_prefix);
- return Status::OK();
- }
- if (id_ == tablet_server) {
- // attach kudu_tserver_ as prefix to metrics
- WriteMetricsPrometheus(writer, metrics, tserver_prefix);
- return Status::OK();
- }
+
+ if (id_ == kIdMaster) {
+ // Prefix all master metrics with 'kudu_master_'.
+ static const string kMasterPrefix = "kudu_master_";
+ WriteMetricsPrometheus(writer, metrics, kMasterPrefix);
+ return Status::OK();
+ }
+ if (id_ == kIdTabletServer) {
+ // Prefix all tablet server metrics with 'kudu_tserver_'.
+ static const string kTabletServerPrefix = "kudu_tserver_";
+ WriteMetricsPrometheus(writer, metrics, kTabletServerPrefix);
+ return Status::OK();
}
- return Status::NotFound("Entity is not relevant to Prometheus");
+ return Status::NotSupported(
+ Substitute("$0: unexpected server-level metric entity", id_));
}
Status MetricEntity::CollectTo(MergedEntityMetrics* collections,