diff --git a/api/src/main/java/io/opentelemetry/metrics/DefaultMeter.java b/api/src/main/java/io/opentelemetry/metrics/DefaultMeter.java index 6bfef5935af..70fc486e882 100644 --- a/api/src/main/java/io/opentelemetry/metrics/DefaultMeter.java +++ b/api/src/main/java/io/opentelemetry/metrics/DefaultMeter.java @@ -47,24 +47,6 @@ public static Meter getInstance() { return INSTANCE; } - @Override - public LongGauge.Builder longGaugeBuilder(String name) { - Utils.checkNotNull(name, "name"); - Utils.checkArgument( - StringUtils.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, - ERROR_MESSAGE_INVALID_NAME); - return new NoopLongGauge.NoopBuilder(); - } - - @Override - public DoubleGauge.Builder doubleGaugeBuilder(String name) { - Utils.checkNotNull(name, "name"); - Utils.checkArgument( - StringUtils.isPrintableString(name) && name.length() <= NAME_MAX_LENGTH, - ERROR_MESSAGE_INVALID_NAME); - return new NoopDoubleGauge.NoopBuilder(); - } - @Override public DoubleCounter.Builder doubleCounterBuilder(String name) { Utils.checkNotNull(name, "name"); @@ -143,96 +125,6 @@ public LabelSet createLabelSet(Map labels) { return NoopLabelSet.INSTANCE; } - /** No-op implementation of LongGauge interface. */ - @Immutable - private static final class NoopLongGauge implements LongGauge { - - /** Creates a new {@code NoopBound}. */ - private NoopLongGauge() {} - - @Override - public void set(long val, LabelSet labelSet) {} - - @Override - public NoopBoundLongGauge bind(LabelSet labelSet) { - Utils.checkNotNull(labelSet, "labelSet"); - return NoopBoundLongGauge.INSTANCE; - } - - @Override - public void unbind(BoundLongGauge boundInstrument) { - Utils.checkNotNull(boundInstrument, "boundLongGauge"); - } - - /** No-op implementation of BoundLongGauge interface. */ - @Immutable - private enum NoopBoundLongGauge implements BoundLongGauge { - INSTANCE; - - @Override - public void set(long val) {} - } - - private static final class NoopBuilder extends NoopAbstractGaugeBuilder - implements Builder { - - @Override - protected Builder getThis() { - return this; - } - - @Override - public LongGauge build() { - return new NoopLongGauge(); - } - } - } - - /** No-op implementation of DoubleGauge interface. */ - @Immutable - private static final class NoopDoubleGauge implements DoubleGauge { - - /** Creates a new {@code NoopBound}. */ - private NoopDoubleGauge() {} - - @Override - public void set(double val, LabelSet labelSet) {} - - @Override - public NoopBoundDoubleGauge bind(LabelSet labelSet) { - Utils.checkNotNull(labelSet, "labelSet"); - return NoopBoundDoubleGauge.INSTANCE; - } - - @Override - public void unbind(BoundDoubleGauge boundInstrument) { - Utils.checkNotNull(boundInstrument, "boundDoubleGauge"); - } - - /** No-op implementation of BoundDoubleGauge interface. */ - @Immutable - private enum NoopBoundDoubleGauge implements BoundDoubleGauge { - INSTANCE; - - @Override - public void set(double val) {} - } - - private static final class NoopBuilder extends NoopAbstractGaugeBuilder - implements Builder { - - @Override - protected Builder getThis() { - return this; - } - - @Override - public DoubleGauge build() { - return new NoopDoubleGauge(); - } - } - } - /** No-op implementation of DoubleCounter interface. */ @Immutable private static final class NoopDoubleCounter implements DoubleCounter { @@ -500,15 +392,6 @@ public BatchRecorder put(DoubleMeasure measure, double value) { public void record() {} } - private abstract static class NoopAbstractGaugeBuilder, V> - extends NoopAbstractInstrumentBuilder implements Gauge.Builder { - - @Override - public B setMonotonic(boolean monotonic) { - return getThis(); - } - } - private abstract static class NoopAbstractCounterBuilder, V> extends NoopAbstractInstrumentBuilder implements Counter.Builder { diff --git a/api/src/main/java/io/opentelemetry/metrics/DoubleGauge.java b/api/src/main/java/io/opentelemetry/metrics/DoubleGauge.java deleted file mode 100644 index 2c04dcc5ad0..00000000000 --- a/api/src/main/java/io/opentelemetry/metrics/DoubleGauge.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.metrics; - -import io.opentelemetry.metrics.DoubleGauge.BoundDoubleGauge; -import javax.annotation.concurrent.ThreadSafe; - -/** - * Gauge metric, to report instantaneous measurement of a double value. Gauges can go both up and - * down. The gauges values can be negative. - * - *

Example: - * - *

{@code
- * class YourClass {
- *
- *   private static final Meter meter = OpenTelemetry.getMeterRegistry().get("my_library_name");
- *   private static final DoubleGauge gauge =
- *       meter
- *           .gaugeDoubleBuilder("processed_jobs")
- *           .setDescription("Processed jobs")
- *           .setUnit("1")
- *           .setLabelKeys(Collections.singletonList("Key"))
- *           .build();
- *   // It is recommended to keep a reference to a Bound Instrument.
- *   private static final BoundDoubleGauge someWorkBound =
- *       gauge.getBound(Collections.singletonList("SomeWork"));
- *
- *   void doSomeWork() {
- *      // Your code here.
- *      someWorkBound.set(15);
- *   }
- *
- * }
- * }
- * - * @since 0.1.0 - */ -@ThreadSafe -public interface DoubleGauge extends Gauge { - - /** - * Sets the given value. - * - *

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 - BoundDoubleGauge bind(LabelSet labelSet); - - @Override - void unbind(BoundDoubleGauge boundInstrument); - - /** - * A {@code Bound Instrument} for a {@code DoubleGauge}. - * - * @since 0.1.0 - */ - @ThreadSafe - interface BoundDoubleGauge { - - /** - * Sets the given value. - * - *

The value added is associated with the current {@code Context}. - * - * @param val the new value. - * @since 0.1.0 - */ - void set(double val); - } - - /** Builder class for {@link LongGauge}. */ - interface Builder extends Gauge.Builder {} -} diff --git a/api/src/main/java/io/opentelemetry/metrics/Gauge.java b/api/src/main/java/io/opentelemetry/metrics/Gauge.java deleted file mode 100644 index 70363e25ea8..00000000000 --- a/api/src/main/java/io/opentelemetry/metrics/Gauge.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.metrics; - -/** - * Base interface for all the Gauge metrics. - * - * @param the specific Bound Gauge type. - * @since 0.1.0 - */ -public interface Gauge extends InstrumentWithBinding { - /** Builder class for {@link Gauge}. */ - interface Builder, V> extends Instrument.Builder { - /** - * Sets the monotonicity property for this {@code Instrument}. If {@code true} successive values - * are expected to rise monotonically. - * - *

Default value is {@code false} - * - * @param monotonic {@code true} successive values are expected to rise monotonically. - * @return this. - */ - B setMonotonic(boolean monotonic); - } -} diff --git a/api/src/main/java/io/opentelemetry/metrics/LongGauge.java b/api/src/main/java/io/opentelemetry/metrics/LongGauge.java deleted file mode 100644 index 76b35840c46..00000000000 --- a/api/src/main/java/io/opentelemetry/metrics/LongGauge.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.metrics; - -import io.opentelemetry.metrics.LongGauge.BoundLongGauge; -import javax.annotation.concurrent.ThreadSafe; - -/** - * Gauge metric, to report instantaneous measurement of an long value. Gauges can go both up and - * down. The gauges values can be negative. - * - *

Example: - * - *

{@code
- * class YourClass {
- *
- *   private static final Meter meter = OpenTelemetry.getMeterRegistry().get("my_library_name");
- *   private static final LongGauge gauge =
- *       meter
- *           .gaugeLongBuilder("processed_jobs")
- *           .setDescription("Processed jobs")
- *           .setUnit("1")
- *           .setLabelKeys(Collections.singletonList("Key"))
- *           .build();
- *   // It is recommended to keep a reference to a Bound Instrument.
- *   private static final BoundLongGauge someWorkBound =
- *       gauge.getBound(Collections.singletonList("SomeWork"));
- *
- *   void doSomeWork() {
- *      // Your code here.
- *      someWorkBound.set(15);
- *   }
- *
- * }
- * }
- * - * @since 0.1.0 - */ -@ThreadSafe -public interface LongGauge extends Gauge { - - /** - * Sets the given value for the gauge. - * - *

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 - BoundLongGauge bind(LabelSet labelSet); - - @Override - void unbind(BoundLongGauge boundInstrument); - - /** - * A {@code Bound Instrument} for a {@code LongGauge}. - * - * @since 0.1.0 - */ - @ThreadSafe - interface BoundLongGauge { - - /** - * Sets the given value for the gauge. - * - *

The value added is associated with the current {@code Context}. - * - * @param val the new value. - * @since 0.1.0 - */ - void set(long val); - } - - /** Builder class for {@link LongGauge}. */ - interface Builder extends Gauge.Builder {} -} diff --git a/api/src/main/java/io/opentelemetry/metrics/Meter.java b/api/src/main/java/io/opentelemetry/metrics/Meter.java index 40c6b8efda4..ae10ceebddb 100644 --- a/api/src/main/java/io/opentelemetry/metrics/Meter.java +++ b/api/src/main/java/io/opentelemetry/metrics/Meter.java @@ -32,114 +32,11 @@ * report cpu/memory usage, or simple metrics like "queue_length". * * - *

Example usage for raw measurement: - * - *

{@code
- * class MyClass {
- *   private static final Meter meter = Metrics.getMeterRegistry().get("my_library_name");
- *   private static final DoubleMeasure cacheHit = meter.measureDoubleBuilder("cache_hit").build();
- *
- *   Response serverBoundr(Request request) {
- *     if (inCache(request)) {
- *       cacheHit.record(1);
- *       return fromCache(request);
- *     }
- *     ...  // do other work
- *   }
- *
- * }
- * }
- * - *

Example usage for already aggregated metrics: - * - *

{@code
- * class YourClass {
- *   private static final Meter meter = Metrics.getMeterRegistry().get("my_library_name");
- *   private static final CounterLong collectionMetric =
- *       meter
- *           .counterLongBuilder("collection")
- *           .setDescription("Time spent in a given JVM garbage collector in milliseconds.")
- *           .setUnit("ms")
- *           .setLabelKeys(Collections.singletonList(GC))
- *           .build();
- *
- *   public final void exportGarbageCollectorMetrics {
- *     collectionMetric.setCallback(
- *         new Runnable() {
- *          {@literal @}Override
- *           public void run() {
- *             for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
- *               LabelValue gcName = LabelValue.create(gc.getName());
- *               collectionMetric
- *                   .getBound(Collections.singletonList(gcName))
- *                   .set(gc.getCollectionTime());
- *             }
- *           }
- *         });
- *   }
- * }
- * }
- * - *

Example usage for simple pre-defined aggregation metrics: - * - *

{@code
- * class YourClass {
- *   private static final Meter meter = Metrics.getMeterRegistry().get("my_library_name");
- *   private static final List keys = Collections.singletonList("Name");
- *   private static final List values = Collections.singletonList("Inbound");
- *   private static final DoubleGauge gauge =
- *       meter
- *           .longGaugeBuilder("queue_size")
- *           .setDescription("Pending jobs")
- *           .setUnit("1")
- *           .setLabelKeys(labelKeys)
- *           .build();
- *
- *   // It is recommended that API users keep a reference to a Bound Instrument.
- *   DoubleGauge.BoundDoubleGauge inboundBoundGauge = gauge.bind(labelValues);
- *
- *   void doAddElement() {
- *      // Your code here.
- *      inboundBoundGauge.set(1);
- *   }
- *
- *   void doRemoveElement() {
- *      inboundBoundGauge.set(-1);
- *      // Your code here.
- *   }
- *
- * }
- * }
+ *

TODO: Update comment. */ @ThreadSafe public interface Meter { - /** - * Returns a builder for a {@link LongGauge}. - * - * @param name the name of the metric. Should be a ASCII string with a length no greater than 255 - * characters. - * @return a {@code LongGauge.Builder}. - * @throws NullPointerException if {@code name} is null. - * @throws IllegalArgumentException if different metric with the same name already registered. - * @throws IllegalArgumentException if the {@code name} does not match the requirements. - * @since 0.1.0 - */ - LongGauge.Builder longGaugeBuilder(String name); - - /** - * Returns a builder for a {@link DoubleGauge}. - * - * @param name the name of the metric. Should be a ASCII string with a length no greater than 255 - * characters. - * @return a {@code DoubleGauge.Builder}. - * @throws NullPointerException if {@code name} is null. - * @throws IllegalArgumentException if different metric with the same name already registered. - * @throws IllegalArgumentException if the {@code name} does not match the requirements. - * @since 0.1.0 - */ - DoubleGauge.Builder doubleGaugeBuilder(String name); - /** * Returns a builder for a {@link DoubleCounter}. * diff --git a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java index 1f0b0d3609c..546aad3a9b2 100644 --- a/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java +++ b/api/src/test/java/io/opentelemetry/OpenTelemetryTest.java @@ -29,12 +29,10 @@ import io.opentelemetry.metrics.BatchRecorder; import io.opentelemetry.metrics.DefaultMeterRegistry; import io.opentelemetry.metrics.DoubleCounter; -import io.opentelemetry.metrics.DoubleGauge; import io.opentelemetry.metrics.DoubleMeasure; import io.opentelemetry.metrics.DoubleObserver; import io.opentelemetry.metrics.LabelSet; import io.opentelemetry.metrics.LongCounter; -import io.opentelemetry.metrics.LongGauge; import io.opentelemetry.metrics.LongMeasure; import io.opentelemetry.metrics.LongObserver; import io.opentelemetry.metrics.Meter; @@ -311,18 +309,6 @@ public MeterRegistry create() { return new FirstMetricsProvider(); } - @Nullable - @Override - public LongGauge.Builder longGaugeBuilder(String name) { - return null; - } - - @Nullable - @Override - public DoubleGauge.Builder doubleGaugeBuilder(String name) { - return null; - } - @Nullable @Override public DoubleCounter.Builder doubleCounterBuilder(String name) { diff --git a/api/src/test/java/io/opentelemetry/metrics/DefaultMeterTest.java b/api/src/test/java/io/opentelemetry/metrics/DefaultMeterTest.java index 89ef658b77e..b3c716f1a58 100644 --- a/api/src/test/java/io/opentelemetry/metrics/DefaultMeterTest.java +++ b/api/src/test/java/io/opentelemetry/metrics/DefaultMeterTest.java @@ -28,20 +28,6 @@ public final class DefaultMeterTest { private static final Meter defaultMeter = DefaultMeter.getInstance(); @Rule public final ExpectedException thrown = ExpectedException.none(); - @Test - public void noopAddLongGauge_NullName() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("name"); - defaultMeter.longGaugeBuilder(null); - } - - @Test - public void noopAddDoubleGauge_NullName() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("name"); - defaultMeter.doubleGaugeBuilder(null); - } - @Test public void noopAddDoubleCumulative_NullName() { thrown.expect(NullPointerException.class); diff --git a/api/src/test/java/io/opentelemetry/metrics/DoubleGaugeTest.java b/api/src/test/java/io/opentelemetry/metrics/DoubleGaugeTest.java deleted file mode 100644 index 3e2b3653950..00000000000 --- a/api/src/test/java/io/opentelemetry/metrics/DoubleGaugeTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.metrics; - -import io.opentelemetry.OpenTelemetry; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link DoubleGauge}. */ -@RunWith(JUnit4.class) -public class DoubleGaugeTest { - @Rule public ExpectedException thrown = ExpectedException.none(); - - private static final String NAME = "name"; - private static final String DESCRIPTION = "description"; - private static final String UNIT = "1"; - private static final List LABEL_KEY = Collections.singletonList("key"); - - private final Meter meter = OpenTelemetry.getMeterRegistry().get("gauge_double_test"); - - @Test - public void preventNonPrintableName() { - thrown.expect(IllegalArgumentException.class); - meter.doubleGaugeBuilder("\2").build(); - } - - @Test - public void preventTooLongName() { - char[] chars = new char[DefaultMeter.NAME_MAX_LENGTH + 1]; - Arrays.fill(chars, 'a'); - String longName = String.valueOf(chars); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME); - meter.doubleGaugeBuilder(longName).build(); - } - - @Test - public void preventNull_Description() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("description"); - meter.doubleGaugeBuilder("metric").setDescription(null).build(); - } - - @Test - public void preventNull_Unit() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("unit"); - meter.doubleGaugeBuilder("metric").setUnit(null).build(); - } - - @Test - public void preventNull_LabelKeys() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("labelKeys"); - meter.doubleGaugeBuilder("metric").setLabelKeys(null).build(); - } - - @Test - public void preventNull_LabelKey() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("labelKey"); - meter - .doubleGaugeBuilder("metric") - .setLabelKeys(Collections.singletonList(null)) - .build(); - } - - @Test - public void preventNull_ConstantLabels() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("constantLabels"); - meter.doubleGaugeBuilder("metric").setConstantLabels(null).build(); - } - - @Test - public void noopBind_WithNullLabelSet() { - DoubleGauge doubleGauge = - meter - .doubleGaugeBuilder(NAME) - .setDescription(DESCRIPTION) - .setLabelKeys(LABEL_KEY) - .setUnit(UNIT) - .build(); - thrown.expect(NullPointerException.class); - thrown.expectMessage("labelSet"); - doubleGauge.bind(null); - } - - @Test - public void noopUnbind_WithNullInstrument() { - DoubleGauge doubleGauge = - meter - .doubleGaugeBuilder(NAME) - .setDescription(DESCRIPTION) - .setLabelKeys(LABEL_KEY) - .setUnit(UNIT) - .build(); - thrown.expect(NullPointerException.class); - thrown.expectMessage("boundDoubleGauge"); - doubleGauge.unbind(null); - } - - @Test - public void doesNotThrow() { - DoubleGauge doubleGauge = - meter - .doubleGaugeBuilder(NAME) - .setDescription(DESCRIPTION) - .setLabelKeys(LABEL_KEY) - .setUnit(UNIT) - .build(); - doubleGauge.bind(meter.createLabelSet()).set(5.0); - } -} diff --git a/api/src/test/java/io/opentelemetry/metrics/LongGaugeTest.java b/api/src/test/java/io/opentelemetry/metrics/LongGaugeTest.java deleted file mode 100644 index fc446e3806d..00000000000 --- a/api/src/test/java/io/opentelemetry/metrics/LongGaugeTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.metrics; - -import io.opentelemetry.OpenTelemetry; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link LongGauge}. */ -@RunWith(JUnit4.class) -public class LongGaugeTest { - @Rule public ExpectedException thrown = ExpectedException.none(); - - private static final String NAME = "name"; - private static final String DESCRIPTION = "description"; - private static final String UNIT = "1"; - private static final List LABEL_KEY = Collections.singletonList("key"); - - private final Meter meter = OpenTelemetry.getMeterRegistry().get("gauge_long_test"); - - @Test - public void preventNonPrintableName() { - thrown.expect(IllegalArgumentException.class); - meter.longGaugeBuilder("\2").build(); - } - - @Test - public void preventTooLongName() { - char[] chars = new char[DefaultMeter.NAME_MAX_LENGTH + 1]; - Arrays.fill(chars, 'a'); - String longName = String.valueOf(chars); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(DefaultMeter.ERROR_MESSAGE_INVALID_NAME); - meter.longGaugeBuilder(longName).build(); - } - - @Test - public void preventNull_Description() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("description"); - meter.longGaugeBuilder("metric").setDescription(null).build(); - } - - @Test - public void preventNull_Unit() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("unit"); - meter.longGaugeBuilder("metric").setUnit(null).build(); - } - - @Test - public void preventNull_LabelKeys() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("labelKeys"); - meter.longGaugeBuilder("metric").setLabelKeys(null).build(); - } - - @Test - public void preventNull_LabelKey() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("labelKey"); - meter.longGaugeBuilder("metric").setLabelKeys(Collections.singletonList(null)).build(); - } - - @Test - public void preventNull_ConstantLabels() { - thrown.expect(NullPointerException.class); - thrown.expectMessage("constantLabels"); - meter.longGaugeBuilder("metric").setConstantLabels(null).build(); - } - - @Test - public void noopBind_WithNullLabelSet() { - LongGauge longGauge = - meter - .longGaugeBuilder(NAME) - .setDescription(DESCRIPTION) - .setLabelKeys(LABEL_KEY) - .setUnit(UNIT) - .build(); - thrown.expect(NullPointerException.class); - thrown.expectMessage("labelSet"); - longGauge.bind(null); - } - - @Test - public void noopUnbind_WithNullBound() { - LongGauge longGauge = - meter - .longGaugeBuilder(NAME) - .setDescription(DESCRIPTION) - .setLabelKeys(LABEL_KEY) - .setUnit(UNIT) - .build(); - thrown.expect(NullPointerException.class); - thrown.expectMessage("boundLongGauge"); - longGauge.unbind(null); - } - - @Test - public void doesNotThrow() { - LongGauge longGauge = - meter - .longGaugeBuilder(NAME) - .setDescription(DESCRIPTION) - .setLabelKeys(LABEL_KEY) - .setUnit(UNIT) - .build(); - longGauge.bind(meter.createLabelSet()).set(5); - } -} diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractGaugeBuilder.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractGaugeBuilder.java deleted file mode 100644 index 8fc9f7af87a..00000000000 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractGaugeBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.sdk.metrics; - -import io.opentelemetry.metrics.Gauge; - -abstract class AbstractGaugeBuilder, V> - extends AbstractInstrumentBuilder implements Gauge.Builder { - private boolean monotonic = false; - - protected AbstractGaugeBuilder(String name) { - super(name); - } - - @Override - public final B setMonotonic(boolean monotonic) { - this.monotonic = monotonic; - return getThis(); - } - - final boolean isMonotonic() { - return this.monotonic; - } -} diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java index ba93e4d68f3..1b29bbb7fa2 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java @@ -18,12 +18,10 @@ import io.opentelemetry.metrics.BatchRecorder; import io.opentelemetry.metrics.DoubleCounter; -import io.opentelemetry.metrics.DoubleGauge; import io.opentelemetry.metrics.DoubleMeasure; import io.opentelemetry.metrics.DoubleObserver; import io.opentelemetry.metrics.LabelSet; import io.opentelemetry.metrics.LongCounter; -import io.opentelemetry.metrics.LongGauge; import io.opentelemetry.metrics.LongMeasure; import io.opentelemetry.metrics.LongObserver; import io.opentelemetry.metrics.Meter; @@ -48,16 +46,6 @@ MeterSharedState getSharedState() { return sharedState; } - @Override - public LongGauge.Builder longGaugeBuilder(String name) { - throw new UnsupportedOperationException("to be implemented"); - } - - @Override - public DoubleGauge.Builder doubleGaugeBuilder(String name) { - throw new UnsupportedOperationException("to be implemented"); - } - @Override public DoubleCounter.Builder doubleCounterBuilder(String name) { return DoubleCounterSdk.builder(name); diff --git a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractGaugeBuilderTest.java b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractGaugeBuilderTest.java deleted file mode 100644 index 64e95493707..00000000000 --- a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractGaugeBuilderTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opentelemetry.sdk.metrics; - -import static com.google.common.truth.Truth.assertThat; - -import io.opentelemetry.metrics.Gauge; -import io.opentelemetry.metrics.LabelSet; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link AbstractGaugeBuilder}. */ -@RunWith(JUnit4.class) -public class AbstractGaugeBuilderTest { - @Rule public ExpectedException thrown = ExpectedException.none(); - - private static final String NAME = "name"; - - @Test - public void defaultValue() { - TestInstrumentBuilder testMetricBuilder = TestInstrumentBuilder.newBuilder(NAME); - assertThat(testMetricBuilder.getName()).isEqualTo(NAME); - assertThat(testMetricBuilder.getDescription()).isEmpty(); - assertThat(testMetricBuilder.getUnit()).isEqualTo("1"); - assertThat(testMetricBuilder.getLabelKeys()).isEmpty(); - assertThat(testMetricBuilder.getConstantLabels()).isEmpty(); - assertThat(testMetricBuilder.isMonotonic()).isFalse(); - assertThat(testMetricBuilder.build()).isInstanceOf(TestInstrument.class); - } - - @Test - public void setAndGetValues() { - TestInstrumentBuilder testMetricBuilder = - TestInstrumentBuilder.newBuilder(NAME).setMonotonic(true); - assertThat(testMetricBuilder.getName()).isEqualTo(NAME); - assertThat(testMetricBuilder.isMonotonic()).isTrue(); - assertThat(testMetricBuilder.build()).isInstanceOf(TestInstrument.class); - } - - private static final class TestInstrumentBuilder - extends AbstractGaugeBuilder { - static TestInstrumentBuilder newBuilder(String name) { - return new TestInstrumentBuilder(name); - } - - TestInstrumentBuilder(String name) { - super(name); - } - - @Override - TestInstrumentBuilder getThis() { - return this; - } - - @Override - public TestInstrument build() { - return new TestInstrument(); - } - } - - private static final class TestInstrument implements Gauge { - private static final TestBound HANDLE = new TestBound(); - - @Override - public TestBound bind(LabelSet labelSet) { - return HANDLE; - } - - @Override - public void unbind(TestBound boundInstrument) {} - } - - private static final class TestBound {} -}