You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@kudu.apache.org by "Khazar Mammadli (Code Review)" <ge...@cloudera.org> on 2022/10/12 18:49:26 UTC

[kudu-CR] [WIP] Expose Prometheus Metrics in Kudu

Khazar Mammadli has uploaded this change for review. ( http://gerrit.cloudera.org:8080/19133


Change subject: [WIP] Expose Prometheus Metrics in Kudu
......................................................................

[WIP] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Tested by feeding all of the generated metrics to a prometheus server
running on localhost.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheuswriter.cc
A src/kudu/util/prometheuswriter.h
8 files changed, 221 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/1
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 1
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Khazar Mammadli has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 7:

(29 comments)

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@16
PS6, Line 16: according
> according
Done


http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@17
PS6, Line 17: t
> nit: extra space
Done


http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@25
PS6, Line 25: kudu-master",
> nit: kudu-master
Done


http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@32
PS6, Line 32: K
> nit: extra space
Done


http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@34
PS6, Line 34: This also makes it possible to keep
            : time based units more accurate as Milliseconds, Nanoseconds and etc.
            : do not need to be converted to seconds which is the base time unit in Prometheus.
> Is it possible to operate with such metrics as time-based ones then in Grap
Yes, it is possible to use these units with the mentioned tools


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc
File src/kudu/server/default_path_handlers.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc@544
PS6, Line 544:   const bool not_styled = false;
             :   const bool is_on_nav_bar =
> If using variables instead of direct constants for arguments, could these b
Converted to constant bool


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/CMakeLists.txt
File src/kudu/util/CMakeLists.txt:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/CMakeLists.txt@224
PS6, Line 224: prometheus_write
> nit: prometheus_writer.cc
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h
File src/kudu/util/metrics.h:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h@587
PS6, Line 587: 
> Why not to pass the prefix as a constant string?
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h@766
PS6, Line 766:   virtual Status WriteAsPrometheus(PrometheusWriter* writer, const std::string& prefix) const = 0;
             : 
             : 
> nit: remove them if not used.
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h@1275
PS6, Line 1275: writer->Value(value());
              :   }
              : 
> nit: how about using Substitute to build the string?
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@75
PS6, Line 75: const auto& val
> nit: could use structed binding (yes, it's C++17): https://en.cppreference.
Couldn't figure out how to apply it to this situation exactly, could you please clarify it more in this case?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@413
PS6, Line 413:   // Thus, eliminating the need to check status message to 
> What if this returns non-OK status?
// Status::NotFound is returned when this entity has been filtered, treat it
// as OK, and skip printing it.

As for Prometheus we do not expose the possibility to filter the entities and this function will return all of the metrics if no filters are specified, thus eliminating the need to re-check the status to see if entry is filtered or not. 

As the MetricFilters are always empty, there no possibility of receiving any other status apart from OK from my understanding


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@415
PS6, Line 415:   // Only emit server level metrics
> nit for here and below: add space between next argument and the comma.
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@416
PS6, Line 416: rcmp(prototype_->name(), "server") == 
> Here and below: why to convert into C string for comparison?
Changed to == as id_ is a std::string not a const char*


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@418
PS6, Line 418:      // attach kudu_master_ as prefix to metrics
             :       WriteMetricsToPrometheus(
> stringstream is a heavy and expensive object; use std::string or just const
done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@431
PS6, Line 431: 
> What if prototype_->name() isn't "server" -- why to return Status::OK() in 
Extended the response, to return a NotFound status when the metric entity is not relevant to Prometheus.


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@590
PS6, Line 590: 
> nit: the indent is messed up
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@733
PS6, Line 733:  output = strings:
> Why not just std::ostringstream?
Converted to string


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@735
PS6, Line 735:                              prefix, name(),MetricType::Name(type()));
             : 
> There are many metrics with the same prototype, each of them will print HEL
Yes, if we don't print Help or Type lines, the Description and Type do not get assigned in Prometheus


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@907
PS6, Line 907:                                       const std::string& /*prefix*/) const {
             :   // Prometheus doesn't support string gauges
             :   return Status::OK();
             : }
> Using strings::Substitute() here instead would be more efficient, I guess.
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@917
PS6, Line 917: ::lock_guard<simple_spinlock> l(lock_);
> Then why to have this method at all?
The abstract base class Gauge implements this function uses the WriteValue()(pure virtual) function to write this entry into Prometheus output. If not overridden this will lead to StringGauge to be written to Prometheus output as well.


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@983
PS6, Line 983:   strings::SubstituteAndAppend(&output, "$0$1$2{unit_type=\"$3\"} $4\n",
             :                                prefix, prototype_->name(), "_sum",
             :                                MetricUnit::Name(prototype_->unit()), total_sum());
             : 
             :   writer->WriteEntry(output);
             : }
             : 
             : //
             : // Counter
             : //
             : // This implementation is optimized by using a striped counter. See LongAdder for details.
             : 
             : scoped_refptr<Counter> CounterPrototype::Instantiate(const scoped_refptr<MetricEntity>& entity) {
             :   return entity->FindOrCreateCounter(this);
             : }
> What sort of Prometheus metric does this map into?  Is gauge allowed to hav
Yes, we can represent gauge in multiple lines. All lines for a given metric must be provided as one single group, with the optional HELP and TYPE lines first (in no particular order). Groups are separated whenever there is a HELP, TYPE or a new line between the metric

E.g

