aboutsummaryrefslogtreecommitdiff
path: root/api/src/main/java
diff options
context:
space:
mode:
authorMayur Kale <mayurkale@google.com>2018-10-17 14:15:48 -0700
committerGitHub <noreply@github.com>2018-10-17 14:15:48 -0700
commit2b11b167c8d7633acaacc0c6aca6b829e8f4df6d (patch)
treed897760da801edea5416c78eab6ff87c9c3ea81f /api/src/main/java
parente56a976d242d34b65e224f74d91fbafec83f96ad (diff)
downloadopencensus-java-2b11b167c8d7633acaacc0c6aca6b829e8f4df6d.tar.gz
Plugs-in the LongGauge into the registry (#1498)
* plug-in longGauge into MetricRegistry * Minor fix * Add TODO and Fix build * Fix review comments
Diffstat (limited to 'api/src/main/java')
-rw-r--r--api/src/main/java/io/opencensus/metrics/DoubleGauge.java4
-rw-r--r--api/src/main/java/io/opencensus/metrics/LongGauge.java8
-rw-r--r--api/src/main/java/io/opencensus/metrics/MetricRegistry.java81
3 files changed, 22 insertions, 71 deletions
diff --git a/api/src/main/java/io/opencensus/metrics/DoubleGauge.java b/api/src/main/java/io/opencensus/metrics/DoubleGauge.java
index 91e131ec..62730a06 100644
--- a/api/src/main/java/io/opencensus/metrics/DoubleGauge.java
+++ b/api/src/main/java/io/opencensus/metrics/DoubleGauge.java
@@ -86,12 +86,12 @@ 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 passed to {@link MetricRegistry#addDoubleGauge}.
+ * that of the label keys.
* @return a {@code DoublePoint} the value of single gauge.
* @throws NullPointerException if {@code labelValues} is null OR any element of {@code
* labelValues} is null.
* @throws IllegalArgumentException if number of {@code labelValues}s are not equal to the label
- * keys passed to {@link MetricRegistry#addDoubleGauge}.
+ * keys.
* @since 0.17
*/
public abstract DoublePoint getOrCreateTimeSeries(List<LabelValue> labelValues);
diff --git a/api/src/main/java/io/opencensus/metrics/LongGauge.java b/api/src/main/java/io/opencensus/metrics/LongGauge.java
index 42951d50..f473a8ac 100644
--- a/api/src/main/java/io/opencensus/metrics/LongGauge.java
+++ b/api/src/main/java/io/opencensus/metrics/LongGauge.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 LongGauge into the registry.
+ *
* LongGauge gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
*
* // It is recommended to keep a reference of a point for manual operations.
@@ -56,7 +56,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 LongGauge into the registry.
* LongGauge gauge = metricRegistry.addLongGauge("queue_size", "Pending jobs", "1", labelKeys);
*
* // It is recommended to keep a reference of a point for manual operations.
@@ -167,11 +166,6 @@ public abstract class LongGauge {
/** Creates a new {@code NoopLongPoint}. */
NoopLongGauge(String name, String description, String unit, List<LabelKey> labelKeys) {
- Utils.checkNotNull(name, "name");
- Utils.checkNotNull(description, "description");
- Utils.checkNotNull(unit, "unit");
- Utils.checkNotNull(labelKeys, "labelKeys should not be null.");
- Utils.checkListElementNotNull(labelKeys, "labelKeys element should not be null.");
labelKeysSize = labelKeys.size();
}
diff --git a/api/src/main/java/io/opencensus/metrics/MetricRegistry.java b/api/src/main/java/io/opencensus/metrics/MetricRegistry.java
index a9987b75..840ad787 100644
--- a/api/src/main/java/io/opencensus/metrics/MetricRegistry.java
+++ b/api/src/main/java/io/opencensus/metrics/MetricRegistry.java
@@ -17,10 +17,8 @@
package io.opencensus.metrics;
import io.opencensus.common.ExperimentalApi;
-import io.opencensus.common.ToDoubleFunction;
-import io.opencensus.common.ToLongFunction;
import io.opencensus.internal.Utils;
-import java.util.LinkedHashMap;
+import java.util.List;
/**
* Creates and manages your application's set of metrics. The default implementation of this creates
@@ -32,44 +30,21 @@ import java.util.LinkedHashMap;
@ExperimentalApi
public abstract class MetricRegistry {
/**
- * Build a new long gauge to be added to the registry.
- *
- * <p>Must be called only once.
+ * Builds a new long 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 obj the function argument.
- * @param function the function to be called.
+ * @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
*/
- public abstract <T> void addLongGauge(
- String name,
- String description,
- String unit,
- LinkedHashMap<LabelKey, LabelValue> labels,
- T obj,
- ToLongFunction<T> function);
-
- /**
- * Build a new double gauge to be added to the registry.
- *
- * <p>Must be called only once.
- *
- * @param name the name of the metric.
- * @param description the description of the metric.
- * @param unit the unit of the metric.
- * @param obj the function argument.
- * @param function the function to be called.
- * @since 0.17
- */
- public abstract <T> void addDoubleGauge(
- String name,
- String description,
- String unit,
- LinkedHashMap<LabelKey, LabelValue> labels,
- T obj,
- ToDoubleFunction<T> function);
+ @ExperimentalApi
+ public abstract LongGauge addLongGauge(
+ String name, String description, String unit, List<LabelKey> labelKeys);
static MetricRegistry newNoopMetricRegistry() {
return new NoopMetricRegistry();
@@ -78,33 +53,15 @@ public abstract class MetricRegistry {
private static final class NoopMetricRegistry extends MetricRegistry {
@Override
- public <T> void addLongGauge(
- String name,
- String description,
- String unit,
- LinkedHashMap<LabelKey, LabelValue> labels,
- T obj,
- ToLongFunction<T> function) {
- Utils.checkNotNull(name, "name");
- Utils.checkNotNull(description, "description");
- Utils.checkNotNull(unit, "unit");
- Utils.checkNotNull(labels, "labels");
- Utils.checkNotNull(function, "function");
- }
-
- @Override
- public <T> void addDoubleGauge(
- String name,
- String description,
- String unit,
- LinkedHashMap<LabelKey, LabelValue> labels,
- T obj,
- ToDoubleFunction<T> function) {
- Utils.checkNotNull(name, "name");
- Utils.checkNotNull(description, "description");
- Utils.checkNotNull(unit, "unit");
- Utils.checkNotNull(labels, "labels");
- Utils.checkNotNull(function, "function");
+ public LongGauge addLongGauge(
+ String name, String description, String unit, List<LabelKey> labelKeys) {
+ Utils.checkListElementNotNull(
+ Utils.checkNotNull(labelKeys, "labelKeys"), "labelKey element should not be null.");
+ return LongGauge.newNoopLongGauge(
+ Utils.checkNotNull(name, "name"),
+ Utils.checkNotNull(description, "description"),
+ Utils.checkNotNull(unit, "unit"),
+ labelKeys);
}
}
}