Add non bound usage to the various metric instruments API (#715)

* WIP on non-bound instrument usages

* Add API methods for non-bound-instrument usages

* add missing javadoc

* add some additional javadoc
This commit is contained in:
John Watson 2019-12-19 16:28:03 -08:00 committed by Bogdan Drutu
parent 64fadf279f
commit fc9a9575c8
7 changed files with 96 additions and 3 deletions

View File

@ -175,6 +175,9 @@ public final class DefaultMeter implements Meter {
/** Creates a new {@code NoopBound}. */ /** Creates a new {@code NoopBound}. */
private NoopLongGauge() {} private NoopLongGauge() {}
@Override
public void set(long val, LabelSet labelSet) {}
@Override @Override
public NoopBoundLongGauge bind(LabelSet labelSet) { public NoopBoundLongGauge bind(LabelSet labelSet) {
Utils.checkNotNull(labelSet, "labelSet"); Utils.checkNotNull(labelSet, "labelSet");
@ -215,6 +218,9 @@ public final class DefaultMeter implements Meter {
/** Creates a new {@code NoopBound}. */ /** Creates a new {@code NoopBound}. */
private NoopDoubleGauge() {} private NoopDoubleGauge() {}
@Override
public void set(double val, LabelSet labelSet) {}
@Override @Override
public NoopBoundDoubleGauge bind(LabelSet labelSet) { public NoopBoundDoubleGauge bind(LabelSet labelSet) {
Utils.checkNotNull(labelSet, "labelSet"); Utils.checkNotNull(labelSet, "labelSet");
@ -255,6 +261,9 @@ public final class DefaultMeter implements Meter {
/** Creates a new {@code NoopBound}. */ /** Creates a new {@code NoopBound}. */
private NoopDoubleCounter() {} private NoopDoubleCounter() {}
@Override
public void add(double delta, LabelSet labelSet) {}
@Override @Override
public NoopBoundDoubleCounter bind(LabelSet labelSet) { public NoopBoundDoubleCounter bind(LabelSet labelSet) {
Utils.checkNotNull(labelSet, "labelSet"); Utils.checkNotNull(labelSet, "labelSet");
@ -295,6 +304,9 @@ public final class DefaultMeter implements Meter {
/** Creates a new {@code NoopBound}. */ /** Creates a new {@code NoopBound}. */
private NoopLongCounter() {} private NoopLongCounter() {}
@Override
public void add(long delta, LabelSet labelSet) {}
@Override @Override
public NoopBoundLongCounter bind(LabelSet labelSet) { public NoopBoundLongCounter bind(LabelSet labelSet) {
Utils.checkNotNull(labelSet, "labelSet"); Utils.checkNotNull(labelSet, "labelSet");
@ -334,6 +346,11 @@ public final class DefaultMeter implements Meter {
/** Creates a new {@code NoopDoubleMeasure}. */ /** Creates a new {@code NoopDoubleMeasure}. */
private NoopDoubleMeasure() {} private NoopDoubleMeasure() {}
@Override
public void record(double value, LabelSet labelSet) {
Utils.checkArgument(value >= 0.0, "Unsupported negative values.");
}
@Override @Override
public NoopBoundDoubleMeasure bind(LabelSet labelSet) { public NoopBoundDoubleMeasure bind(LabelSet labelSet) {
Utils.checkNotNull(labelSet, "labelSet"); Utils.checkNotNull(labelSet, "labelSet");
@ -374,6 +391,11 @@ public final class DefaultMeter implements Meter {
private static final class NoopLongMeasure implements LongMeasure { private static final class NoopLongMeasure implements LongMeasure {
private NoopLongMeasure() {} private NoopLongMeasure() {}
@Override
public void record(long value, LabelSet labelSet) {
Utils.checkArgument(value >= 0, "Unsupported negative values.");
}
@Override @Override
public NoopBoundLongMeasure bind(LabelSet labelSet) { public NoopBoundLongMeasure bind(LabelSet labelSet) {
Utils.checkNotNull(labelSet, "labelSet"); Utils.checkNotNull(labelSet, "labelSet");

View File

@ -52,6 +52,18 @@ import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe @ThreadSafe
public interface DoubleCounter extends Counter<BoundDoubleCounter> { public interface DoubleCounter extends Counter<BoundDoubleCounter> {
/**
* Adds the given {@code delta} to the current value. The values can be negative iff monotonic was
* set to {@code false}.
*
* <p>The value added is associated with the current {@code Context} and provided LabelSet.
*
* @param delta the value to add.
* @param labelSet the labels to be associated to this recording
* @since 0.1.0
*/
void add(double delta, LabelSet labelSet);
@Override @Override
BoundDoubleCounter bind(LabelSet labelSet); BoundDoubleCounter bind(LabelSet labelSet);

View File

@ -36,7 +36,7 @@ import javax.annotation.concurrent.ThreadSafe;
* .setUnit("1") * .setUnit("1")
* .setLabelKeys(Collections.singletonList("Key")) * .setLabelKeys(Collections.singletonList("Key"))
* .build(); * .build();
* // It is recommended to keep a reference to a Bound Instrument. * // It is recommended to keep a reference to a Bound Metric.
* private static final BoundDoubleGauge someWorkBound = * private static final BoundDoubleGauge someWorkBound =
* gauge.getBound(Collections.singletonList("SomeWork")); * gauge.getBound(Collections.singletonList("SomeWork"));
* *
@ -52,6 +52,18 @@ import javax.annotation.concurrent.ThreadSafe;
*/ */
@ThreadSafe @ThreadSafe
public interface DoubleGauge extends Gauge<BoundDoubleGauge> { public interface DoubleGauge extends Gauge<BoundDoubleGauge> {
/**
* Sets the given value.
*
* <p>The value added is associated with the current {@code Context} and provided LabelSet.
*
* @param val the new value.
* @param labelSet the labels to be associated to this recording
* @since 0.1.0
*/
void set(double val, LabelSet labelSet);
@Override @Override
BoundDoubleGauge bind(LabelSet labelSet); BoundDoubleGauge bind(LabelSet labelSet);

View File

@ -48,6 +48,18 @@ import javax.annotation.concurrent.ThreadSafe;
*/ */
@ThreadSafe @ThreadSafe
public interface DoubleMeasure extends Measure<BoundDoubleMeasure> { public interface DoubleMeasure extends Measure<BoundDoubleMeasure> {
/**
* Records the given measurement, associated with the current {@code Context} and provided
* LabelSet.
*
* @param value the measurement to record.
* @param labelSet the labels to be associated to this recording
* @throws IllegalArgumentException if value is negative.
* @since 0.1.0
*/
void record(double value, LabelSet labelSet);
@Override @Override
BoundDoubleMeasure bind(LabelSet labelSet); BoundDoubleMeasure bind(LabelSet labelSet);

View File

@ -52,6 +52,18 @@ import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe @ThreadSafe
public interface LongCounter extends Metric<BoundLongCounter> { public interface LongCounter extends Metric<BoundLongCounter> {
/**
* Adds the given {@code delta} to the current value. The values can be negative iff monotonic was
* set to {@code false}.
*
* <p>The value added is associated with the current {@code Context} and provided LabelSet.
*
* @param delta the value to add.
* @param labelSet the labels to be associated to this recording.
* @since 0.1.0
*/
void add(long delta, LabelSet labelSet);
@Override @Override
BoundLongCounter bind(LabelSet labelSet); BoundLongCounter bind(LabelSet labelSet);

View File

@ -36,7 +36,7 @@ import javax.annotation.concurrent.ThreadSafe;
* .setUnit("1") * .setUnit("1")
* .setLabelKeys(Collections.singletonList("Key")) * .setLabelKeys(Collections.singletonList("Key"))
* .build(); * .build();
* // It is recommended to keep a reference to a Bound Instrument. * // It is recommended to keep a reference to a Bound Metric.
* private static final BoundLongGauge someWorkBound = * private static final BoundLongGauge someWorkBound =
* gauge.getBound(Collections.singletonList("SomeWork")); * gauge.getBound(Collections.singletonList("SomeWork"));
* *
@ -53,6 +53,17 @@ import javax.annotation.concurrent.ThreadSafe;
@ThreadSafe @ThreadSafe
public interface LongGauge extends Gauge<BoundLongGauge> { public interface LongGauge extends Gauge<BoundLongGauge> {
/**
* Sets the given value for the gauge.
*
* <p>The value added is associated with the current {@code Context} and provided LabelSet.
*
* @param val the new value.
* @param labelSet the labels to be associated to this value
* @since 0.1.0
*/
void set(long val, LabelSet labelSet);
@Override @Override
BoundLongGauge bind(LabelSet labelSet); BoundLongGauge bind(LabelSet labelSet);
@ -67,7 +78,7 @@ public interface LongGauge extends Gauge<BoundLongGauge> {
interface BoundLongGauge { interface BoundLongGauge {
/** /**
* Sets the given value. * Sets the given value for the gauge.
* *
* <p>The value added is associated with the current {@code Context}. * <p>The value added is associated with the current {@code Context}.
* *

View File

@ -48,6 +48,18 @@ import javax.annotation.concurrent.ThreadSafe;
*/ */
@ThreadSafe @ThreadSafe
public interface LongMeasure extends Measure<BoundLongMeasure> { public interface LongMeasure extends Measure<BoundLongMeasure> {
/**
* Records the given measurement, associated with the current {@code Context} and provided
* LabelSet.
*
* @param value the measurement to record.
* @param labelSet the labels to be associated to this recording
* @throws IllegalArgumentException if value is negative.
* @since 0.1.0
*/
void record(long value, LabelSet labelSet);
@Override @Override
BoundLongMeasure bind(LabelSet labelSet); BoundLongMeasure bind(LabelSet labelSet);