#HELP metric_name description
#TYPE metric_name gauge
kudu_metric 0
kudu_metric_count 0
kudu_metric_sum 0
// new line
#New line like above or new HELP/TYPE line results in a new metric 
#HELP new_metric Description
#TYPE new_metric counter
new_metric 0


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@1109
PS6, Line 1109: gs::Substitu
> why not just ostringstream?
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@1111
PS6, Line 1111:                                MetricUnit::Name(prototype_->unit()),
              :                                snapshot.percent
> nit for here and below: the indent is messed up
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@1130
PS6, Line 1130:                                prefix, prototype_->name(), "_bucket",
              :                                MetricUnit::Name(prototype_->unit()),
              :                                snapsho
> What if histogram_->TotalCount() value changes between this call and the ca
Better solution would be to use a snapshot, and emit metrics based on that to keep consistency

Another way to handle this, would be storing the TotalCount in a variable before this call and outputting it in both function calls.


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h
File src/kudu/util/prometheuswriter.h:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h@17
PS6, Line 17: 
            : 
> nit: use 'pragma' once instead
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h@24
PS6, Line 24: 
            : 
> nit: move this to be after the 'public' section
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h@30
PS6, Line 30: 
> Pass constant input parameters by constant reference: https://google.github
Done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.cc
File src/kudu/util/prometheuswriter.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.cc@22
PS6, Line 22: 
            : 
            : 
> If the output data is converted into std::string anyways before writing int
Done



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 7
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Tue, 18 Oct 2022 17:56:37 +0000
Gerrit-HasComments: Yes

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Alexey Serbin, Yingchun Lai, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#12).

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................

[metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in Prometheus.

More information on Prometheus Metric units and naming conventions can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 440 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/12
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 12
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Khazar Mammadli has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 9:

(14 comments)

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc
File src/kudu/server/default_path_handlers.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc@544
PS6, Line 544:   constexpr bool not_styled = false;
             :   constexpr bool is_on_nav_b
> nit: constexpr might be even better since it opens more opportunities for c
Done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/server/server_base.cc
File src/kudu/server/server_base.cc:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/server/server_base.cc@972
PS7, Line 972: ,
> nit: add a space after comma
done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics-test.cc
File src/kudu/util/metrics-test.cc:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics-test.cc@308
PS7, Line 308: ASSERT_EQ(expected_output, output.str());
> nit for here and below: the reference/expected value should come first, oth
done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics-test.cc@403
PS7, Line 403: const string expected_outpu
> nit for here and other places: consider adding 'const' to be more explicit 
done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.h
File src/kudu/util/metrics.h:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.h@586
PS7, Line 586: & 
> style nit: stick the ampersand to the type
done


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@75
PS6, Line 75:                
> It's something like
Done, thanks for clarifying


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@413
PS6, Line 413:   const string master_server = "kudu.master";
> Alright, but then why to store the status of the GetMetricsAndAttrs() call 
Re added the status check for NotFound() to skip over filtered entities. If there are any extra cases that also should be considered that come to your mind, please do share


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@983
PS6, Line 983:                        prefix, prototype_->name(), "_sum",
             :                        MetricUnit::Name(prototype_->unit()), total_sum());
             : 
             :   writer->WriteEntry(output);
             : }
             : 
             : //
             : // Counter
             : //
             : // This implementation is optimized by using a striped counter. See LongAdder for details.
             : 
             : scoped_refptr<Counter> CounterPrototype::Instantiate(const scoped_refptr<MetricEntity>& entity) {
             :   return entity->FindOrCreateCounter(this);
             : }
             : 
> Cool, thanks for clarifying on this.
Can't find an explicit location on where it is mentioned in the documentation but I have seen use cases, and they can be either ignored or utilized by the users. This explanation itself is provided in the commit with the text explosion format.


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@417
PS7, Line 417: tMetricsAndAt
> nit: consider defining a constant for this and for "kudu.tabletserver" as w
done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@731
PS7, Line 731:     writer->String(description());
             : 
             :     writer->String("level");
             :     writer->String(MetricLevelName(level()));
             :   }
             : }
             : 
