Skip to content

Commit

Permalink
Remove unnecessary LabelValue object. (#433)
Browse files Browse the repository at this point in the history
* Remove unnecessary LabelValue object.

* Remove the LabelValue class and all usages.
  • Loading branch information
bogdandrutu authored Aug 13, 2019
1 parent 5acf1e8 commit 9ede324
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 245 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/internal/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public static <T> void checkListElementNotNull(
* @param errorMessage the message to use for the exception. Will be converted to a string using
* {@link String#valueOf(Object)}.
*/
public static <K, V> void checkMapElementNotNull(
public static <K, V> void checkMapKeysNotNull(
Map<K, V> map, @javax.annotation.Nullable Object errorMessage) {
for (Map.Entry<K, V> entry : map.entrySet()) {
if (entry.getKey() == null || entry.getValue() == null) {
if (entry.getKey() == null) {
throw new NullPointerException(String.valueOf(errorMessage));
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/metrics/CounterDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* .build();
* // It is recommended to keep a reference of a TimeSeries.
* private static final CounterDouble.TimeSeries inboundTimeSeries =
* counter.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
* counter.getOrCreateTimeSeries(Collections.singletonList("SomeWork"));
* private static final CounterDouble.TimeSeries defaultTimeSeries =
* counter.getDefaultTimeSeries();
*
Expand All @@ -61,7 +61,7 @@
public interface CounterDouble extends Metric<CounterDouble.TimeSeries> {

@Override
TimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues);
TimeSeries getOrCreateTimeSeries(List<String> labelValues);

@Override
TimeSeries getDefaultTimeSeries();
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/metrics/CounterLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* .build();
* // It is recommended to keep a reference of a TimeSeries.
* private static final CounterLong.TimeSeries inboundTimeSeries =
* counter.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
* counter.getOrCreateTimeSeries(Collections.singletonList("SomeWork"));
* private static final CounterLong.TimeSeries defaultTimeSeries = counter.getDefaultTimeSeries();
*
* void doDefaultWork() {
Expand All @@ -61,7 +61,7 @@
public interface CounterLong extends Metric<TimeSeries> {

@Override
TimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues);
TimeSeries getOrCreateTimeSeries(List<String> labelValues);

@Override
TimeSeries getDefaultTimeSeries();
Expand Down
40 changes: 20 additions & 20 deletions api/src/main/java/io/opentelemetry/metrics/DefaultMeter.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ private NoopGaugeLong(int labelKeysSize) {
}

@Override
public NoopTimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues) {
Utils.checkListElementNotNull(Utils.checkNotNull(labelValues, "labelValues"), "labelValue");
public NoopTimeSeries getOrCreateTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
Utils.checkArgument(
labelKeysSize == labelValues.size(), "Label Keys and Label Values don't have same size.");
return new NoopTimeSeries();
Expand All @@ -129,7 +129,7 @@ public void setCallback(Runnable metricUpdater) {
}

@Override
public void removeTimeSeries(List<LabelValue> labelValues) {
public void removeTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
}

Expand Down Expand Up @@ -170,8 +170,8 @@ public Builder setLabelKeys(List<LabelKey> labelKeys) {
}

@Override
public Builder setConstantLabels(Map<LabelKey, LabelValue> constantLabels) {
Utils.checkMapElementNotNull(
public Builder setConstantLabels(Map<LabelKey, String> constantLabels) {
Utils.checkMapKeysNotNull(
Utils.checkNotNull(constantLabels, "constantLabels"), "constantLabel");
return this;
}
Expand Down Expand Up @@ -205,8 +205,8 @@ private NoopGaugeDouble(int labelKeysSize) {
}

@Override
public NoopTimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues) {
Utils.checkListElementNotNull(Utils.checkNotNull(labelValues, "labelValues"), "labelValue");
public NoopTimeSeries getOrCreateTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
Utils.checkArgument(
labelKeysSize == labelValues.size(), "Label Keys and Label Values don't have same size.");
return new NoopTimeSeries();
Expand All @@ -223,7 +223,7 @@ public void setCallback(Runnable metricUpdater) {
}

@Override
public void removeTimeSeries(List<LabelValue> labelValues) {
public void removeTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
}

Expand Down Expand Up @@ -264,8 +264,8 @@ public Builder setLabelKeys(List<LabelKey> labelKeys) {
}

@Override
public Builder setConstantLabels(Map<LabelKey, LabelValue> constantLabels) {
Utils.checkMapElementNotNull(
public Builder setConstantLabels(Map<LabelKey, String> constantLabels) {
Utils.checkMapKeysNotNull(
Utils.checkNotNull(constantLabels, "constantLabels"), "constantLabel");
return this;
}
Expand Down Expand Up @@ -299,8 +299,8 @@ private NoopCounterDouble(int labelKeysSize) {
}

@Override
public NoopTimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues) {
Utils.checkListElementNotNull(Utils.checkNotNull(labelValues, "labelValues"), "labelValue");
public NoopTimeSeries getOrCreateTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
Utils.checkArgument(
labelKeysSize == labelValues.size(), "Label Keys and Label Values don't have same size.");
return NoopTimeSeries.INSTANCE;
Expand All @@ -317,7 +317,7 @@ public void setCallback(Runnable metricUpdater) {
}

@Override
public void removeTimeSeries(List<LabelValue> labelValues) {
public void removeTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
}

Expand Down Expand Up @@ -360,8 +360,8 @@ public Builder setLabelKeys(List<LabelKey> labelKeys) {
}

@Override
public Builder setConstantLabels(Map<LabelKey, LabelValue> constantLabels) {
Utils.checkMapElementNotNull(
public Builder setConstantLabels(Map<LabelKey, String> constantLabels) {
Utils.checkMapKeysNotNull(
Utils.checkNotNull(constantLabels, "constantLabels"), "constantLabel");
return this;
}
Expand Down Expand Up @@ -395,8 +395,8 @@ private NoopCounterLong(int labelKeysSize) {
}

@Override
public NoopTimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues) {
Utils.checkListElementNotNull(Utils.checkNotNull(labelValues, "labelValues"), "labelValue");
public NoopTimeSeries getOrCreateTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
Utils.checkArgument(
labelKeysSize == labelValues.size(), "Label Keys and Label Values don't have same size.");
return NoopTimeSeries.INSTANCE;
Expand All @@ -413,7 +413,7 @@ public void setCallback(Runnable metricUpdater) {
}

@Override
public void removeTimeSeries(List<LabelValue> labelValues) {
public void removeTimeSeries(List<String> labelValues) {
Utils.checkNotNull(labelValues, "labelValues");
}

Expand Down Expand Up @@ -456,8 +456,8 @@ public Builder setLabelKeys(List<LabelKey> labelKeys) {
}

@Override
public Builder setConstantLabels(Map<LabelKey, LabelValue> constantLabels) {
Utils.checkMapElementNotNull(
public Builder setConstantLabels(Map<LabelKey, String> constantLabels) {
Utils.checkMapKeysNotNull(
Utils.checkNotNull(constantLabels, "constantLabels"), "constantLabel");
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/metrics/GaugeDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* .build();
* // It is recommended to keep a reference of a TimeSeries.
* private static final GaugeDouble.TimeSeries inboundTimeSeries =
* gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
* gauge.getOrCreateTimeSeries(Collections.singletonList("SomeWork"));
* private static final GaugeDouble.TimeSeries defaultTimeSeries = gauge.getDefaultTimeSeries();
*
* void doDefault() {
Expand All @@ -61,7 +61,7 @@
public interface GaugeDouble extends Metric<TimeSeries> {

@Override
TimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues);
TimeSeries getOrCreateTimeSeries(List<String> labelValues);

@Override
TimeSeries getDefaultTimeSeries();
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/metrics/GaugeLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* .build();
* // It is recommended to keep a reference of a TimeSeries.
* private static final GaugeLong.TimeSeries inboundTimeSeries =
* gauge.getOrCreateTimeSeries(Collections.singletonList(LabelValue.create("SomeWork")));
* gauge.getOrCreateTimeSeries(Collections.singletonList("SomeWork"));
* private static final GaugeLong.TimeSeries defaultTimeSeries = gauge.getDefaultTimeSeries();
*
* void doDefault() {
Expand All @@ -60,7 +60,7 @@
public interface GaugeLong extends Metric<GaugeLong.TimeSeries> {

@Override
TimeSeries getOrCreateTimeSeries(List<LabelValue> labelValues);
TimeSeries getOrCreateTimeSeries(List<String> labelValues);

@Override
TimeSeries getDefaultTimeSeries();
Expand Down
55 changes: 0 additions & 55 deletions api/src/main/java/io/opentelemetry/metrics/LabelValue.java

This file was deleted.

9 changes: 5 additions & 4 deletions api/src/main/java/io/opentelemetry/metrics/Metric.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface Metric<T> {
* keys.
* @since 0.1.0
*/
T getOrCreateTimeSeries(List<LabelValue> labelValues);
T getOrCreateTimeSeries(List<String> labelValues);

/**
* Returns a {@code TimeSeries} for a metric with all labels not set (default label value).
Expand All @@ -64,11 +64,12 @@ public interface Metric<T> {
* Removes the {@code TimeSeries} from the metric, if it is present. i.e. references to previous
* {@code TimeSeries} are invalid (not part of the metric).
*
* <p>If value is missing for one of the predefined keys {@code null} must be used for that value.
*
* @param labelValues the list of label values.
* @throws NullPointerException if {@code labelValues} is null.
* @since 0.1.0
*/
void removeTimeSeries(List<LabelValue> labelValues);
void removeTimeSeries(List<String> labelValues);

/**
* Removes all {@code TimeSeries} from the metric. i.e. references to all previous {@code
Expand Down Expand Up @@ -117,7 +118,7 @@ interface Builder<B extends Builder<B, V>, V> {
* @param constantLabels the map of constant labels for the Metric.
* @return this.
*/
B setConstantLabels(Map<LabelKey, LabelValue> constantLabels);
B setConstantLabels(Map<LabelKey, String> constantLabels);

/**
* Sets the name of the component that reports this {@code Metric}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.opentelemetry.metrics;

import io.opentelemetry.OpenTelemetry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Rule;
Expand All @@ -36,7 +35,7 @@ public class CounterDoubleTest {
private static final String UNIT = "1";
private static final List<LabelKey> LABEL_KEY =
Collections.singletonList(LabelKey.create("key", "key description"));
private static final List<LabelValue> EMPTY_LABEL_VALUES = new ArrayList<>();
private static final List<String> EMPTY_LABEL_VALUES = Collections.emptyList();

private final Meter meter = OpenTelemetry.getMeter();

Expand All @@ -54,21 +53,6 @@ public void noopGetOrCreateTimeSeries_WithNullLabelValues() {
counterDouble.getOrCreateTimeSeries(null);
}

@Test
public void noopGetOrCreateTimeSeries_WithNullElement() {
List<LabelValue> labelValues = Collections.singletonList(null);
CounterDouble counterDouble =
meter
.counterDoubleBuilder(NAME)
.setDescription(DESCRIPTION)
.setLabelKeys(LABEL_KEY)
.setUnit(UNIT)
.build();
thrown.expect(NullPointerException.class);
thrown.expectMessage("labelValue");
counterDouble.getOrCreateTimeSeries(labelValues);
}

@Test
public void noopGetOrCreateTimeSeries_WithInvalidLabelSize() {
CounterDouble counterDouble =
Expand Down
18 changes: 1 addition & 17 deletions api/src/test/java/io/opentelemetry/metrics/CounterLongTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.opentelemetry.metrics;

import io.opentelemetry.OpenTelemetry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Rule;
Expand All @@ -36,7 +35,7 @@ public class CounterLongTest {
private static final String UNIT = "1";
private static final List<LabelKey> LABEL_KEY =
Collections.singletonList(LabelKey.create("key", "key description"));
private static final List<LabelValue> EMPTY_LABEL_VALUES = new ArrayList<>();
private static final List<String> EMPTY_LABEL_VALUES = Collections.emptyList();

private final Meter meter = OpenTelemetry.getMeter();

Expand All @@ -54,21 +53,6 @@ public void noopGetOrCreateTimeSeries_WithNullLabelValues() {
counterLong.getOrCreateTimeSeries(null);
}

@Test
public void noopGetOrCreateTimeSeries_WithNullElement() {
List<LabelValue> labelValues = Collections.singletonList(null);
CounterLong counterLong =
meter
.counterLongBuilder(NAME)
.setDescription(DESCRIPTION)
.setLabelKeys(LABEL_KEY)
.setUnit(UNIT)
.build();
thrown.expect(NullPointerException.class);
thrown.expectMessage("labelValue");
counterLong.getOrCreateTimeSeries(labelValues);
}

@Test
public void noopGetOrCreateTimeSeries_WithInvalidLabelSize() {
CounterLong counterLong =
Expand Down
Loading

0 comments on commit 9ede324

Please sign in to comment.