Skip to content

Commit

Permalink
Convert the usages of the LabelSetSdk to use the Labels class. (#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwatson authored Jun 17, 2020
1 parent f1f5975 commit fccc6d9
Show file tree
Hide file tree
Showing 86 changed files with 499 additions and 825 deletions.
4 changes: 4 additions & 0 deletions api/src/main/java/io/opentelemetry/common/Labels.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public static Labels of(
key5, value5);
}

public static Labels of(String[] keyValueLabelPairs) {
return sortAndFilterToLabels((Object[]) keyValueLabelPairs);
}

private static Labels sortAndFilterToLabels(Object... data) {
return new AutoValue_Labels_ArrayBackedLabels(sortAndFilter(data));
}
Expand Down
7 changes: 3 additions & 4 deletions api/src/main/java/io/opentelemetry/metrics/DefaultMeter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.internal.Utils;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.ThreadSafe;

Expand Down Expand Up @@ -621,9 +621,8 @@ public B setUnit(String unit) {
}

@Override
public B setConstantLabels(Map<String, String> constantLabels) {
Utils.checkMapKeysNotNull(
Utils.checkNotNull(constantLabels, "constantLabels"), "constantLabel");
public B setConstantLabels(Labels constantLabels) {
Utils.checkNotNull(constantLabels, "constantLabels");
return getThis();
}

Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/metrics/DoubleCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.DoubleCounter.BoundDoubleCounter;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -97,7 +97,7 @@ interface Builder extends SynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
DoubleCounter build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ interface Builder extends AsynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
DoubleSumObserver build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.DoubleUpDownCounter.BoundDoubleUpDownCounter;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -100,7 +100,7 @@ interface Builder extends SynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
DoubleUpDownCounter build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ interface Builder extends AsynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
DoubleUpDownSumObserver build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ interface Builder extends AsynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
DoubleValueObserver build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.DoubleValueRecorder.BoundDoubleValueRecorder;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ interface Builder extends SynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
DoubleValueRecorder build();
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/metrics/Instrument.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import java.util.Collections;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ interface Builder {
* @param constantLabels the map of constant labels for the Instrument.
* @return this.
*/
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

/**
* Builds and returns a {@code Instrument} with the desired options.
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/opentelemetry/metrics/LongCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.LongCounter.BoundLongCounter;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ interface Builder extends SynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
LongCounter build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ interface Builder extends AsynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
LongSumObserver build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.LongUpDownCounter.BoundLongUpDownCounter;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ interface Builder extends SynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
LongUpDownCounter build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ interface Builder extends AsynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
LongUpDownSumObserver build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ interface Builder extends AsynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
LongValueObserver build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.opentelemetry.metrics;

import io.opentelemetry.common.Labels;
import io.opentelemetry.metrics.LongValueRecorder.BoundLongValueRecorder;
import java.util.Map;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ interface Builder extends SynchronousInstrument.Builder {
Builder setUnit(String unit);

@Override
Builder setConstantLabels(Map<String, String> constantLabels);
Builder setConstantLabels(Labels constantLabels);

@Override
LongValueRecorder build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package io.opentelemetry.metrics;

import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.common.Labels;
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.metrics.DoubleCounter.BoundDoubleCounter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -36,8 +35,7 @@ public class DoubleCounterTest {
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String UNIT = "1";
private static final Map<String, String> CONSTANT_LABELS =
Collections.singletonMap("key", "value");
private static final Labels CONSTANT_LABELS = Labels.of("key", "value");

private final Meter meter = OpenTelemetry.getMeter("DoubleCounterTest");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package io.opentelemetry.metrics;

import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.common.Labels;
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -37,8 +36,7 @@ public class DoubleSumObserverTest {
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String UNIT = "1";
private static final Map<String, String> CONSTANT_LABELS =
Collections.singletonMap("key", "value");
private static final Labels CONSTANT_LABELS = Labels.of("key", "value");

private final Meter meter = OpenTelemetry.getMeter("DoubleSumObserverTest");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package io.opentelemetry.metrics;

import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.common.Labels;
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.metrics.DoubleUpDownCounter.BoundDoubleUpDownCounter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -36,8 +35,7 @@ public class DoubleUpDownCounterTest {
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String UNIT = "1";
private static final Map<String, String> CONSTANT_LABELS =
Collections.singletonMap("key", "value");
private static final Labels CONSTANT_LABELS = Labels.of("key", "value");

private final Meter meter = OpenTelemetry.getMeter("DoubleUpDownCounterTest");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package io.opentelemetry.metrics;

import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.common.Labels;
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -37,8 +36,7 @@ public class DoubleUpDownSumObserverTest {
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String UNIT = "1";
private static final Map<String, String> CONSTANT_LABELS =
Collections.singletonMap("key", "value");
private static final Labels CONSTANT_LABELS = Labels.of("key", "value");

private final Meter meter = OpenTelemetry.getMeter("DoubleUpDownSumObserverTest");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package io.opentelemetry.metrics;

import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.common.Labels;
import io.opentelemetry.internal.StringUtils;
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -37,8 +36,7 @@ public class DoubleValueObserverTest {
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
private static final String UNIT = "1";
private static final Map<String, String> CONSTANT_LABELS =
Collections.singletonMap("key", "value");
private static final Labels CONSTANT_LABELS = Labels.of("key", "value");

private final Meter meter = OpenTelemetry.getMeter("DoubleSumObserverTest");

Expand Down
Loading

0 comments on commit fccc6d9

Please sign in to comment.