> nit for here and below: could get rid of temporary variable and the assignm
Done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@900
PS7, Line 900: 
> nit for here and elsewher: drop the 'strings::' namespace prefix since this
Done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@974
PS7, Line 974: void MeanGauge::WriteValue(PrometheusWriter* writer, const std::string& prefix) const {
             :   auto output = Substitute("$0$1{unit_type=\"$2\"} $3\n", prefix, prototype_->name(),
             :           
> nit: could join these into
Done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@1100
PS7, Line 1100: 
              :   output = Substitute("$0$1$2{unit_type=\"$3\", le=\"0.75\"} $4\n",
              :                        prefix, prototype_->name(), "_buck
> nit: please add a comment to explain that the snapshot is taken to preserve
done


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@1109
PS7, Line 1109:                      snapsho
> nit: remove the 'strings::' namespace prefix and add 'using strings::Substi
Done



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 9
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Tue, 08 Nov 2022 16:08:03 +0000
Gerrit-HasComments: Yes

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Alexey Serbin, Yingchun Lai, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#8).

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................

[metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in Prometheus.

More information on Prometheus Metric units and naming conventions can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 439 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/8
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 8
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 12: Code-Review+1

(1 comment)

Overall looks good to me, please address Yingchun's comments and one more nit.

http://gerrit.cloudera.org:8080/#/c/19133/11//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/11//COMMIT_MSG@36
PS11, Line 36: do not need to be converted to seconds which is the base time unit in Prometheus.
             : 
             : More information on Prometheus Metric units and naming conventions can be found at:
nit: strive to keep lines' length under 72 symbols, the guide is at https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project#_commit_guidelines  (it can be found at the https://kudu.apache.org/docs/contributing.html#_submitting_patches page).



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 12
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Wed, 09 Nov 2022 16:00:51 +0000
Gerrit-HasComments: Yes

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#5).

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................

[metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names accroding to
Prometheus naming convention  to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="‘kudu-master’", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because  Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in Prometheus.

More information on Prometheus Metric units and naming conventions can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheuswriter.cc
A src/kudu/util/prometheuswriter.h
9 files changed, 409 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/5
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 5
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 16: Code-Review+2


-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 16
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Thu, 10 Nov 2022 03:42:30 +0000
Gerrit-HasComments: No

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Alexey Serbin, Yingchun Lai, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#14).

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................

KUDU-3375 Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in
Prometheus.

More information on Prometheus Metric units and naming conventions
can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 426 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/14
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 14
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Alexey Serbin, Yingchun Lai, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#7).

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................

[metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in Prometheus.

More information on Prometheus Metric units and naming conventions can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 442 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/7
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 7
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Khazar Mammadli has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 13:

(6 comments)

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h
File src/kudu/util/metrics.h:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h@1030
PS13, Line 1030:                              
> nit: the indent is off
Done


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h@1415
PS13, Line 1415:                              
> nit: the indent is off
Done


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h@1492
PS13, Line 1492:                              
> nit: the indent is off
Done


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@418
PS13, Line 418:   if (s.IsNotFound()) {
              :     // Status::NotFound is returned when this entity has been filtered, treat it
              :     // as OK, and skip printing it.
              :     return Status::OK();
              :   }
> I still don't see the code that would handle other than Status::NotFound() 
// Get a snapshot of the entity's metrics as well as the entity's attributes,
// maybe filtered by 'filters', see MetricFilters structure for details.
// Return Status::NotFound when it has been filtered, or Status::OK when succeed.

As you've mentioned previously, we can completely remove storing the status as well. Instead of making a new method to get metrics and attributes I've went along with already existing GetMetricsAndAttrs(). From the function comments and itself, returned Status is based on the passed filters. The filters that are passed to it are only for setting the level to Debug, which shouldl still return Status:OK() at any given time when the function is called. 

The code will fail if the GetMetricsAndAttributes() fails to work properly though, meaning if it doesn't assign the metrics and attributes


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@902
PS13, Line 902:   writer->WriteEntry(Substitute("$0$1{unit_type=\"$2\"} $3\n",
              :                                 prefix, prototype_->name(),
              :                                 MetricUnit::Name(prototype_->unit()), value()));
              : }
> If, according to the comment in StringGauge::WriteAsPrometheus(), string ga
Removed the contents of the function to do nothing. Comment on line 911 explains it further.


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@907
PS13, Line 907: Status StringGauge::WriteAsPrometheus(PrometheusWriter* /*writer*/,
              :                                       const std::string& /*prefix*/) const {
              :   // Prometheus doesn't support string gauges
              :   return Status::OK();
              : }
> There was a thread about this in PS6, and I missed following-up.  As of PS1
Yes, I've removed the method. I've mistaken Gauge::WriteAsPrometheus() as a pure virtual function as well, that's why there is an empty implementation for it in StringGauge as well. I've removed the contents of the StringGauge::WriteValue() which will be used like you've mentioned when Gauge::WriteAsPrometheus() is called.



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 13
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Wed, 09 Nov 2022 19:59:05 +0000
Gerrit-HasComments: Yes

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 15: Code-Review+1

(2 comments)

One more nit, otherwise looks good to me.

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@907
PS13, Line 907:                                 MetricUnit::Name(prototype_->unit()),value()));
              :   DCHECK(false);
              : }
              : 
              : S
> The desired result should be fully empty, as leaving comments without actua
Ah, now I see -- thank you for clarifying.


http://gerrit.cloudera.org:8080/#/c/19133/15/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/15/src/kudu/util/metrics.cc@902
PS15, Line 902:   // This method implements the Prometheus format for string gauges,
              :   // but it is not called anywhere, because Prometheus does not
              :   // support string gauges.
              :   writer->WriteEntry(Substitute("$0$1{unit_type=\"$2\"} $3\n",
              :                                 prefix, prototype_->name(),
              :                                 MetricUnit::Name(prototype_->unit()),value()));
Instead of this piece of unused code that the compiler takes time to process but never uses, could we just leave here the following comment:

A string gauge's value can be anything, but Prometheus does not support non-numeric values for gauges with exception of {+,-}Inf and NaN (see https://prometheus.io/docs/instrumenting/exposition_formats/). DCHECK() is added to make sure this method is not called from anywhere, but overriding it is necessary since Gauge::WriteValue() is a pure virtual one. An alternative could be defining a empty implementation for Gauge::WriteValue() virtual method and not adding this empty override here.



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 15
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Thu, 10 Nov 2022 02:21:59 +0000
Gerrit-HasComments: Yes

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has submitted this change and it was merged. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................

KUDU-3375 Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in
Prometheus.

More information on Prometheus Metric units and naming conventions
can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Reviewed-on: http://gerrit.cloudera.org:8080/19133
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <al...@apache.org>
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 445 insertions(+), 14 deletions(-)

Approvals:
  Kudu Jenkins: Verified
  Alexey Serbin: Looks good to me, approved

-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 17
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 6:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@75
PS6, Line 75: const auto& val
> Couldn't figure out how to apply it to this situation exactly, could you pl
It's something like

for (const auto& [name, val] : metrics) {
   ...
}

where 'name' is for '.first', and 'val' is for '.second' of the elements being iterated, there isn't a need to introduce extra variables in the scope of the for() cycle.



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 6
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Fri, 28 Oct 2022 17:31:19 +0000
Gerrit-HasComments: Yes

[kudu-CR] [WIP] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#2).

Change subject: [WIP] Expose Prometheus Metrics in Kudu
......................................................................

[WIP] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Tested by feeding all of the generated metrics to a prometheus server
running on localhost.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheuswriter.cc
A src/kudu/util/prometheuswriter.h
8 files changed, 261 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/2
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 2
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)

[kudu-CR] [WIP] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#4).

Change subject: [WIP] Expose Prometheus Metrics in Kudu
......................................................................

[WIP] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheuswriter.cc
A src/kudu/util/prometheuswriter.h
9 files changed, 371 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/4
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 4
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Alexey Serbin, Yingchun Lai, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#16).

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................

KUDU-3375 Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in
Prometheus.

More information on Prometheus Metric units and naming conventions
can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 445 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/16
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 16
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Alexey Serbin, Yingchun Lai, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#13).

Change subject: KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu
......................................................................

KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in
Prometheus.

More information on Prometheus Metric units and naming conventions
can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 440 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/13
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 13
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] [WIP] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#3).

