diff options
author | Mayur Kale <mayurkale@google.com> | 2018-10-17 22:09:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-17 22:09:40 -0700 |
commit | 30b613fcbf329bf130ae18267b431c4f820bbe28 (patch) | |
tree | 327465dd6ad7c9d34815ed0baa25209711560027 /api/src/main/java | |
parent | 2f53b977da6b10b7f8e8c29d83f0478d470b229c (diff) | |
download | opencensus-java-30b613fcbf329bf130ae18267b431c4f820bbe28.tar.gz |
Plugs-in the DoubleGauge into the registry (#1503)
Diffstat (limited to 'api/src/main/java')
-rw-r--r-- | api/src/main/java/io/opencensus/metrics/DoubleGauge.java | 5 | ||||
-rw-r--r-- | api/src/main/java/io/opencensus/metrics/MetricRegistry.java | 29 |
2 files changed, 31 insertions, 3 deletions
diff --git a/api/src/main/java/io/opencensus/metrics/DoubleGauge.java b/api/src/main/java/io/opencensus/metrics/DoubleGauge.java index de2b053b..32759973 100644 --- a/api/src/main/java/io/opencensus/metrics/DoubleGauge.java +++ b/api/src/main/java/io/opencensus/metrics/DoubleGauge.java @@ -32,7 +32,7 @@ import javax.annotation.concurrent.ThreadSafe; * private static final MetricRegistry metricRegistry = Metrics.getMetricRegistry(); * * List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc")); - * // TODO(mayurkale): Plugs-in the DoubleGauge into the registry. + * * DoubleGauge gauge = metricRegistry.addDoubleGauge("queue_size", * "Pending jobs", "1", labelKeys); * @@ -57,7 +57,6 @@ import javax.annotation.concurrent.ThreadSafe; * List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("Name", "desc")); * List<LabelValue> labelValues = Arrays.asList(LabelValue.create("Inbound")); * - * // TODO(mayurkale): Plugs-in the DoubleGauge into the registry. * DoubleGauge gauge = metricRegistry.addDoubleGauge("queue_size", * "Pending jobs", "1", labelKeys); * @@ -86,7 +85,7 @@ public abstract class DoubleGauge { * method for manual operations. * * @param labelValues the list of label values. The number of label values must be the same to - * that of the label keys. + * that of the label keys passed to {@link MetricRegistry#addDoubleGauge}. * @return a {@code DoublePoint} the value of single gauge. * @throws NullPointerException if {@code labelValues} is null OR any element of {@code * labelValues} is null. diff --git a/api/src/main/java/io/opencensus/metrics/MetricRegistry.java b/api/src/main/java/io/opencensus/metrics/MetricRegistry.java index 840ad787..557f886a 100644 --- a/api/src/main/java/io/opencensus/metrics/MetricRegistry.java +++ b/api/src/main/java/io/opencensus/metrics/MetricRegistry.java @@ -46,6 +46,23 @@ public abstract class MetricRegistry { public abstract LongGauge addLongGauge( String name, String description, String unit, List<LabelKey> labelKeys); + /** + * Builds a new double gauge to be added to the registry. This is more convenient form when you + * want to manually increase and decrease values as per your service requirements. + * + * @param name the name of the metric. + * @param description the description of the metric. + * @param unit the unit of the metric. + * @param labelKeys the list of the label keys. + * @throws NullPointerException if {@code labelKeys} is null OR any element of {@code labelKeys} + * is null OR {@code name}, {@code description}, {@code unit} is null. + * @throws IllegalArgumentException if different metric with the same name already registered. + * @since 0.17 + */ + @ExperimentalApi + public abstract DoubleGauge addDoubleGauge( + String name, String description, String unit, List<LabelKey> labelKeys); + static MetricRegistry newNoopMetricRegistry() { return new NoopMetricRegistry(); } @@ -63,5 +80,17 @@ public abstract class MetricRegistry { Utils.checkNotNull(unit, "unit"), labelKeys); } + + @Override + public DoubleGauge addDoubleGauge( + String name, String description, String unit, List<LabelKey> labelKeys) { + Utils.checkListElementNotNull( + Utils.checkNotNull(labelKeys, "labelKeys"), "labelKey element should not be null."); + return DoubleGauge.newNoopDoubleGauge( + Utils.checkNotNull(name, "name"), + Utils.checkNotNull(description, "description"), + Utils.checkNotNull(unit, "unit"), + labelKeys); + } } } |