diff options
| author | Thor Anker Kvisgård Lange <lange@kvisgaard-lange.dk> | 2018-07-12 21:43:32 +0200 |
|---|---|---|
| committer | Yang Song <songy23@users.noreply.github.com> | 2018-07-12 12:43:32 -0700 |
| commit | d4d2956db232c408f188443a6914e8cde603c871 (patch) | |
| tree | 2282c6a8ded0d6bba3f8f66c94ea5fb0a1dae3be /exporters | |
| parent | d3a3fbf5a6151c621b49f88942fcdeb09e856ce6 (diff) | |
| download | platform_external_opencensus-java-d4d2956db232c408f188443a6914e8cde603c871.tar.gz platform_external_opencensus-java-d4d2956db232c408f188443a6914e8cde603c871.tar.bz2 platform_external_opencensus-java-d4d2956db232c408f188443a6914e8cde603c871.zip | |
Export cumulative buckets for Prometheus (#1309)
* census-instrumentation/opencensus-java#1307 Prometheus does cumulative counts in the historgram buckets, see also io.prometheus.client.Histogram.Child.observe(..)
* Rename variable to be more precise about its purpose
Diffstat (limited to 'exporters')
3 files changed, 9 insertions, 7 deletions
diff --git a/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java b/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java index fe54c4df..b13af308 100644 --- a/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java +++ b/exporters/stats/prometheus/src/main/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtils.java @@ -190,6 +190,7 @@ final class PrometheusExportUtils { List<Double> boundaries = distribution.getBucketBoundaries().getBoundaries(); List<String> labelNamesWithLe = new ArrayList<String>(labelNames); labelNamesWithLe.add(LABEL_NAME_BUCKET_BOUND); + long cumulativeCount = 0; for (int i = 0; i < arg.getBucketCounts().size(); i++) { List<String> labelValuesWithLe = new ArrayList<String>(labelValues); // The label value of "le" is the upper inclusive bound. @@ -198,12 +199,13 @@ final class PrometheusExportUtils { doubleToGoString( i < boundaries.size() ? boundaries.get(i) : Double.POSITIVE_INFINITY); labelValuesWithLe.add(bucketBoundary); + cumulativeCount += arg.getBucketCounts().get(i); samples.add( new MetricFamilySamples.Sample( name + SAMPLE_SUFFIX_BUCKET, labelNamesWithLe, labelValuesWithLe, - arg.getBucketCounts().get(i))); + cumulativeCount)); } samples.add( diff --git a/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java b/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java index d8ab2d8d..ca8315b9 100644 --- a/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java +++ b/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusExportUtilsTest.java @@ -211,9 +211,9 @@ public class PrometheusExportUtilsTest { new Sample( SAMPLE_NAME + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v1", "0.0"), 2), new Sample( - SAMPLE_NAME + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v1", "5.0"), 2), + SAMPLE_NAME + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v1", "5.0"), 4), new Sample( - SAMPLE_NAME + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v1", "+Inf"), 1), + SAMPLE_NAME + "_bucket", Arrays.asList("k1", "le"), Arrays.asList("v1", "+Inf"), 5), new Sample(SAMPLE_NAME + "_count", Arrays.asList("k1"), Arrays.asList("v1"), 5), new Sample(SAMPLE_NAME + "_sum", Arrays.asList("k1"), Arrays.asList("v1"), 22.0)) .inOrder(); @@ -303,12 +303,12 @@ public class PrometheusExportUtilsTest { new Sample( "view_3_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "0.0"), 2), new Sample( - "view_3_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "5.0"), 2), + "view_3_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "5.0"), 4), new Sample( "view_3_bucket", Arrays.asList("k1", "le"), Arrays.asList("v-3", "+Inf"), - 1), + 5), new Sample("view_3_count", Arrays.asList("k1"), Arrays.asList("v-3"), 5), new Sample("view_3_sum", Arrays.asList("k1"), Arrays.asList("v-3"), 22.0)))); assertThat( diff --git a/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusStatsCollectorTest.java b/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusStatsCollectorTest.java index 7010ff03..3bd98451 100644 --- a/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusStatsCollectorTest.java +++ b/exporters/stats/prometheus/src/test/java/io/opencensus/exporter/stats/prometheus/PrometheusStatsCollectorTest.java @@ -122,12 +122,12 @@ public class PrometheusStatsCollectorTest { name + "_bucket", Arrays.asList("k1", "k2", "le"), Arrays.asList("v1", "v2", "5.0"), - 2), + 4), new Sample( name + "_bucket", Arrays.asList("k1", "k2", "le"), Arrays.asList("v1", "v2", "+Inf"), - 1), + 5), new Sample( name + "_count", Arrays.asList("k1", "k2"), Arrays.asList("v1", "v2"), 5), new Sample( |
