RFR: metrics: add library
Erik Joelsson
erikj at openjdk.java.net
Tue May 11 21:07:38 UTC 2021
On Tue, 11 May 2021 18:32:17 GMT, Erik Helin <ehelin at openjdk.org> wrote:
> Hi all,
>
> please review this patch that adds the new `metrics` library. The metrics library can be used to collect runtime metrics, such as the number of HTTP requests or the number of bot runs. The library is designed according to the [Prometheus library guide](https://prometheus.io/docs/instrumenting/writing_clientlibs/) and currently features the two Prometheus types [gauge](https://prometheus.io/docs/concepts/metric_types/#gauge) and [counter](https://prometheus.io/docs/concepts/metric_types/#counter). The library is designed to allow it to be extended with the [histogram](https://prometheus.io/docs/concepts/metric_types/#histogram) and [summary](https://prometheus.io/docs/concepts/metric_types/#summary) types if we find a need for them.
>
> The `Counter` and `Gauge` types are designed to be thread-safe and should typically be stored in a `private final static` variable in a classes (similar to how one might store a `Logger` instance). A minimal `Counter` example looks like:
>
>
> class Example {
> private static final Counter counter = Counter.name("test").register();
> }
>
>
> I won't go into details here on how Prometheus naming and labelling works, please see the Prometheus [documentation](https://prometheus.io/docs/introduction/overview/) for those concepts. The goal is that library should be fairly self-explanatory for someone with an understanding of how Prometheus works. Note though that the `metrics` library itself is not tied to Prometheus in any way, it only supports the collection of runtime metrics. It is however designed to make it easy to write a Prometheus exporter, something I will show in a follow-up patch.
>
> I also added a bunch of unit tests for the new library.
>
> Thanks,
> Erik
Looks good, thanks for implementing this!
metrics/src/main/java/org/openjdk/skara/metrics/Counter.java line 185:
> 183: this.name = name;
> 184: this.label = label;
> 185: this.value = new ConcurrentHashMap<String, DoubleAdder>();
Can leave out the types between <> here.
metrics/src/main/java/org/openjdk/skara/metrics/Gauge.java line 213:
> 211: this.name = name;
> 212: this.label = label;
> 213: this.value = new ConcurrentHashMap<String, DoubleAdder>();
And here.
-------------
Marked as reviewed by erikj (Reviewer).
PR: https://git.openjdk.java.net/skara/pull/1148
More information about the skara-dev
mailing list