From 5980a17233cad1ad1d1aaf246bf0d45ed235b62d Mon Sep 17 00:00:00 2001 From: Vasily Vasilkov Date: Wed, 7 Oct 2020 23:43:59 +0300 Subject: [PATCH 1/6] Add ability to filter metrics in DropwizardExports Fix #573 Signed-off-by: Vasily Vasilkov --- .../client/dropwizard/DropwizardExports.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java index e8011dd34..94d3ba598 100644 --- a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java +++ b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java @@ -20,15 +20,28 @@ public class DropwizardExports extends io.prometheus.client.Collector implements io.prometheus.client.Collector.Describable { private static final Logger LOGGER = Logger.getLogger(DropwizardExports.class.getName()); private MetricRegistry registry; + private MetricFilter metricFilter; private SampleBuilder sampleBuilder; /** - * Creates a new DropwizardExports with a {@link DefaultSampleBuilder}. + * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and {@link MetricFilter#ALL} * * @param registry a metric registry to export in prometheus. */ public DropwizardExports(MetricRegistry registry) { this.registry = registry; + this.metricFilter = MetricFilter.ALL; + this.sampleBuilder = new DefaultSampleBuilder(); + } + + /** + * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and custom MetricFilter + * + * @param registry a metric registry to export in prometheus. + */ + public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter) { + this.registry = registry; + this.metricFilter = metricFilter; this.sampleBuilder = new DefaultSampleBuilder(); } @@ -38,6 +51,17 @@ public DropwizardExports(MetricRegistry registry) { */ public DropwizardExports(MetricRegistry registry, SampleBuilder sampleBuilder) { this.registry = registry; + this.metricFilter = MetricFilter.ALL; + this.sampleBuilder = sampleBuilder; + } + + /** + * @param registry a metric registry to export in prometheus. + * @param sampleBuilder sampleBuilder to use to create prometheus samples. + */ + public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter, SampleBuilder sampleBuilder) { + this.registry = registry; + this.metricFilter = metricFilter; this.sampleBuilder = sampleBuilder; } @@ -128,19 +152,19 @@ MetricFamilySamples fromMeter(String dropwizardName, Meter meter) { public List collect() { Map mfSamplesMap = new HashMap(); - for (SortedMap.Entry entry : registry.getGauges().entrySet()) { + for (SortedMap.Entry entry : registry.getGauges(metricFilter).entrySet()) { addToMap(mfSamplesMap, fromGauge(entry.getKey(), entry.getValue())); } - for (SortedMap.Entry entry : registry.getCounters().entrySet()) { + for (SortedMap.Entry entry : registry.getCounters(metricFilter).entrySet()) { addToMap(mfSamplesMap, fromCounter(entry.getKey(), entry.getValue())); } - for (SortedMap.Entry entry : registry.getHistograms().entrySet()) { + for (SortedMap.Entry entry : registry.getHistograms(metricFilter).entrySet()) { addToMap(mfSamplesMap, fromHistogram(entry.getKey(), entry.getValue())); } - for (SortedMap.Entry entry : registry.getTimers().entrySet()) { + for (SortedMap.Entry entry : registry.getTimers(metricFilter).entrySet()) { addToMap(mfSamplesMap, fromTimer(entry.getKey(), entry.getValue())); } - for (SortedMap.Entry entry : registry.getMeters().entrySet()) { + for (SortedMap.Entry entry : registry.getMeters(metricFilter).entrySet()) { addToMap(mfSamplesMap, fromMeter(entry.getKey(), entry.getValue())); } return new ArrayList(mfSamplesMap.values()); From 210dc71b28fcc19b8db1e2b533cb3d65befaf604 Mon Sep 17 00:00:00 2001 From: Vasily Vasilkov Date: Wed, 7 Oct 2020 23:47:08 +0300 Subject: [PATCH 2/6] Add ability to filter metrics in DropwizardExports Add comments Fix #573 Signed-off-by: Vasily Vasilkov --- .../java/io/prometheus/client/dropwizard/DropwizardExports.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java index 94d3ba598..8aec4f51a 100644 --- a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java +++ b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java @@ -38,6 +38,7 @@ public DropwizardExports(MetricRegistry registry) { * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and custom MetricFilter * * @param registry a metric registry to export in prometheus. + * @param metricFilter a custom metric filter */ public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter) { this.registry = registry; @@ -57,6 +58,7 @@ public DropwizardExports(MetricRegistry registry, SampleBuilder sampleBuilder) { /** * @param registry a metric registry to export in prometheus. + * @param metricFilter a custom metric filter * @param sampleBuilder sampleBuilder to use to create prometheus samples. */ public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter, SampleBuilder sampleBuilder) { From a32fb9b76f4e440a3b35da7c0762ec1c0f55d289 Mon Sep 17 00:00:00 2001 From: Vasily Vasilkov Date: Thu, 8 Oct 2020 20:07:21 +0300 Subject: [PATCH 3/6] Add ability to filter metrics in DropwizardExports Code review fixes Fix #573 Signed-off-by: Vasily Vasilkov --- .../java/io/prometheus/client/dropwizard/DropwizardExports.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java index 8aec4f51a..c691da10e 100644 --- a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java +++ b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java @@ -35,7 +35,7 @@ public DropwizardExports(MetricRegistry registry) { } /** - * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and custom MetricFilter + * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and custom {@link MetricFilter} * * @param registry a metric registry to export in prometheus. * @param metricFilter a custom metric filter From 6e83505aa329a784b0ee398871d72130fd0e3b76 Mon Sep 17 00:00:00 2001 From: Vasily Vasilkov Date: Thu, 8 Oct 2020 23:48:30 +0300 Subject: [PATCH 4/6] Add ability to filter metrics in DropwizardExports Code review fixes, split wildcard import into concrete classes Fix #573 Signed-off-by: Vasily Vasilkov --- .../client/dropwizard/DropwizardExports.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java index c691da10e..0780bafd7 100644 --- a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java +++ b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java @@ -1,6 +1,14 @@ package io.prometheus.client.dropwizard; -import com.codahale.metrics.*; +import com.codahale.metrics.Counter; +import com.codahale.metrics.Metric; +import com.codahale.metrics.Gauge; +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Timer; +import com.codahale.metrics.Snapshot; +import com.codahale.metrics.Meter; +import com.codahale.metrics.MetricFilter; +import com.codahale.metrics.MetricRegistry; import io.prometheus.client.dropwizard.samplebuilder.SampleBuilder; import io.prometheus.client.dropwizard.samplebuilder.DefaultSampleBuilder; From caeb938eaf2a2cb529755ead5a9c4f39450942dd Mon Sep 17 00:00:00 2001 From: Vasily Vasilkov Date: Wed, 14 Oct 2020 00:39:33 +0300 Subject: [PATCH 5/6] Add ability to filter metrics in DropwizardExports Code review fixes Fix #573 Signed-off-by: Vasily Vasilkov --- .../client/dropwizard/DropwizardExports.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java index 0780bafd7..2679a3f89 100644 --- a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java +++ b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java @@ -1,14 +1,14 @@ package io.prometheus.client.dropwizard; import com.codahale.metrics.Counter; -import com.codahale.metrics.Metric; import com.codahale.metrics.Gauge; import com.codahale.metrics.Histogram; -import com.codahale.metrics.Timer; -import com.codahale.metrics.Snapshot; import com.codahale.metrics.Meter; +import com.codahale.metrics.Metric; import com.codahale.metrics.MetricFilter; import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Snapshot; +import com.codahale.metrics.Timer; import io.prometheus.client.dropwizard.samplebuilder.SampleBuilder; import io.prometheus.client.dropwizard.samplebuilder.DefaultSampleBuilder; @@ -32,7 +32,7 @@ public class DropwizardExports extends io.prometheus.client.Collector implements private SampleBuilder sampleBuilder; /** - * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and {@link MetricFilter#ALL} + * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and {@link MetricFilter#ALL}. * * @param registry a metric registry to export in prometheus. */ @@ -43,10 +43,10 @@ public DropwizardExports(MetricRegistry registry) { } /** - * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and custom {@link MetricFilter} + * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and custom {@link MetricFilter}. * * @param registry a metric registry to export in prometheus. - * @param metricFilter a custom metric filter + * @param metricFilter a custom metric filter. */ public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter) { this.registry = registry; @@ -66,7 +66,7 @@ public DropwizardExports(MetricRegistry registry, SampleBuilder sampleBuilder) { /** * @param registry a metric registry to export in prometheus. - * @param metricFilter a custom metric filter + * @param metricFilter a custom metric filter. * @param sampleBuilder sampleBuilder to use to create prometheus samples. */ public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter, SampleBuilder sampleBuilder) { From 708975eac45490b539d465b5ca8d7e2b4c84fe19 Mon Sep 17 00:00:00 2001 From: Vasily Vasilkov Date: Wed, 14 Oct 2020 10:15:59 +0300 Subject: [PATCH 6/6] Add ability to filter metrics in DropwizardExports Code review fixes Fix #573 Signed-off-by: Vasily Vasilkov --- .../io/prometheus/client/dropwizard/DropwizardExports.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java index 2679a3f89..4bf89899f 100644 --- a/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java +++ b/simpleclient_dropwizard/src/main/java/io/prometheus/client/dropwizard/DropwizardExports.java @@ -45,7 +45,7 @@ public DropwizardExports(MetricRegistry registry) { /** * Creates a new DropwizardExports with a {@link DefaultSampleBuilder} and custom {@link MetricFilter}. * - * @param registry a metric registry to export in prometheus. + * @param registry a metric registry to export in prometheus. * @param metricFilter a custom metric filter. */ public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter) { @@ -66,7 +66,7 @@ public DropwizardExports(MetricRegistry registry, SampleBuilder sampleBuilder) { /** * @param registry a metric registry to export in prometheus. - * @param metricFilter a custom metric filter. + * @param metricFilter a custom metric filter. * @param sampleBuilder sampleBuilder to use to create prometheus samples. */ public DropwizardExports(MetricRegistry registry, MetricFilter metricFilter, SampleBuilder sampleBuilder) {