Change subject: [WIP] Expose Prometheus Metrics in Kudu
......................................................................

[WIP] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheuswriter.cc
A src/kudu/util/prometheuswriter.h
9 files changed, 364 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/3
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 3
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 6:

(25 comments)

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@16
PS6, Line 16: accroding
according


http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@17
PS6, Line 17:  
nit: extra space


http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@32
PS6, Line 32:  
nit: extra space


http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@34
PS6, Line 34: This also makes it possible to keep
            : time based units more accurate as Milliseconds, Nanoseconds and etc.
            : do not need to be converted to seconds which is the base time unit in Prometheus.
Is it possible to operate with such metrics as time-based ones then in Graphana and other tools?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc
File src/kudu/server/default_path_handlers.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc@544
PS6, Line 544:   bool not_styled = false;
             :   bool is_on_nav_bar = true;
If using variables instead of direct constants for arguments, could these be constant/constexpr?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/CMakeLists.txt
File src/kudu/util/CMakeLists.txt:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/CMakeLists.txt@224
PS6, Line 224: prometheuswriter
nit: prometheus_writer.cc


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h
File src/kudu/util/metrics.h:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h@587
PS6, Line 587: std::stringstream*
Why not to pass the prefix as a constant string?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@75
PS6, Line 75: const auto& val
nit: could use structed binding (yes, it's C++17): https://en.cppreference.com/w/cpp/language/structured_binding


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@413
PS6, Line 413:   Status s = GetMetricsAndAttrs(filters, &metrics, &attrs);
What if this returns non-OK status?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@415
PS6, Line 415:   if (strcmp(prototype_->name(),"server") == 0) {
nit for here and below: add space between next argument and the comma.


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@416
PS6, Line 416: strcmp(id_.c_str(),"kudu.master") == 0
Here and below: why to convert into C string for comparison?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@418
PS6, Line 418:      std::stringstream prefix;
             :       prefix << "kudu_master_";
stringstream is a heavy and expensive object; use std::string or just const char* instead


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@431
PS6, Line 431:   return Status::OK();
What if prototype_->name() isn't "server" -- why to return Status::OK() in that case if nothing has been written?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@590
PS6, Line 590:               
nit: the indent is messed up


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@733
PS6, Line 733:  std::stringstream
Why not just std::ostringstream?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@907
PS6, Line 907:   std::stringstream output;
             :   output << prefix->str() << prototype_->name() <<
             :   "{unit_type=\"" << MetricUnit::Name(prototype_->unit()) << "\"" << "}"
             :   << " " << value() << "\n";
Using strings::Substitute() here instead would be more efficient, I guess.


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@917
PS6, Line 917: Prometheus doesn't support string gauges
Then why to have this method at all?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@983
PS6, Line 983:   std::stringstream output;
             : 
             :   output << prefix->str() << prototype_->name() <<
             :   "{unit_type=\"" << MetricUnit::Name(prototype_->unit()) << "\"" << "}"
             :   << " " << value() << "\n";
             : 
             :   output << prefix->str() << prototype_->name() << "_count" <<
             :   "{unit_type=\"" << MetricUnit::Name(prototype_->unit()) << "\"" << "}"
             :   << " " << total_count() << "\n";
             : 
             :   output << prefix->str() << prototype_->name() << "_sum" <<
             :   "{unit_type=\"" << MetricUnit::Name(prototype_->unit()) << "\"" << "}"
             :   << " " << total_sum() << "\n";
             : 
             :   writer->WriteEntry(&output);
What sort of Prometheus metric does this map into?  Is gauge allowed to have multiple lines?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@1109
PS6, Line 1109: stringstream
why not just ostringstream?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@1111
PS6, Line 1111:   "{unit_type=\"" << MetricUnit::Name(prototype_->unit()) << "\"" << ", " << "le=\"0.75\"} "
              :   << histogram_->ValueAtPercentile(75) << "\n";
nit for here and below: the indent is messed up


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@1130
PS6, Line 1130:   output << prefix->str() << prototype_->name() << "_bucket" <<
              :   "{unit_type=\"" << MetricUnit::Name(prototype_->unit()) << "\"" << ", " << "le=\"+Inf\"} "
              :   << histogram_->TotalCount() << "\n";
What if histogram_->TotalCount() value changes between this call and the call below when outputting 'x_count' value?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h
File src/kudu/util/prometheuswriter.h:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h@17
PS6, Line 17: #ifndef KUDU_UTIL_PROMETHEUSWRITER_H
            : #define KUDU_UTIL_PROMETHEUSWRITER_H
nit: use 'pragma' once instead


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h@24
PS6, Line 24:  private:
            :   std::ostringstream* output_;
nit: move this to be after the 'public' section


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.h@30
PS6, Line 30: const std::stringstream*
Pass constant input parameters by constant reference: https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.cc
File src/kudu/util/prometheuswriter.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/prometheuswriter.cc@22
PS6, Line 22: void PrometheusWriter::WriteEntry(const std::stringstream* data) {
            :  *output_ << data->str();
            : }
If the output data is converted into std::string anyways before writing into the output stream, why not to pass the parameter as std::string then?



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 6
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Fri, 14 Oct 2022 01:56:11 +0000
Gerrit-HasComments: Yes

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 10:

> Uploaded patch set 10.

There are build failures in PS10:

11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/metrics.cc: In member function 'virtual kudu::Status kudu::Histogram::WriteAsPrometheus(PrometheusWriter*, const string&) const':
11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/metrics.cc:1100:41: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say '&kudu::Histogram::snapshot' [-fpermissive]
11:21:37    RETURN_NOT_OK(GetHistogramSnapshotPB(&snapshot, opts));
11:21:37                                          ^
11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/status.h:41:33: note: in definition of macro 'KUDU_RETURN_NOT_OK'
11:21:37      const ::kudu::Status& _s = (s);             \
11:21:37                                  ^
11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/metrics.cc:1100:3: note: in expansion of macro 'RETURN_NOT_OK'
11:21:37    RETURN_NOT_OK(GetHistogramSnapshotPB(&snapshot, opts));


-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 10
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Tue, 08 Nov 2022 21:35:03 +0000
Gerrit-HasComments: No

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Yingchun Lai (Code Review)" <ge...@cloudera.org>.
Yingchun Lai has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 11:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/19133/11//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/11//COMMIT_MSG@7
PS11, Line 7: [metrics]
Add the related JIRA ID, https://issues.apache.org/jira/browse/KUDU-3375



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 11
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Wed, 09 Nov 2022 02:51:30 +0000
Gerrit-HasComments: Yes

[kudu-CR] KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 13:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@902
PS13, Line 902:   writer->WriteEntry(Substitute("$0$1{unit_type=\"$2\"} $3\n",
              :                                 prefix, prototype_->name(),
              :                                 MetricUnit::Name(prototype_->unit()), value()));
              : }
If, according to the comment in StringGauge::WriteAsPrometheus(), string gauges aren't supported in Prometheus format, then why to implement this method at all?  Maybe, this implementation should do nothing?



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 13
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Wed, 09 Nov 2022 18:41:44 +0000
Gerrit-HasComments: Yes

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 17:

> (1 comment)
 > 
 > Added the comment as well. Thanks for reviewing!

Thank you for the contribution!


-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 17
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Thu, 10 Nov 2022 03:43:41 +0000
Gerrit-HasComments: No

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Attila Bukor (Code Review)" <ge...@cloudera.org>.
Attila Bukor has uploaded a new patch set (#10) to the change originally created by Khazar Mammadli. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................

[metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in Prometheus.

More information on Prometheus Metric units and naming conventions can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 440 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/10
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 10
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Attila Bukor (Code Review)" <ge...@cloudera.org>.
Attila Bukor has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 11:

> Patch Set 10:
> 
> > Uploaded patch set 10.
> 
> There are build failures in PS10:
> 
> 11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/metrics.cc: In member function 'virtual kudu::Status kudu::Histogram::WriteAsPrometheus(PrometheusWriter*, const string&) const':
> 11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/metrics.cc:1100:41: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say '&kudu::Histogram::snapshot' [-fpermissive]
> 11:21:37    RETURN_NOT_OK(GetHistogramSnapshotPB(&snapshot, opts));
> 11:21:37                                          ^
> 11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/status.h:41:33: note: in definition of macro 'KUDU_RETURN_NOT_OK'
> 11:21:37      const ::kudu::Status& _s = (s);             \
> 11:21:37                                  ^
> 11:21:37 /home/jenkins-slave/workspace/kudu-master/2/src/kudu/util/metrics.cc:1100:3: note: in expansion of macro 'RETURN_NOT_OK'
> 11:21:37    RETURN_NOT_OK(GetHistogramSnapshotPB(&snapshot, opts));

My bad, messed up reformatting a comment.


-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 11
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Tue, 08 Nov 2022 21:46:49 +0000
Gerrit-HasComments: No

[kudu-CR] KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Khazar Mammadli has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 13:

(2 comments)

http://gerrit.cloudera.org:8080/#/c/19133/11//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/11//COMMIT_MSG@7
PS11, Line 7: KUDU-3375
> Add the related JIRA ID, https://issues.apache.org/jira/browse/KUDU-3375
Done


http://gerrit.cloudera.org:8080/#/c/19133/11//COMMIT_MSG@36
PS11, Line 36: do not need to be converted to seconds which is the base time unit in
             : Prometheus.
             : 
> nit: strive to keep lines' length under 72 symbols, the guide is at https:/
Done



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 13
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Wed, 09 Nov 2022 17:07:31 +0000
Gerrit-HasComments: Yes

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 14:

(3 comments)

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@418
PS13, Line 418:   // Only emit server level metrics
              :   if (strcmp(prototype_->name(), "server") == 0) {
              :     if (id_ == master_server) {
              :       // attach kudu_master_ as prefix to metrics
              :    
> // Get a snapshot of the entity's metrics as well as the entity's attribute
Could you please just add proper status code handling here for GetMetricsAndAttrs()?  That's what I think is missing here to make the code robust and future-proof regarding GetMetricsAndAttrs().

I guess that might look like the following:

  ...

  const auto s = GetMetricsAndAttrs(filters, &metrics, &attrs);
  if (s.IsNotFound()) {
    // Status::NotFound is returned when this entity has been filtered, treat it
    // as OK, and skip printing it.
    return Status::OK();
  }
  RETURN_NOT_OK(s);

  ...

The important piece is adding having RETURN_NOT_OK(s) to handle other than Status::NotFound() status.


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@907
PS13, Line 907:   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_;
              :  
> Yes, I've removed the method. I've mistaken Gauge::WriteAsPrometheus() as a
OK, thanks for the update.

Since I guess there is something I'm still missing here, I want to clarify on that.

So, what do we want to see as a result when calling WriteAsPrometheus() for a string gauge: should we have a completely empty output or we still want the comment to be output as per MetricPrototype::WriteFields() implementation?

If a completely empty output is desired, maybe your original approach of overriding StringGauge::WriteAsPrometheus() that does nothing but returns Status::OK() is the desired goal?  And if it's indeed so, then we want that instead of relying on Gauge::WriteAsPrometheus(), and maybe we also want to add DCHECK(false) into the implementation of the StringGauge::WriteValue(PrometheusWriter*, const std::string&) method to make sure it's not called from anywhere?

Thanks!


http://gerrit.cloudera.org:8080/#/c/19133/14/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/14/src/kudu/util/metrics.cc@896
PS14, Line 896: void StringGauge::WriteValue(PrometheusWriter* writer, const std::string& prefix) const {
Please add a comment to explain why this method does nothing, otherwise it looks like the implementation was omitted by a mistake.



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 14
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Wed, 09 Nov 2022 22:21:34 +0000
Gerrit-HasComments: Yes

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Alexey Serbin, Yingchun Lai, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#15).

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................

KUDU-3375 Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in
Prometheus.

More information on Prometheus Metric units and naming conventions
can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 445 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/15
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 15
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Khazar Mammadli has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 16:

(1 comment)

Added the comment as well. Thanks for reviewing!

http://gerrit.cloudera.org:8080/#/c/19133/15/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/15/src/kudu/util/metrics.cc@902
PS15, Line 902: // (see https://prometheus.io/docs/instrumenting/exposition_formats/).
              : // DCHECK() is added to make sure this method is not called from anywhere,
              : // but overriding it is necessary since Gauge::WriteValue() is a pure virtual one.
              : // An alternative could be defining a empty implementation for Gauge::WriteValue()
              : // virtual method and not adding this empty override here.
              : void StringGauge::WriteValue(PrometheusWriter* writer, const std::string& prefi
> Instead of this piece of unused code that the compiler takes time to proces
Done



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 16
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Thu, 10 Nov 2022 02:40:30 +0000
Gerrit-HasComments: Yes

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Hello Tidy Bot, Zoltan Chovan, Attila Bukor, Kudu Jenkins, 

I'd like you to reexamine a change. Please visit

    http://gerrit.cloudera.org:8080/19133

to look at the new patch set (#6).

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................

[metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names accroding to
Prometheus naming convention  to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="‘kudu-master’", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because  Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in Prometheus.

More information on Prometheus Metric units and naming conventions can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheuswriter.cc
A src/kudu/util/prometheuswriter.h
9 files changed, 410 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/6
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 6
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Yingchun Lai (Code Review)" <ge...@cloudera.org>.
Yingchun Lai has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 6:

(4 comments)

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@25
PS6, Line 25: ‘kudu-master’
nit: kudu-master


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h
File src/kudu/util/metrics.h:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h@766
PS6, Line 766:   // All metrics must be able to render themselves as Prometheus.
             : //  virtual Status WriteAsPrometheus(PrometheusWriter* writer) const = 0;
             : 
nit: remove them if not used.


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.h@1275
PS6, Line 1275: output << prefix->str() << prototype_->name() <<
              :     "{unit_type=\"" << MetricUnit::Name(prototype_->unit()) << "\"" << "}"
              :     << " " << value() << "\n";
nit: how about using Substitute to build the string?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@735
PS6, Line 735: output << "# HELP " << name() << " " << description() << "\n";
             :   output << "# TYPE " << name() << " " << MetricType::Name(type()) << "\n";
There are many metrics with the same prototype, each of them will print HELP and TYPE?



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 6
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Sat, 15 Oct 2022 13:52:51 +0000
Gerrit-HasComments: Yes

[kudu-CR] KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 13:

(7 comments)

http://gerrit.cloudera.org:8080/#/c/19133/13//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/13//COMMIT_MSG@7
PS13, Line 7: KUDU-3375 [metrics]
nit: just for future reference, please use either 'KUDU-3375' or '[metrics]', but not both (it also helps to keep the summary under 50 symbols in length)


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h
File src/kudu/util/metrics.h:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h@1030
PS13, Line 1030:                              
nit: the indent is off


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h@1415
PS13, Line 1415:                              
nit: the indent is off


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.h@1492
PS13, Line 1492:                              
nit: the indent is off


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@917
PS6, Line 917: d_refptr<Metric> MeanGauge::snapshot() c
> The abstract base class Gauge implements this function uses the WriteValue(
If not overridden, the implementation will just use WriteValue() that's been overridden by the custom implementation for StringGauge::WriteValue(), isn't it?

With that, should we remove this method?


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@418
PS13, Line 418:   if (s.IsNotFound()) {
              :     // Status::NotFound is returned when this entity has been filtered, treat it
              :     // as OK, and skip printing it.
              :     return Status::OK();
              :   }
I still don't see the code that would handle other than Status::NotFound() error status at this point.  Current implementation of GetMetricsAndAttrs() is one thing, but the code should provide clear semantics of what happens in case of other error codes returned.  Also, the implementation of GetMetricsAndAttrs() may change in the future and start returning other status codes.

As of now, Status::OK() and other than Status::NotFound() are treated exactly the same in this code, I don't think it's OK.


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@907
PS13, Line 907: Status StringGauge::WriteAsPrometheus(PrometheusWriter* /*writer*/,
              :                                       const std::string& /*prefix*/) const {
              :   // Prometheus doesn't support string gauges
              :   return Status::OK();
              : }
There was a thread about this in PS6, and I missed following-up.  As of PS13, I'm still confused with this.

If not overridden, the implementation of Gauge::WriteAsPrometheus() will use WriteValue() that's been overridden by the custom implementation for StringGauge::WriteValue(), isn't it?

With that, should we remove this method?



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 13
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Wed, 09 Nov 2022 18:32:53 +0000
Gerrit-HasComments: Yes

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Attila Bukor (Code Review)" <ge...@cloudera.org>.
Attila Bukor has uploaded a new patch set (#11) to the change originally created by Khazar Mammadli. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................

[metrics] Expose Prometheus Metrics in Kudu

This patch introduces an endpoint which emits server level metrics in
Prometheus Text Explosion format for Kudu. The endpoint can be found at
/metrics_prometheus path of the webserver.

More information on the Prometheus format can be found at:
https://prometheus.io/docs/instrumenting/exposition_formats

Prefix kudu_ has been added to all of the metric names according to
Prometheus naming convention to specify the domain and differentiate
from any other metrics belonging to different services. Following the
kudu_ prefix either master_ or tserver_ prefix is attached based on the
server type that is exposing the metrics. In order to differentiate
between different master and tablet servers running on the same host
Prometheus automatically attaches an instance label which holds the
"hostname:portname".

eg: kudu_master_metric{instance="localhost:8765", job="kudu-master", unit_type="unit"}

Not all of the Kudu metric names follow the Prometheus metric naming
recommendations which state metric units should be attached at the end
of the metric name. In Kudu some metrics have these units at the end of
the metric name, some in the middle of the metric and for some metrics
it is unclear what the metric unit is just by looking at the metric
name. Due to this and also because Kudu supports more Metric Units
than base Prometheus Metric units, metric units are represented as
Prometheus labels for each metric. This also makes it possible to keep
time based units more accurate as Milliseconds, Nanoseconds and etc.
do not need to be converted to seconds which is the base time unit in Prometheus.

More information on Prometheus Metric units and naming conventions can be found at:
https://prometheus.io/docs/practices/naming/#metric-names

Tested by feeding all of the generated metrics to a prometheus server
running on localhost. Added unit tests to each metric type.

Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
---
M src/kudu/server/default_path_handlers.cc
M src/kudu/server/default_path_handlers.h
M src/kudu/server/server_base.cc
M src/kudu/util/CMakeLists.txt
M src/kudu/util/metrics-test.cc
M src/kudu/util/metrics.cc
M src/kudu/util/metrics.h
A src/kudu/util/prometheus_writer.cc
A src/kudu/util/prometheus_writer.h
9 files changed, 440 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/33/19133/11
-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 11
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>

[kudu-CR] KUDU-3375 Expose Prometheus Metrics in Kudu

Posted by "Khazar Mammadli (Code Review)" <ge...@cloudera.org>.
Khazar Mammadli has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: KUDU-3375 Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 15:

(3 comments)

http://gerrit.cloudera.org:8080/#/c/19133/13//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/13//COMMIT_MSG@7
PS13, Line 7: KUDU-3375 Expose Pr
> nit: just for future reference, please use either 'KUDU-3375' or '[metrics]
Okay


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@418
PS13, Line 418:     // Status::NotFound is returned when this entity has been filtered, treat it
              :     // as OK, and skip printing it.
              :     return Status::OK();
              :   }
              :   R
> Could you please just add proper status code handling here for GetMetricsAn
Done


http://gerrit.cloudera.org:8080/#/c/19133/13/src/kudu/util/metrics.cc@907
PS13, Line 907:                                 MetricUnit::Name(prototype_->unit()),value()));
              :   DCHECK(false);
              : }
              : 
              : S
> OK, thanks for the update.
The desired result should be fully empty, as leaving comments without actually having a actual line representing the metric might lead to some incorrect parsing of the data now that I think about it. 

I've added a DCHECK to StringGauge::WriteValue() and restored the implementation in case Prometheus starts supporting String Gauges, along with adding an empty reimplementation of StringGauge::WriteAsPrometheus().



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 15
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Thu, 10 Nov 2022 01:18:38 +0000
Gerrit-HasComments: Yes

[kudu-CR] [metrics] Expose Prometheus Metrics in Kudu

Posted by "Alexey Serbin (Code Review)" <ge...@cloudera.org>.
Alexey Serbin has posted comments on this change. ( http://gerrit.cloudera.org:8080/19133 )

Change subject: [metrics] Expose Prometheus Metrics in Kudu
......................................................................


Patch Set 7:

(14 comments)

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/19133/6//COMMIT_MSG@34
PS6, Line 34: This also makes it possible to keep
            : time based units more accurate as Milliseconds, Nanoseconds and etc.
            : do not need to be converted to seconds which is the base time unit in Prometheus.
> Yes, it is possible to use these units with the mentioned tools
Cool -- glad to hear it's not an obstacle for the tools, so we don't need to expose everything in seconds.


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc
File src/kudu/server/default_path_handlers.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/server/default_path_handlers.cc@544
PS6, Line 544:   const bool not_styled = false;
             :   const bool is_on_nav_bar =
> Converted to constant bool
nit: constexpr might be even better since it opens more opportunities for compile-time optimization


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/server/server_base.cc
File src/kudu/server/server_base.cc:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/server/server_base.cc@972
PS7, Line 972: ,
nit: add a space after comma


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics-test.cc
File src/kudu/util/metrics-test.cc:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics-test.cc@308
PS7, Line 308: ASSERT_EQ(output.str(), expected_output);
nit for here and below: the reference/expected value should come first, otherwise it's harder to comprehend the output if this assertion ever triggers


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics-test.cc@403
PS7, Line 403: std::string expected_output
nit for here and other places: consider adding 'const' to be more explicit on the immutable semantics of the references


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.h
File src/kudu/util/metrics.h:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.h@586
PS7, Line 586:  &
style nit: stick the ampersand to the type

Also, consider having parameter by default there for prefix to be empty, so it's not necessary to supply empty strings in case where prefix isn't relevant


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@413
PS6, Line 413:   // Thus, eliminating the need to check status message to 
> // Status::NotFound is returned when this entity has been filtered, treat i
Alright, but then why to store the status of the GetMetricsAndAttrs() call at all?

If it returned NotFound(), shouldn't the code short-circuit right here and return from this method/function?

Also, what if GetMetricsAndAttrs() changes to start returning something beside Status::OK() and Status::NotFound()?


http://gerrit.cloudera.org:8080/#/c/19133/6/src/kudu/util/metrics.cc@983
PS6, Line 983:   strings::SubstituteAndAppend(&output, "$0$1$2{unit_type=\"$3\"} $4\n",
             :                                prefix, prototype_->name(), "_sum",
             :                                MetricUnit::Name(prototype_->unit()), total_sum());
             : 
             :   writer->WriteEntry(output);
             : }
             : 
             : //
             : // Counter
             : //
             : // This implementation is optimized by using a striped counter. See LongAdder for details.
             : 
             : scoped_refptr<Counter> CounterPrototype::Instantiate(const scoped_refptr<MetricEntity>& entity) {
             :   return entity->FindOrCreateCounter(this);
             : }
> Yes, we can represent gauge in multiple lines. All lines for a given metric
Cool, thanks for clarifying on this.

Could you please also add a reference to the documentation where it's clear (or explicitly said so) that a gauge is allowed to have multiple values like in your example?


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc
File src/kudu/util/metrics.cc:

http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@417
PS7, Line 417: "kudu.master"
nit: consider defining a constant for this and for "kudu.tabletserver" as well as you did for the prefixes


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@731
PS7, Line 731:   std::string output = "";
             : 
             :   output = strings::Substitute("# HELP $0$1 $2\n# TYPE $3$4 $5\n",
             :                                prefix, name(), description(),
             :                                prefix, name(),MetricType::Name(type()));
             : 
             :   writer->WriteEntry(output);
nit for here and below: could get rid of temporary variable and the assignment operator

writer->WriteEntry(Substitute(...));


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@900
PS7, Line 900: strings::
nit for here and elsewher: drop the 'strings::' namespace prefix since this file already has 'using strings::Substitute'


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@974
PS7, Line 974:   std::string output = "";
             : 
             :   output =
nit: could join these into

auto string = Substitute(...);


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@1100
PS7, Line 1100:   MetricJsonOptions opts;
              :   HistogramSnapshotPB snapshot;
              :   RETURN_NOT_OK(GetHistogramSnapshotPB(&snapshot, opts));
nit: please add a comment to explain that the snapshot is taken to preserve consistency across the metrics and to satisfy the Prometheus' requirement on the '_bucket' and '_count' values.


http://gerrit.cloudera.org:8080/#/c/19133/7/src/kudu/util/metrics.cc@1109
PS7, Line 1109: strings::SubstituteAndAppend
nit: remove the 'strings::' namespace prefix and add 'using strings::SubstituteAndAppend' in the beginning of this file



-- 
To view, visit http://gerrit.cloudera.org:8080/19133
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I4b2d01bd56f6f0f1b6f31cbce15e671d16521739
Gerrit-Change-Number: 19133
Gerrit-PatchSet: 7
Gerrit-Owner: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Alexey Serbin <al...@apache.org>
Gerrit-Reviewer: Attila Bukor <ab...@apache.org>
Gerrit-Reviewer: Khazar Mammadli <ma...@cloudera.com>
Gerrit-Reviewer: Kudu Jenkins (120)
Gerrit-Reviewer: Tidy Bot (241)
Gerrit-Reviewer: Yingchun Lai <ac...@gmail.com>
Gerrit-Reviewer: Zoltan Chovan <zc...@cloudera.com>
Gerrit-Comment-Date: Fri, 28 Oct 2022 18:30:33 +0000
Gerrit-HasComments: Yes