diff options
author | Mayur Kale <mayurkale@google.com> | 2018-10-14 17:36:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-14 17:36:19 -0700 |
commit | 418e675ee250299b77370620229bf7d3cd6c6830 (patch) | |
tree | cc1d1ff1105fe5f1c7b387e97984a0fb0908d9d3 /impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java | |
parent | 53b1b60633cc3704bdaf0bd84efb3d2503578b20 (diff) | |
download | opencensus-java-418e675ee250299b77370620229bf7d3cd6c6830.tar.gz |
Metrics/Metric: Add a version of create that accepts only one timeseries. (#1495)
* Metrics/Metric: Add createWithOneTimeSeries method
* Fix review comments
Diffstat (limited to 'impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java')
-rw-r--r-- | impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java b/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java index 4ad4e354..a7f84347 100644 --- a/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java +++ b/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java @@ -129,18 +129,21 @@ public final class LongGaugeImpl extends LongGauge implements Meter { @Override public Metric getMetric(Clock clock) { Map<List<LabelValue>, PointImpl> currentRegisteredPoints = registeredPoints; + if (currentRegisteredPoints.isEmpty()) { + return null; + } int pointCount = currentRegisteredPoints.size(); - if (pointCount > 0) { - List<TimeSeries> timeSeriesList = new ArrayList<TimeSeries>(pointCount); - for (Map.Entry<List<LabelValue>, PointImpl> entry : currentRegisteredPoints.entrySet()) { - timeSeriesList.add(entry.getValue().getTimeSeries(clock)); - } - - // TODO(mayurkale): optimize this for 1 timeseries (issue #1491). - return Metric.create(metricDescriptor, timeSeriesList); + if (pointCount == 1) { + PointImpl point = currentRegisteredPoints.values().iterator().next(); + return Metric.createWithOneTimeSeries(metricDescriptor, point.getTimeSeries(clock)); + } + + List<TimeSeries> timeSeriesList = new ArrayList<TimeSeries>(pointCount); + for (Map.Entry<List<LabelValue>, PointImpl> entry : currentRegisteredPoints.entrySet()) { + timeSeriesList.add(entry.getValue().getTimeSeries(clock)); } - return null; + return Metric.create(metricDescriptor, timeSeriesList); } /** Implementation of {@link LongGauge.LongPoint}. */ |