Convert the usages of the LabelSetSdk to use the Labels class. (#1338)
This commit is contained in:
parent
f1f5975d5c
commit
fccc6d9bc3
|
|
@ -102,6 +102,10 @@ public abstract class Labels extends ImmutableKeyValuePairs<String> {
|
|||
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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -621,9 +621,8 @@ public final class DefaultMeter implements Meter {
|
|||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -97,7 +97,7 @@ public interface DoubleCounter extends SynchronousInstrument<BoundDoubleCounter>
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
DoubleCounter build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +74,7 @@ public interface DoubleSumObserver extends AsynchronousInstrument<DoubleResult>
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
DoubleSumObserver build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -100,7 +100,7 @@ public interface DoubleUpDownCounter extends SynchronousInstrument<BoundDoubleUp
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
DoubleUpDownCounter build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +74,7 @@ public interface DoubleUpDownSumObserver extends AsynchronousInstrument<DoubleRe
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
DoubleUpDownSumObserver build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -70,7 +70,7 @@ public interface DoubleValueObserver extends AsynchronousInstrument<DoubleResult
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
DoubleValueObserver build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -108,7 +108,7 @@ public interface DoubleValueRecorder extends SynchronousInstrument<BoundDoubleVa
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
DoubleValueRecorder build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -59,7 +59,7 @@ public interface Instrument {
|
|||
* @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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -98,7 +98,7 @@ public interface LongCounter extends SynchronousInstrument<BoundLongCounter> {
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
LongCounter build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +74,7 @@ public interface LongSumObserver extends AsynchronousInstrument<LongResult> {
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
LongSumObserver build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -101,7 +101,7 @@ public interface LongUpDownCounter extends SynchronousInstrument<BoundLongUpDown
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
LongUpDownCounter build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +74,7 @@ public interface LongUpDownSumObserver extends AsynchronousInstrument<LongResult
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
LongUpDownSumObserver build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -70,7 +70,7 @@ public interface LongValueObserver extends AsynchronousInstrument<LongResult> {
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
LongValueObserver build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
@ -108,7 +108,7 @@ public interface LongValueRecorder extends SynchronousInstrument<BoundLongValueR
|
|||
Builder setUnit(String unit);
|
||||
|
||||
@Override
|
||||
Builder setConstantLabels(Map<String, String> constantLabels);
|
||||
Builder setConstantLabels(Labels constantLabels);
|
||||
|
||||
@Override
|
||||
LongValueRecorder build();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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");
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@
|
|||
package io.opentelemetry.metrics;
|
||||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.DoubleValueRecorder.BoundDoubleValueRecorder;
|
||||
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;
|
||||
|
|
@ -35,8 +34,7 @@ public final class DoubleValueRecorderTest {
|
|||
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("DoubleValueRecorderTest");
|
||||
|
||||
|
|
|
|||
|
|
@ -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.LongCounter.BoundLongCounter;
|
||||
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;
|
||||
|
|
@ -36,8 +35,7 @@ public class LongCounterTest {
|
|||
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("LongCounterTest");
|
||||
|
||||
|
|
|
|||
|
|
@ -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.LongResult;
|
||||
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;
|
||||
|
|
@ -37,8 +36,7 @@ public class LongSumObserverTest {
|
|||
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("LongSumObserverTest");
|
||||
|
||||
|
|
|
|||
|
|
@ -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.LongUpDownCounter.BoundLongUpDownCounter;
|
||||
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;
|
||||
|
|
@ -36,8 +35,7 @@ public class LongUpDownCounterTest {
|
|||
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("LongUpDownCounterTest");
|
||||
|
||||
|
|
|
|||
|
|
@ -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.LongResult;
|
||||
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;
|
||||
|
|
@ -37,8 +36,7 @@ public class LongUpDownSumObserverTest {
|
|||
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("LongUpDownSumObserverTest");
|
||||
|
||||
|
|
|
|||
|
|
@ -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.LongResult;
|
||||
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;
|
||||
|
|
@ -37,8 +36,7 @@ public class LongValueObserverTest {
|
|||
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("LongValueObserverTest");
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@
|
|||
package io.opentelemetry.metrics;
|
||||
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.LongValueRecorder.BoundLongValueRecorder;
|
||||
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;
|
||||
|
|
@ -35,8 +34,7 @@ public final class LongValueRecorderTest {
|
|||
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("LongValueRecorderTest");
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
|
|
@ -71,14 +72,14 @@ public class LoggingMetricExporterTest {
|
|||
"A summarized test measure",
|
||||
"ms",
|
||||
Type.SUMMARY,
|
||||
ImmutableMap.of("foo", "bar", "baz", "zoom")),
|
||||
Labels.of("foo", "bar", "baz", "zoom")),
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
nowEpochNanos,
|
||||
nowEpochNanos + 245,
|
||||
ImmutableMap.of("a", "b", "c", "d"),
|
||||
Labels.of("a", "b", "c", "d"),
|
||||
1010,
|
||||
50000,
|
||||
Arrays.asList(
|
||||
|
|
@ -90,29 +91,26 @@ public class LoggingMetricExporterTest {
|
|||
"A simple counter",
|
||||
"one",
|
||||
Type.MONOTONIC_LONG,
|
||||
ImmutableMap.of("alpha", "aleph", "beta", "bet")),
|
||||
Labels.of("alpha", "aleph", "beta", "bet")),
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
nowEpochNanos,
|
||||
nowEpochNanos + 245,
|
||||
ImmutableMap.of("z", "y", "x", "w"),
|
||||
1010))),
|
||||
nowEpochNanos, nowEpochNanos + 245, Labels.of("z", "y", "x", "w"), 1010))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"observedValue",
|
||||
"an observer gauge",
|
||||
"kb",
|
||||
Type.NON_MONOTONIC_DOUBLE,
|
||||
ImmutableMap.of("uno", "eins", "dos", "zwei")),
|
||||
Labels.of("uno", "eins", "dos", "zwei")),
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
nowEpochNanos,
|
||||
nowEpochNanos + 245,
|
||||
ImmutableMap.of("1", "2", "3", "4"),
|
||||
Labels.of("1", "2", "3", "4"),
|
||||
33.7767)))));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package io.opentelemetry.exporters.otlp;
|
||||
|
||||
import io.opentelemetry.common.KeyValueConsumer;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.proto.common.v1.StringKeyValue;
|
||||
import io.opentelemetry.proto.metrics.v1.DoubleDataPoint;
|
||||
import io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics;
|
||||
|
|
@ -233,15 +235,18 @@ final class MetricAdapter {
|
|||
}
|
||||
|
||||
@SuppressWarnings("MixedMutabilityReturnType")
|
||||
static Collection<StringKeyValue> toProtoLabels(Map<String, String> labels) {
|
||||
static Collection<StringKeyValue> toProtoLabels(Labels labels) {
|
||||
if (labels.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<StringKeyValue> result = new ArrayList<>(labels.size());
|
||||
for (Map.Entry<String, String> entry : labels.entrySet()) {
|
||||
result.add(
|
||||
StringKeyValue.newBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build());
|
||||
}
|
||||
final List<StringKeyValue> result = new ArrayList<>(labels.size());
|
||||
labels.forEach(
|
||||
new KeyValueConsumer<String>() {
|
||||
@Override
|
||||
public void consume(String key, String value) {
|
||||
result.add(StringKeyValue.newBuilder().setKey(key).setValue(value).build());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ package io.opentelemetry.exporters.otlp;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue;
|
||||
import io.opentelemetry.proto.common.v1.AttributeKeyValue.ValueType;
|
||||
import io.opentelemetry.proto.common.v1.InstrumentationLibrary;
|
||||
|
|
@ -49,10 +49,10 @@ import org.junit.runners.JUnit4;
|
|||
public class MetricAdapterTest {
|
||||
@Test
|
||||
public void toProtoLabels() {
|
||||
assertThat(MetricAdapter.toProtoLabels(Collections.<String, String>emptyMap())).isEmpty();
|
||||
assertThat(MetricAdapter.toProtoLabels(Collections.singletonMap("k", "v")))
|
||||
assertThat(MetricAdapter.toProtoLabels(Labels.empty())).isEmpty();
|
||||
assertThat(MetricAdapter.toProtoLabels(Labels.of("k", "v")))
|
||||
.containsExactly(StringKeyValue.newBuilder().setKey("k").setValue("v").build());
|
||||
assertThat(MetricAdapter.toProtoLabels(ImmutableMap.of("k1", "v1", "k2", "v2")))
|
||||
assertThat(MetricAdapter.toProtoLabels(Labels.of("k1", "v1", "k2", "v2")))
|
||||
.containsExactly(
|
||||
StringKeyValue.newBuilder().setKey("k1").setValue("v1").build(),
|
||||
StringKeyValue.newBuilder().setKey("k2").setValue("v2").build());
|
||||
|
|
@ -99,7 +99,7 @@ public class MetricAdapterTest {
|
|||
assertThat(
|
||||
MetricAdapter.toInt64DataPoints(
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.LongPoint.create(123, 456, Collections.singletonMap("k", "v"), 5))))
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5))))
|
||||
.containsExactly(
|
||||
Int64DataPoint.newBuilder()
|
||||
.setStartTimeUnixNano(123)
|
||||
|
|
@ -112,9 +112,8 @@ public class MetricAdapterTest {
|
|||
assertThat(
|
||||
MetricAdapter.toInt64DataPoints(
|
||||
ImmutableList.<Point>of(
|
||||
MetricData.LongPoint.create(
|
||||
123, 456, Collections.<String, String>emptyMap(), 5),
|
||||
MetricData.LongPoint.create(321, 654, Collections.singletonMap("k", "v"), 7))))
|
||||
MetricData.LongPoint.create(123, 456, Labels.empty(), 5),
|
||||
MetricData.LongPoint.create(321, 654, Labels.of("k", "v"), 7))))
|
||||
.containsExactly(
|
||||
Int64DataPoint.newBuilder()
|
||||
.setStartTimeUnixNano(123)
|
||||
|
|
@ -138,8 +137,7 @@ public class MetricAdapterTest {
|
|||
assertThat(
|
||||
MetricAdapter.toDoubleDataPoints(
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.DoublePoint.create(
|
||||
123, 456, Collections.singletonMap("k", "v"), 5.1))))
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1))))
|
||||
.containsExactly(
|
||||
DoubleDataPoint.newBuilder()
|
||||
.setStartTimeUnixNano(123)
|
||||
|
|
@ -152,10 +150,8 @@ public class MetricAdapterTest {
|
|||
assertThat(
|
||||
MetricAdapter.toDoubleDataPoints(
|
||||
ImmutableList.<Point>of(
|
||||
MetricData.DoublePoint.create(
|
||||
123, 456, Collections.<String, String>emptyMap(), 5.1),
|
||||
MetricData.DoublePoint.create(
|
||||
321, 654, Collections.singletonMap("k", "v"), 7.1))))
|
||||
MetricData.DoublePoint.create(123, 456, Labels.empty(), 5.1),
|
||||
MetricData.DoublePoint.create(321, 654, Labels.of("k", "v"), 7.1))))
|
||||
.containsExactly(
|
||||
DoubleDataPoint.newBuilder()
|
||||
.setStartTimeUnixNano(123)
|
||||
|
|
@ -182,7 +178,7 @@ public class MetricAdapterTest {
|
|||
MetricData.SummaryPoint.create(
|
||||
123,
|
||||
456,
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
5,
|
||||
14.2,
|
||||
Collections.singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1))))))
|
||||
|
|
@ -205,14 +201,14 @@ public class MetricAdapterTest {
|
|||
MetricData.SummaryPoint.create(
|
||||
123,
|
||||
456,
|
||||
Collections.<String, String>emptyMap(),
|
||||
Labels.empty(),
|
||||
7,
|
||||
15.3,
|
||||
Collections.<MetricData.ValueAtPercentile>emptyList()),
|
||||
MetricData.SummaryPoint.create(
|
||||
321,
|
||||
654,
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
9,
|
||||
18.3,
|
||||
ImmutableList.of(
|
||||
|
|
@ -249,7 +245,7 @@ public class MetricAdapterTest {
|
|||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("k", "v"))))
|
||||
Labels.of("k", "v"))))
|
||||
.isEqualTo(
|
||||
MetricDescriptor.newBuilder()
|
||||
.setName("name")
|
||||
|
|
@ -263,11 +259,7 @@ public class MetricAdapterTest {
|
|||
assertThat(
|
||||
MetricAdapter.toProtoMetricDescriptor(
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap())))
|
||||
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.empty())))
|
||||
.isEqualTo(
|
||||
MetricDescriptor.newBuilder()
|
||||
.setName("name")
|
||||
|
|
@ -287,12 +279,11 @@ public class MetricAdapterTest {
|
|||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_LONG,
|
||||
Collections.singletonMap("k", "v")),
|
||||
Labels.of("k", "v")),
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.LongPoint.create(
|
||||
123, 456, Collections.singletonMap("k", "v"), 5)))))
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)))))
|
||||
.isEqualTo(
|
||||
Metric.newBuilder()
|
||||
.setMetricDescriptor(
|
||||
|
|
@ -324,12 +315,11 @@ public class MetricAdapterTest {
|
|||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("k", "v")),
|
||||
Labels.of("k", "v")),
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.DoublePoint.create(
|
||||
123, 456, Collections.singletonMap("k", "v"), 5.1)))))
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1)))))
|
||||
.isEqualTo(
|
||||
Metric.newBuilder()
|
||||
.setMetricDescriptor(
|
||||
|
|
@ -359,11 +349,7 @@ public class MetricAdapterTest {
|
|||
public void toProtoResourceMetrics() {
|
||||
Descriptor descriptor =
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("k", "v"));
|
||||
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.of("k", "v"));
|
||||
Resource resource =
|
||||
Resource.create(Collections.singletonMap("ka", AttributeValue.stringAttributeValue("va")));
|
||||
io.opentelemetry.proto.resource.v1.Resource resourceProto =
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import io.grpc.Status.Code;
|
|||
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||
import io.grpc.inprocess.InProcessServerBuilder;
|
||||
import io.grpc.testing.GrpcCleanupRule;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
|
||||
import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse;
|
||||
import io.opentelemetry.proto.collector.metrics.v1.MetricsServiceGrpc;
|
||||
|
|
@ -233,16 +234,10 @@ public class OtlpGrpcMetricExporterTest {
|
|||
long startNs = TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
|
||||
long endNs = startNs + TimeUnit.MILLISECONDS.toNanos(900);
|
||||
return MetricData.create(
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("name", "description", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(startNs, endNs, Collections.singletonMap("k", "v"), 5)));
|
||||
Collections.<Point>singletonList(LongPoint.create(startNs, endNs, Labels.of("k", "v"), 5)));
|
||||
}
|
||||
|
||||
private static final class FakeCollector extends MetricsServiceGrpc.MetricsServiceImplBase {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.opentelemetry.exporters.prometheus;
|
|||
|
||||
import static io.prometheus.client.Collector.doubleToGoString;
|
||||
|
||||
import io.opentelemetry.common.KeyValueConsumer;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
|
|
@ -33,7 +34,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Util methods to convert OpenTelemetry Metrics data models to Prometheus data models.
|
||||
|
|
@ -105,10 +105,18 @@ final class MetricAdapter {
|
|||
if (descriptor.getConstantLabels().size() != 0) {
|
||||
constLabelNames = new ArrayList<>(descriptor.getConstantLabels().size());
|
||||
constLabelValues = new ArrayList<>(descriptor.getConstantLabels().size());
|
||||
for (Map.Entry<String, String> entry : descriptor.getConstantLabels().entrySet()) {
|
||||
constLabelNames.add(toLabelName(entry.getKey()));
|
||||
constLabelValues.add(entry.getValue() == null ? "" : entry.getValue());
|
||||
}
|
||||
final List<String> finalConstLabelNames = constLabelNames;
|
||||
final List<String> finalConstLabelValues = constLabelValues;
|
||||
descriptor
|
||||
.getConstantLabels()
|
||||
.forEach(
|
||||
new KeyValueConsumer<String>() {
|
||||
@Override
|
||||
public void consume(String key, String value) {
|
||||
finalConstLabelNames.add(toLabelName(key));
|
||||
finalConstLabelValues.add(value == null ? "" : value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (Point point : points) {
|
||||
|
|
@ -122,12 +130,19 @@ final class MetricAdapter {
|
|||
new ArrayList<>(descriptor.getConstantLabels().size() + point.getLabels().size());
|
||||
labelValues.addAll(constLabelValues);
|
||||
|
||||
for (Map.Entry<String, String> entry : point.getLabels().entrySet()) {
|
||||
// TODO: Use a cache(map) of converted label names to avoid sanitization multiple times
|
||||
// for the same label key.
|
||||
labelNames.add(toLabelName(entry.getKey()));
|
||||
labelValues.add(entry.getValue() == null ? "" : entry.getValue());
|
||||
}
|
||||
// TODO: Use a cache(map) of converted label names to avoid sanitization multiple times
|
||||
final List<String> finalLabelNames = labelNames;
|
||||
final List<String> finalLabelValues = labelValues;
|
||||
point
|
||||
.getLabels()
|
||||
.forEach(
|
||||
new KeyValueConsumer<String>() {
|
||||
@Override
|
||||
public void consume(String key, String value) {
|
||||
finalLabelNames.add(toLabelName(key));
|
||||
finalLabelValues.add(value == null ? "" : value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
switch (descriptor.getType()) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
|
|
@ -56,11 +57,7 @@ public class MetricAdapterTest {
|
|||
MetricAdapter.toSamples(
|
||||
"full_name",
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"name", "description", "1", Descriptor.Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Collections.<MetricData.Point>emptyList()))
|
||||
.isEmpty();
|
||||
|
||||
|
|
@ -68,14 +65,9 @@ public class MetricAdapterTest {
|
|||
MetricAdapter.toSamples(
|
||||
"full_name",
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.NON_MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"name", "description", "1", Descriptor.Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.LongPoint.create(
|
||||
123, 456, Collections.singletonMap("kp", "vp"), 5))))
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("kp", "vp"), 5))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kp"), ImmutableList.of("vp"), 5));
|
||||
|
||||
|
|
@ -87,10 +79,9 @@ public class MetricAdapterTest {
|
|||
"description",
|
||||
"1",
|
||||
Descriptor.Type.NON_MONOTONIC_LONG,
|
||||
Collections.singletonMap("kc", "vc")),
|
||||
Labels.of("kc", "vc")),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.LongPoint.create(
|
||||
123, 456, Collections.singletonMap("kp", "vp"), 5))))
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("kp", "vp"), 5))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kc", "kp"), ImmutableList.of("vc", "vp"), 5));
|
||||
|
||||
|
|
@ -102,12 +93,10 @@ public class MetricAdapterTest {
|
|||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_LONG,
|
||||
Collections.singletonMap("kc", "vc")),
|
||||
Labels.of("kc", "vc")),
|
||||
ImmutableList.<Point>of(
|
||||
MetricData.LongPoint.create(
|
||||
123, 456, Collections.<String, String>emptyMap(), 5),
|
||||
MetricData.LongPoint.create(
|
||||
321, 654, Collections.singletonMap("kp", "vp"), 7))))
|
||||
MetricData.LongPoint.create(123, 456, Labels.empty(), 5),
|
||||
MetricData.LongPoint.create(321, 654, Labels.of("kp", "vp"), 7))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kc"), ImmutableList.of("vc"), 5),
|
||||
new Sample("full_name", ImmutableList.of("kc", "kp"), ImmutableList.of("vc", "vp"), 7));
|
||||
|
|
@ -123,7 +112,7 @@ public class MetricAdapterTest {
|
|||
"description",
|
||||
"1",
|
||||
Descriptor.Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Labels.empty()),
|
||||
Collections.<MetricData.Point>emptyList()))
|
||||
.isEmpty();
|
||||
|
||||
|
|
@ -131,14 +120,9 @@ public class MetricAdapterTest {
|
|||
MetricAdapter.toSamples(
|
||||
"full_name",
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.DoublePoint.create(
|
||||
123, 456, Collections.singletonMap("kp", "vp"), 5))))
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("kp", "vp"), 5))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kp"), ImmutableList.of("vp"), 5));
|
||||
|
||||
|
|
@ -150,12 +134,10 @@ public class MetricAdapterTest {
|
|||
"description",
|
||||
"1",
|
||||
Descriptor.Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("kc", "vc")),
|
||||
Labels.of("kc", "vc")),
|
||||
ImmutableList.<Point>of(
|
||||
MetricData.DoublePoint.create(
|
||||
123, 456, Collections.<String, String>emptyMap(), 5),
|
||||
MetricData.DoublePoint.create(
|
||||
321, 654, Collections.singletonMap("kp", "vp"), 7))))
|
||||
MetricData.DoublePoint.create(123, 456, Labels.empty(), 5),
|
||||
MetricData.DoublePoint.create(321, 654, Labels.of("kp", "vp"), 7))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kc"), ImmutableList.of("vc"), 5),
|
||||
new Sample("full_name", ImmutableList.of("kc", "kp"), ImmutableList.of("vc", "vp"), 7));
|
||||
|
|
@ -167,11 +149,7 @@ public class MetricAdapterTest {
|
|||
MetricAdapter.toSamples(
|
||||
"full_name",
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.SUMMARY,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"name", "description", "1", Descriptor.Type.SUMMARY, Labels.empty()),
|
||||
Collections.<MetricData.Point>emptyList()))
|
||||
.isEmpty();
|
||||
|
||||
|
|
@ -179,16 +157,12 @@ public class MetricAdapterTest {
|
|||
MetricAdapter.toSamples(
|
||||
"full_name",
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.SUMMARY,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"name", "description", "1", Descriptor.Type.SUMMARY, Labels.empty()),
|
||||
ImmutableList.<Point>of(
|
||||
MetricData.SummaryPoint.create(
|
||||
321,
|
||||
654,
|
||||
Collections.singletonMap("kp", "vp"),
|
||||
Labels.of("kp", "vp"),
|
||||
9,
|
||||
18.3,
|
||||
ImmutableList.of(MetricData.ValueAtPercentile.create(0.9, 1.1))))))
|
||||
|
|
@ -205,23 +179,19 @@ public class MetricAdapterTest {
|
|||
MetricAdapter.toSamples(
|
||||
"full_name",
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.SUMMARY,
|
||||
Collections.singletonMap("kc", "vc")),
|
||||
"name", "description", "1", Descriptor.Type.SUMMARY, Labels.of("kc", "vc")),
|
||||
ImmutableList.<Point>of(
|
||||
MetricData.SummaryPoint.create(
|
||||
123,
|
||||
456,
|
||||
Collections.<String, String>emptyMap(),
|
||||
Labels.empty(),
|
||||
7,
|
||||
15.3,
|
||||
Collections.<MetricData.ValueAtPercentile>emptyList()),
|
||||
MetricData.SummaryPoint.create(
|
||||
321,
|
||||
654,
|
||||
Collections.singletonMap("kp", "vp"),
|
||||
Labels.of("kp", "vp"),
|
||||
9,
|
||||
18.3,
|
||||
ImmutableList.of(
|
||||
|
|
@ -250,11 +220,7 @@ public class MetricAdapterTest {
|
|||
public void toMetricFamilySamples() {
|
||||
Descriptor descriptor =
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("kc", "vc"));
|
||||
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.of("kc", "vc"));
|
||||
|
||||
MetricData metricData =
|
||||
MetricData.create(
|
||||
|
|
@ -263,7 +229,7 @@ public class MetricAdapterTest {
|
|||
Collections.singletonMap("kr", AttributeValue.stringAttributeValue("vr"))),
|
||||
InstrumentationLibraryInfo.create("full", "version"),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.DoublePoint.create(123, 456, Collections.singletonMap("kp", "vp"), 5)));
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("kp", "vp"), 5)));
|
||||
|
||||
assertThat(MetricAdapter.toMetricFamilySamples(metricData))
|
||||
.isEqualTo(
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
|
|
@ -75,24 +76,23 @@ public class PrometheusCollectorTest {
|
|||
"long_description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_LONG,
|
||||
Collections.singletonMap("kc", "vc")),
|
||||
Labels.of("kc", "vc")),
|
||||
Resource.create(
|
||||
Collections.singletonMap("kr", AttributeValue.stringAttributeValue("vr"))),
|
||||
InstrumentationLibraryInfo.create("grpc", "version"),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.LongPoint.create(123, 456, Collections.singletonMap("kp", "vp"), 5))),
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("kp", "vp"), 5))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"name",
|
||||
"double_description",
|
||||
"1",
|
||||
Descriptor.Type.MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("kc", "vc")),
|
||||
Labels.of("kc", "vc")),
|
||||
Resource.create(
|
||||
Collections.singletonMap("kr", AttributeValue.stringAttributeValue("vr"))),
|
||||
InstrumentationLibraryInfo.create("http", "version"),
|
||||
Collections.<Point>singletonList(
|
||||
MetricData.DoublePoint.create(
|
||||
123, 456, Collections.singletonMap("kp", "vp"), 3.5))));
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("kp", "vp"), 3.5))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -99,7 +100,7 @@ abstract class AbstractAsynchronousInstrument<T extends AsynchronousInstrument.R
|
|||
Aggregator aggregator = activeBatcher.getAggregator();
|
||||
aggregator.recordLong(sum);
|
||||
activeBatcher.batch(
|
||||
LabelSetSdk.create(keyValueLabelPairs), aggregator, /* mappedAggregator= */ false);
|
||||
Labels.of(keyValueLabelPairs), aggregator, /* mappedAggregator= */ false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -132,7 +133,7 @@ abstract class AbstractAsynchronousInstrument<T extends AsynchronousInstrument.R
|
|||
Aggregator aggregator = activeBatcher.getAggregator();
|
||||
aggregator.recordDouble(sum);
|
||||
activeBatcher.batch(
|
||||
LabelSetSdk.create(keyValueLabelPairs), aggregator, /* mappedAggregator= */ false);
|
||||
Labels.of(keyValueLabelPairs), aggregator, /* mappedAggregator= */ false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,16 +16,14 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.internal.StringUtils;
|
||||
import io.opentelemetry.internal.Utils;
|
||||
import io.opentelemetry.metrics.Instrument;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
abstract class AbstractInstrument implements Instrument {
|
||||
|
|
@ -97,7 +95,7 @@ abstract class AbstractInstrument implements Instrument {
|
|||
private final MeterSharedState meterSharedState;
|
||||
private String description = "";
|
||||
private String unit = "1";
|
||||
private Map<String, String> constantLabels = Collections.emptyMap();
|
||||
private Labels constantLabels = Labels.empty();
|
||||
|
||||
Builder(
|
||||
String name,
|
||||
|
|
@ -125,10 +123,8 @@ abstract class AbstractInstrument implements Instrument {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final B setConstantLabels(Map<String, String> constantLabels) {
|
||||
Utils.checkMapKeysNotNull(
|
||||
Objects.requireNonNull(constantLabels, "constantLabels"), "constantLabel");
|
||||
this.constantLabels = Collections.unmodifiableMap(new HashMap<>(constantLabels));
|
||||
public final B setConstantLabels(Labels constantLabels) {
|
||||
this.constantLabels = constantLabels;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -24,7 +25,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
|
||||
abstract class AbstractSynchronousInstrument<B extends AbstractBoundInstrument>
|
||||
extends AbstractInstrument {
|
||||
private final ConcurrentHashMap<LabelSetSdk, B> boundLabels;
|
||||
private final ConcurrentHashMap<Labels, B> boundLabels;
|
||||
private final ReentrantLock collectLock;
|
||||
|
||||
AbstractSynchronousInstrument(
|
||||
|
|
@ -37,7 +38,7 @@ abstract class AbstractSynchronousInstrument<B extends AbstractBoundInstrument>
|
|||
collectLock = new ReentrantLock();
|
||||
}
|
||||
|
||||
final B bind(LabelSetSdk labelSet) {
|
||||
final B bind(Labels labelSet) {
|
||||
B binding = boundLabels.get(labelSet);
|
||||
if (binding != null && binding.bind()) {
|
||||
// At this moment it is guaranteed that the Bound is in the map and will not be removed.
|
||||
|
|
@ -71,7 +72,7 @@ abstract class AbstractSynchronousInstrument<B extends AbstractBoundInstrument>
|
|||
collectLock.lock();
|
||||
try {
|
||||
Batcher batcher = getActiveBatcher();
|
||||
for (Map.Entry<LabelSetSdk, B> entry : boundLabels.entrySet()) {
|
||||
for (Map.Entry<Labels, B> entry : boundLabels.entrySet()) {
|
||||
boolean unmappedEntry = entry.getValue().tryUnmap();
|
||||
if (unmappedEntry) {
|
||||
// If able to unmap then remove the record from the current Map. This can race with the
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import java.util.List;
|
||||
|
|
@ -41,7 +42,7 @@ final class ActiveBatcher implements Batcher {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void batch(LabelSetSdk labelSet, Aggregator aggregator, boolean mappedAggregator) {
|
||||
public void batch(Labels labelSet, Aggregator aggregator, boolean mappedAggregator) {
|
||||
batcher.batch(labelSet, aggregator, mappedAggregator);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.BatchRecorder;
|
||||
import io.opentelemetry.metrics.DoubleCounter;
|
||||
import io.opentelemetry.metrics.DoubleUpDownCounter;
|
||||
|
|
@ -31,10 +32,10 @@ import io.opentelemetry.metrics.LongValueRecorder;
|
|||
* <p>TODO: Add an async queue processing to process batch records.
|
||||
*/
|
||||
final class BatchRecorderSdk implements BatchRecorder {
|
||||
private final LabelSetSdk labelSet;
|
||||
private final Labels labelSet;
|
||||
|
||||
BatchRecorderSdk(String... keyValuePairs) {
|
||||
this.labelSet = LabelSetSdk.create(keyValuePairs);
|
||||
this.labelSet = Labels.of(keyValuePairs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import java.util.List;
|
||||
|
|
@ -27,7 +28,7 @@ import java.util.List;
|
|||
*
|
||||
* <p>The only thread safe method in this class is {@link #getAggregator()}. An entire collection
|
||||
* cycle must be protected by a lock. A collection cycle is defined by multiple calls to {@link
|
||||
* #batch(LabelSetSdk, Aggregator, boolean)} followed by one {@link #completeCollectionCycle()};
|
||||
* #batch(Labels, Aggregator, boolean)} followed by one {@link #completeCollectionCycle()};
|
||||
*/
|
||||
interface Batcher {
|
||||
|
||||
|
|
@ -40,15 +41,15 @@ interface Batcher {
|
|||
|
||||
/**
|
||||
* Batches multiple entries together that are part of the same metric. It may remove labels from
|
||||
* the {@link LabelSetSdk} and merge aggregations together.
|
||||
* the {@link Labels} and merge aggregations together.
|
||||
*
|
||||
* @param labelSet the {@link LabelSetSdk} associated with this {@code Aggregator}.
|
||||
* @param labelSet the {@link Labels} associated with this {@code Aggregator}.
|
||||
* @param aggregator the {@link Aggregator} used to aggregate individual events for the given
|
||||
* {@code LabelSetSdk}.
|
||||
* @param mappedAggregator {@code true} if the {@code Aggregator} is still in used by a binding.
|
||||
* If {@code false} the {@code Batcher} can reuse the {@code Aggregator} instance.
|
||||
*/
|
||||
void batch(LabelSetSdk labelSet, Aggregator aggregator, boolean mappedAggregator);
|
||||
void batch(Labels labelSet, Aggregator aggregator, boolean mappedAggregator);
|
||||
|
||||
/**
|
||||
* Ends the current collection cycle and returns the list of metrics batched in this Batcher.
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.Clock;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.aggregator.Aggregator;
|
||||
|
|
@ -76,7 +77,7 @@ final class Batchers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void batch(LabelSetSdk labelSet, Aggregator aggregator, boolean mappedAggregator) {}
|
||||
public void batch(Labels labelSet, Aggregator aggregator, boolean mappedAggregator) {}
|
||||
|
||||
@Override
|
||||
public List<MetricData> completeCollectionCycle() {
|
||||
|
|
@ -90,7 +91,7 @@ final class Batchers {
|
|||
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
|
||||
private final Clock clock;
|
||||
private final AggregatorFactory aggregatorFactory;
|
||||
private Map<Map<String, String>, Aggregator> aggregatorMap;
|
||||
private Map<Labels, Aggregator> aggregatorMap;
|
||||
private long startEpochNanos;
|
||||
private final boolean delta;
|
||||
|
||||
|
|
@ -117,18 +118,16 @@ final class Batchers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final void batch(
|
||||
LabelSetSdk labelSet, Aggregator aggregator, boolean unmappedAggregator) {
|
||||
Map<String, String> labels = labelSet.getLabels();
|
||||
Aggregator currentAggregator = aggregatorMap.get(labels);
|
||||
public final void batch(Labels labelSet, Aggregator aggregator, boolean unmappedAggregator) {
|
||||
Aggregator currentAggregator = aggregatorMap.get(labelSet);
|
||||
if (currentAggregator == null) {
|
||||
// This aggregator is not mapped, we can use this instance.
|
||||
if (unmappedAggregator) {
|
||||
aggregatorMap.put(labels, aggregator);
|
||||
aggregatorMap.put(labelSet, aggregator);
|
||||
return;
|
||||
}
|
||||
currentAggregator = aggregatorFactory.getAggregator();
|
||||
aggregatorMap.put(labels, currentAggregator);
|
||||
aggregatorMap.put(labelSet, currentAggregator);
|
||||
}
|
||||
aggregator.mergeToAndReset(currentAggregator);
|
||||
}
|
||||
|
|
@ -137,7 +136,7 @@ final class Batchers {
|
|||
public final List<MetricData> completeCollectionCycle() {
|
||||
List<Point> points = new ArrayList<>(aggregatorMap.size());
|
||||
long epochNanos = clock.now();
|
||||
for (Map.Entry<Map<String, String>, Aggregator> entry : aggregatorMap.entrySet()) {
|
||||
for (Map.Entry<Labels, Aggregator> entry : aggregatorMap.entrySet()) {
|
||||
Point point = entry.getValue().toPoint(startEpochNanos, epochNanos, entry.getKey());
|
||||
if (point != null) {
|
||||
points.add(point);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.DoubleCounter;
|
||||
import io.opentelemetry.sdk.metrics.DoubleCounterSdk.BoundInstrument;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -40,10 +41,10 @@ final class DoubleCounterSdk extends AbstractSynchronousInstrument<BoundInstrume
|
|||
|
||||
@Override
|
||||
public void add(double increment, String... labelKeyValuePairs) {
|
||||
add(increment, LabelSetSdk.create(labelKeyValuePairs));
|
||||
add(increment, Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
void add(double increment, LabelSetSdk labelSet) {
|
||||
void add(double increment, Labels labelSet) {
|
||||
BoundInstrument boundInstrument = bind(labelSet);
|
||||
try {
|
||||
boundInstrument.add(increment);
|
||||
|
|
@ -54,7 +55,7 @@ final class DoubleCounterSdk extends AbstractSynchronousInstrument<BoundInstrume
|
|||
|
||||
@Override
|
||||
public BoundInstrument bind(String... labelKeyValuePairs) {
|
||||
return bind(LabelSetSdk.create(labelKeyValuePairs));
|
||||
return bind(Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.DoubleUpDownCounter;
|
||||
import io.opentelemetry.sdk.metrics.DoubleUpDownCounterSdk.BoundInstrument;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -40,10 +41,10 @@ final class DoubleUpDownCounterSdk extends AbstractSynchronousInstrument<BoundIn
|
|||
|
||||
@Override
|
||||
public void add(double increment, String... labelKeyValuePairs) {
|
||||
add(increment, LabelSetSdk.create(labelKeyValuePairs));
|
||||
add(increment, Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
public void add(double increment, LabelSetSdk labelSetSdk) {
|
||||
public void add(double increment, Labels labelSetSdk) {
|
||||
BoundInstrument boundInstrument = bind(labelSetSdk);
|
||||
boundInstrument.add(increment);
|
||||
boundInstrument.unbind();
|
||||
|
|
@ -51,7 +52,7 @@ final class DoubleUpDownCounterSdk extends AbstractSynchronousInstrument<BoundIn
|
|||
|
||||
@Override
|
||||
public BoundInstrument bind(String... labelKeyValuePairs) {
|
||||
return bind(LabelSetSdk.create(labelKeyValuePairs));
|
||||
return bind(Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.DoubleValueRecorder;
|
||||
import io.opentelemetry.sdk.metrics.DoubleValueRecorderSdk.BoundInstrument;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -43,10 +44,10 @@ final class DoubleValueRecorderSdk extends AbstractSynchronousInstrument<BoundIn
|
|||
|
||||
@Override
|
||||
public void record(double delta, String... labelKeyValuePairs) {
|
||||
record(delta, LabelSetSdk.create(labelKeyValuePairs));
|
||||
record(delta, Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
void record(double value, LabelSetSdk labelSet) {
|
||||
void record(double value, Labels labelSet) {
|
||||
BoundInstrument boundInstrument = bind(labelSet);
|
||||
boundInstrument.record(value);
|
||||
boundInstrument.unbind();
|
||||
|
|
@ -54,7 +55,7 @@ final class DoubleValueRecorderSdk extends AbstractSynchronousInstrument<BoundIn
|
|||
|
||||
@Override
|
||||
public BoundInstrument bind(String... labelKeyValuePairs) {
|
||||
return bind(LabelSetSdk.create(labelKeyValuePairs));
|
||||
return bind(Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ package io.opentelemetry.sdk.metrics;
|
|||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.auto.value.extension.memoized.Memoized;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@AutoValue
|
||||
|
|
@ -30,7 +30,7 @@ abstract class InstrumentDescriptor {
|
|||
String name,
|
||||
String description,
|
||||
String unit,
|
||||
Map<String, String> constantLabels,
|
||||
Labels constantLabels,
|
||||
InstrumentType type,
|
||||
InstrumentValueType valueType) {
|
||||
return new AutoValue_InstrumentDescriptor(
|
||||
|
|
@ -43,7 +43,7 @@ abstract class InstrumentDescriptor {
|
|||
|
||||
abstract String getUnit();
|
||||
|
||||
abstract Map<String, String> getConstantLabels();
|
||||
abstract Labels getConstantLabels();
|
||||
|
||||
abstract InstrumentType getType();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,46 +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 com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.internal.Utils;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@AutoValue
|
||||
@Immutable
|
||||
abstract class LabelSetSdk {
|
||||
private static final LabelSetSdk EMPTY =
|
||||
new AutoValue_LabelSetSdk(Collections.<String, String>emptyMap());
|
||||
|
||||
static LabelSetSdk create(String... keyValuePairs) {
|
||||
if (keyValuePairs.length == 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
Utils.validateLabelPairs(keyValuePairs);
|
||||
Map<String, String> data = new HashMap<>(keyValuePairs.length / 2);
|
||||
for (int i = 0; i < keyValuePairs.length; i++) {
|
||||
String key = keyValuePairs[i];
|
||||
data.put(key, keyValuePairs[++i]);
|
||||
}
|
||||
return new AutoValue_LabelSetSdk(Collections.unmodifiableMap(data));
|
||||
}
|
||||
|
||||
abstract Map<String, String> getLabels();
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.LongCounter;
|
||||
import io.opentelemetry.sdk.metrics.LongCounterSdk.BoundInstrument;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -40,10 +41,10 @@ final class LongCounterSdk extends AbstractSynchronousInstrument<BoundInstrument
|
|||
|
||||
@Override
|
||||
public void add(long increment, String... labelKeyValuePairs) {
|
||||
add(increment, LabelSetSdk.create(labelKeyValuePairs));
|
||||
add(increment, Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
void add(long increment, LabelSetSdk labelSet) {
|
||||
void add(long increment, Labels labelSet) {
|
||||
BoundInstrument boundInstrument = bind(labelSet);
|
||||
try {
|
||||
boundInstrument.add(increment);
|
||||
|
|
@ -54,7 +55,7 @@ final class LongCounterSdk extends AbstractSynchronousInstrument<BoundInstrument
|
|||
|
||||
@Override
|
||||
public BoundInstrument bind(String... labelKeyValuePairs) {
|
||||
return bind(LabelSetSdk.create(labelKeyValuePairs));
|
||||
return bind(Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.LongUpDownCounter;
|
||||
import io.opentelemetry.sdk.metrics.LongUpDownCounterSdk.BoundInstrument;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -40,10 +41,10 @@ final class LongUpDownCounterSdk extends AbstractSynchronousInstrument<BoundInst
|
|||
|
||||
@Override
|
||||
public void add(long increment, String... labelKeyValuePairs) {
|
||||
add(increment, LabelSetSdk.create(labelKeyValuePairs));
|
||||
add(increment, Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
public void add(long increment, LabelSetSdk labelSetSdk) {
|
||||
public void add(long increment, Labels labelSetSdk) {
|
||||
BoundInstrument boundInstrument = bind(labelSetSdk);
|
||||
boundInstrument.add(increment);
|
||||
boundInstrument.unbind();
|
||||
|
|
@ -51,7 +52,7 @@ final class LongUpDownCounterSdk extends AbstractSynchronousInstrument<BoundInst
|
|||
|
||||
@Override
|
||||
public BoundInstrument bind(String... labelKeyValuePairs) {
|
||||
return bind(LabelSetSdk.create(labelKeyValuePairs));
|
||||
return bind(Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.LongValueRecorder;
|
||||
import io.opentelemetry.sdk.metrics.LongValueRecorderSdk.BoundInstrument;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -43,10 +44,10 @@ final class LongValueRecorderSdk extends AbstractSynchronousInstrument<BoundInst
|
|||
|
||||
@Override
|
||||
public void record(long value, String... labelKeyValuePairs) {
|
||||
record(value, LabelSetSdk.create(labelKeyValuePairs));
|
||||
record(value, Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
void record(long value, LabelSetSdk labelSet) {
|
||||
void record(long value, Labels labelSet) {
|
||||
BoundInstrument boundInstrument = bind(labelSet);
|
||||
boundInstrument.record(value);
|
||||
boundInstrument.unbind();
|
||||
|
|
@ -54,7 +55,7 @@ final class LongValueRecorderSdk extends AbstractSynchronousInstrument<BoundInst
|
|||
|
||||
@Override
|
||||
public BoundInstrument bind(String... labelKeyValuePairs) {
|
||||
return bind(LabelSetSdk.create(labelKeyValuePairs));
|
||||
return bind(Labels.of(labelKeyValuePairs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ public interface Aggregator {
|
|||
* @return the {@code Point} with the value from this Aggregation.
|
||||
*/
|
||||
@Nullable
|
||||
Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels);
|
||||
Point toPoint(long startEpochNanos, long epochNanos, Labels labels);
|
||||
|
||||
/**
|
||||
* Updates the current aggregator with a newly recorded {@code long} value.
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ public final class DoubleLastValueAggregator extends AbstractAggregator {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
@Nullable Double currentValue = current.get();
|
||||
return currentValue == null
|
||||
? null
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
|
@ -55,7 +55,7 @@ public final class DoubleMinMaxSumCount extends AbstractAggregator {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return current.toPoint(startEpochNanos, epochNanos, labels);
|
||||
}
|
||||
|
||||
|
|
@ -125,8 +125,7 @@ public final class DoubleMinMaxSumCount extends AbstractAggregator {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private SummaryPoint toPoint(
|
||||
long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
private SummaryPoint toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
return count == 0
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@
|
|||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Map;
|
||||
|
||||
public final class DoubleSumAggregator extends AbstractAggregator {
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ public final class DoubleSumAggregator extends AbstractAggregator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return DoublePoint.create(startEpochNanos, epochNanos, labels, current.get());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ public final class LongLastValueAggregator extends AbstractAggregator {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
@Nullable Long currentValue = current.get();
|
||||
return currentValue == null
|
||||
? null
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
|
@ -56,7 +56,7 @@ public final class LongMinMaxSumCount extends AbstractAggregator {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return current.toPoint(startEpochNanos, epochNanos, labels);
|
||||
}
|
||||
|
||||
|
|
@ -126,8 +126,7 @@ public final class LongMinMaxSumCount extends AbstractAggregator {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private SummaryPoint toPoint(
|
||||
long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
private SummaryPoint toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
return count == 0
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public final class LongSumAggregator extends AbstractAggregator {
|
||||
|
|
@ -51,7 +51,7 @@ public final class LongSumAggregator extends AbstractAggregator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return LongPoint.create(startEpochNanos, epochNanos, labels, current.get());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package io.opentelemetry.sdk.metrics.aggregator;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class NoopAggregator implements Aggregator {
|
||||
|
|
@ -41,7 +41,7 @@ public final class NoopAggregator implements Aggregator {
|
|||
|
||||
@Nullable
|
||||
@Override
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Map<String, String> labels) {
|
||||
public Point toPoint(long startEpochNanos, long epochNanos, Labels labels) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@
|
|||
package io.opentelemetry.sdk.metrics.data;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
|
|
@ -104,7 +104,7 @@ public abstract class MetricData {
|
|||
*
|
||||
* @return the labels associated with this {@code Point}.
|
||||
*/
|
||||
public abstract Map<String, String> getLabels();
|
||||
public abstract Labels getLabels();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,7 +126,7 @@ public abstract class MetricData {
|
|||
public abstract long getValue();
|
||||
|
||||
public static LongPoint create(
|
||||
long startEpochNanos, long epochNanos, Map<String, String> labels, long value) {
|
||||
long startEpochNanos, long epochNanos, Labels labels, long value) {
|
||||
return new AutoValue_MetricData_LongPoint(startEpochNanos, epochNanos, labels, value);
|
||||
}
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ public abstract class MetricData {
|
|||
public abstract double getValue();
|
||||
|
||||
public static DoublePoint create(
|
||||
long startEpochNanos, long epochNanos, Map<String, String> labels, double value) {
|
||||
long startEpochNanos, long epochNanos, Labels labels, double value) {
|
||||
return new AutoValue_MetricData_DoublePoint(startEpochNanos, epochNanos, labels, value);
|
||||
}
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ public abstract class MetricData {
|
|||
public static SummaryPoint create(
|
||||
long startEpochNanos,
|
||||
long epochNanos,
|
||||
Map<String, String> labels,
|
||||
Labels labels,
|
||||
long count,
|
||||
double sum,
|
||||
List<ValueAtPercentile> percentileValues) {
|
||||
|
|
@ -313,14 +313,10 @@ public abstract class MetricData {
|
|||
* @return the constant labels associated with this metric descriptor.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Map<String, String> getConstantLabels();
|
||||
public abstract Labels getConstantLabels();
|
||||
|
||||
public static Descriptor create(
|
||||
String name,
|
||||
String description,
|
||||
String unit,
|
||||
Type type,
|
||||
Map<String, String> constantLabels) {
|
||||
String name, String description, String unit, Type type, Labels constantLabels) {
|
||||
return new AutoValue_MetricData_Descriptor(name, description, unit, type, constantLabels);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -27,7 +28,6 @@ import io.opentelemetry.sdk.resources.Resource;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
|
@ -42,8 +42,7 @@ public class AbstractInstrumentBuilderTest {
|
|||
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_2", "value_2");
|
||||
private static final Labels CONSTANT_LABELS = Labels.of("key_2", "value_2");
|
||||
private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE =
|
||||
MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty());
|
||||
private static final MeterSharedState METER_SHARED_STATE =
|
||||
|
|
@ -126,7 +125,7 @@ public class AbstractInstrumentBuilderTest {
|
|||
assertThat(testInstrument.getDescriptor().getName()).isEqualTo(NAME);
|
||||
assertThat(testInstrument.getDescriptor().getDescription()).isEmpty();
|
||||
assertThat(testInstrument.getDescriptor().getUnit()).isEqualTo("1");
|
||||
assertThat(testInstrument.getDescriptor().getConstantLabels()).isEmpty();
|
||||
assertThat(testInstrument.getDescriptor().getConstantLabels().isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -38,7 +39,7 @@ public class AbstractInstrumentTest {
|
|||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Collections.singletonMap("key_2", "value_2"),
|
||||
Labels.of("key_2", "value_2"),
|
||||
InstrumentType.COUNTER,
|
||||
InstrumentValueType.LONG);
|
||||
private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE =
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -70,7 +71,7 @@ public class BatchRecorderSdkTest {
|
|||
testSdk.doubleValueRecorderBuilder("testDoubleValueRecorder").build();
|
||||
LongValueRecorderSdk longValueRecorder =
|
||||
testSdk.longValueRecorderBuilder("testLongValueRecorder").build();
|
||||
LabelSetSdk labelSet = LabelSetSdk.create("key", "value");
|
||||
Labels labelSet = Labels.of("key", "value");
|
||||
|
||||
testSdk
|
||||
.newBatchRecorder("key", "value")
|
||||
|
|
@ -86,56 +87,36 @@ public class BatchRecorderSdkTest {
|
|||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testDoubleCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"testDoubleCounter", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now(), testClock.now(), labelSet.getLabels(), 12.1d))));
|
||||
DoublePoint.create(testClock.now(), testClock.now(), labelSet, 12.1d))));
|
||||
assertThat(longCounter.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testLongCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(testClock.now(), testClock.now(), labelSet.getLabels(), 12))));
|
||||
LongPoint.create(testClock.now(), testClock.now(), labelSet, 12))));
|
||||
assertThat(doubleUpDownCounter.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testDoubleUpDownCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"testDoubleUpDownCounter", "", "1", Type.NON_MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now(), testClock.now(), labelSet.getLabels(), -12.1d))));
|
||||
DoublePoint.create(testClock.now(), testClock.now(), labelSet, -12.1d))));
|
||||
assertThat(longUpDownCounter.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testLongUpDownCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.NON_MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"testLongUpDownCounter", "", "1", Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now(), testClock.now(), labelSet.getLabels(), -12))));
|
||||
LongPoint.create(testClock.now(), testClock.now(), labelSet, -12))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.DoubleCounter;
|
||||
import io.opentelemetry.metrics.DoubleCounter.BoundDoubleCounter;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -60,7 +61,7 @@ public class DoubleCounterSdkTest {
|
|||
DoubleCounterSdk doubleCounter =
|
||||
testSdk
|
||||
.doubleCounterBuilder("testCounter")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -74,7 +75,7 @@ public class DoubleCounterSdkTest {
|
|||
"My very own counter",
|
||||
"ms",
|
||||
Type.MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("sk1", "sv1")));
|
||||
Labels.of("sk1", "sv1")));
|
||||
assertThat(metricData.getResource()).isEqualTo(RESOURCE);
|
||||
assertThat(metricData.getInstrumentationLibraryInfo()).isEqualTo(INSTRUMENTATION_LIBRARY_INFO);
|
||||
assertThat(metricData.getPoints()).isEmpty();
|
||||
|
|
@ -96,16 +97,13 @@ public class DoubleCounterSdkTest {
|
|||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
12.1d));
|
||||
testClock.now() - SECOND_NANOS, testClock.now(), Labels.empty(), 12.1d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithMultipleCollects() {
|
||||
LabelSetSdk labelSet = LabelSetSdk.create("K", "V");
|
||||
LabelSetSdk emptyLabelSet = LabelSetSdk.create();
|
||||
Labels labelSet = Labels.of("K", "V");
|
||||
Labels emptyLabelSet = Labels.empty();
|
||||
long startTime = testClock.now();
|
||||
DoubleCounterSdk doubleCounter = testSdk.doubleCounterBuilder("testCounter").build();
|
||||
BoundDoubleCounter boundCounter = doubleCounter.bind("K", "V");
|
||||
|
|
@ -126,8 +124,8 @@ public class DoubleCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(startTime, firstCollect, labelSet.getLabels(), 555.9d),
|
||||
DoublePoint.create(startTime, firstCollect, emptyLabelSet.getLabels(), 33.5d));
|
||||
DoublePoint.create(startTime, firstCollect, labelSet, 555.9d),
|
||||
DoublePoint.create(startTime, firstCollect, emptyLabelSet, 33.5d));
|
||||
|
||||
// Repeat to prove we keep previous values.
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
|
|
@ -141,8 +139,8 @@ public class DoubleCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(startTime, secondCollect, labelSet.getLabels(), 777.9d),
|
||||
DoublePoint.create(startTime, secondCollect, emptyLabelSet.getLabels(), 44.5d));
|
||||
DoublePoint.create(startTime, secondCollect, labelSet, 777.9d),
|
||||
DoublePoint.create(startTime, secondCollect, emptyLabelSet, 44.5d));
|
||||
} finally {
|
||||
boundCounter.unbind();
|
||||
}
|
||||
|
|
@ -215,8 +213,7 @@ public class DoubleCounterSdkTest {
|
|||
assertThat(metricDataList).hasSize(1);
|
||||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(
|
||||
testClock.now(), testClock.now(), Collections.singletonMap("K", "V"), 80_000));
|
||||
DoublePoint.create(testClock.now(), testClock.now(), Labels.of("K", "V"), 80_000));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -244,25 +241,13 @@ public class DoubleCounterSdkTest {
|
|||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[0], values[0]),
|
||||
40_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[0], values[0]), 40_000),
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[1], values[1]),
|
||||
40_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[1], values[1]), 40_000),
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[2], values[2]),
|
||||
40_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[2], values[2]), 40_000),
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[3], values[3]),
|
||||
40_000));
|
||||
testClock.now(), testClock.now(), Labels.of(keys[3], values[3]), 40_000));
|
||||
}
|
||||
|
||||
private static class OperationUpdaterWithBinding extends OperationUpdater {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -60,7 +61,7 @@ public class DoubleSumObserverSdkTest {
|
|||
DoubleSumObserverSdk doubleSumObserver =
|
||||
testSdk
|
||||
.doubleSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own DoubleSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -72,7 +73,7 @@ public class DoubleSumObserverSdkTest {
|
|||
DoubleSumObserverSdk doubleSumObserver =
|
||||
testSdk
|
||||
.doubleSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own DoubleSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -91,7 +92,7 @@ public class DoubleSumObserverSdkTest {
|
|||
"My own DoubleSumObserver",
|
||||
"ms",
|
||||
Type.MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -112,37 +113,27 @@ public class DoubleSumObserverSdkTest {
|
|||
assertThat(doubleSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12.1d))));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(doubleSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12.1d))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.DoubleUpDownCounter;
|
||||
import io.opentelemetry.metrics.DoubleUpDownCounter.BoundDoubleUpDownCounter;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -61,7 +62,7 @@ public class DoubleUpDownCounterSdkTest {
|
|||
DoubleUpDownCounterSdk doubleUpDownCounter =
|
||||
testSdk
|
||||
.doubleUpDownCounterBuilder("testCounter")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -75,7 +76,7 @@ public class DoubleUpDownCounterSdkTest {
|
|||
"My very own counter",
|
||||
"ms",
|
||||
Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("sk1", "sv1")));
|
||||
Labels.of("sk1", "sv1")));
|
||||
assertThat(metricData.getResource()).isEqualTo(RESOURCE);
|
||||
assertThat(metricData.getInstrumentationLibraryInfo()).isEqualTo(INSTRUMENTATION_LIBRARY_INFO);
|
||||
assertThat(metricData.getPoints()).isEmpty();
|
||||
|
|
@ -98,16 +99,13 @@ public class DoubleUpDownCounterSdkTest {
|
|||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
12.1d));
|
||||
testClock.now() - SECOND_NANOS, testClock.now(), Labels.empty(), 12.1d));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithMultipleCollects() {
|
||||
LabelSetSdk labelSet = LabelSetSdk.create("K", "V");
|
||||
LabelSetSdk emptyLabelSet = LabelSetSdk.create();
|
||||
Labels labelSet = Labels.of("K", "V");
|
||||
Labels emptyLabelSet = Labels.empty();
|
||||
long startTime = testClock.now();
|
||||
DoubleUpDownCounterSdk doubleUpDownCounter =
|
||||
testSdk.doubleUpDownCounterBuilder("testCounter").build();
|
||||
|
|
@ -129,8 +127,8 @@ public class DoubleUpDownCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(startTime, firstCollect, labelSet.getLabels(), 555.9d),
|
||||
DoublePoint.create(startTime, firstCollect, emptyLabelSet.getLabels(), 33.5d));
|
||||
DoublePoint.create(startTime, firstCollect, labelSet, 555.9d),
|
||||
DoublePoint.create(startTime, firstCollect, emptyLabelSet, 33.5d));
|
||||
|
||||
// Repeat to prove we keep previous values.
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
|
|
@ -144,8 +142,8 @@ public class DoubleUpDownCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(startTime, secondCollect, labelSet.getLabels(), 777.9d),
|
||||
DoublePoint.create(startTime, secondCollect, emptyLabelSet.getLabels(), 44.5d));
|
||||
DoublePoint.create(startTime, secondCollect, labelSet, 777.9d),
|
||||
DoublePoint.create(startTime, secondCollect, emptyLabelSet, 44.5d));
|
||||
} finally {
|
||||
boundCounter.unbind();
|
||||
}
|
||||
|
|
@ -205,8 +203,7 @@ public class DoubleUpDownCounterSdkTest {
|
|||
assertThat(metricDataList).hasSize(1);
|
||||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(
|
||||
testClock.now(), testClock.now(), Collections.singletonMap("K", "V"), 80_000));
|
||||
DoublePoint.create(testClock.now(), testClock.now(), Labels.of("K", "V"), 80_000));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -237,25 +234,13 @@ public class DoubleUpDownCounterSdkTest {
|
|||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[0], values[0]),
|
||||
40_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[0], values[0]), 40_000),
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[1], values[1]),
|
||||
40_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[1], values[1]), 40_000),
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[2], values[2]),
|
||||
40_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[2], values[2]), 40_000),
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[3], values[3]),
|
||||
40_000));
|
||||
testClock.now(), testClock.now(), Labels.of(keys[3], values[3]), 40_000));
|
||||
}
|
||||
|
||||
private static class OperationUpdaterWithBinding extends OperationUpdater {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -60,7 +61,7 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
DoubleUpDownSumObserverSdk doubleUpDownSumObserver =
|
||||
testSdk
|
||||
.doubleUpDownSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own DoubleUpDownSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -72,7 +73,7 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
DoubleUpDownSumObserverSdk doubleUpDownSumObserver =
|
||||
testSdk
|
||||
.doubleUpDownSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own DoubleUpDownSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -91,7 +92,7 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
"My own DoubleUpDownSumObserver",
|
||||
"ms",
|
||||
Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -113,36 +114,28 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"testObserver", "", "1", Type.NON_MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12.1d))));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(doubleUpDownSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"testObserver", "", "1", Type.NON_MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12.1d))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -63,7 +64,7 @@ public class DoubleValueObserverSdkTest {
|
|||
DoubleValueObserverSdk doubleValueObserver =
|
||||
testSdk
|
||||
.doubleValueObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own DoubleValueObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -75,7 +76,7 @@ public class DoubleValueObserverSdkTest {
|
|||
DoubleValueObserverSdk doubleValueObserver =
|
||||
testSdk
|
||||
.doubleValueObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own DoubleValueObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -94,7 +95,7 @@ public class DoubleValueObserverSdkTest {
|
|||
"My own DoubleValueObserver",
|
||||
"ms",
|
||||
Type.SUMMARY,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -115,15 +116,14 @@ public class DoubleValueObserverSdkTest {
|
|||
assertThat(doubleValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver", "", "1", Type.SUMMARY, Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
1,
|
||||
12.1d,
|
||||
valueAtPercentiles(12.1d, 12.1d)))));
|
||||
|
|
@ -131,15 +131,14 @@ public class DoubleValueObserverSdkTest {
|
|||
assertThat(doubleValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver", "", "1", Type.SUMMARY, Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
1,
|
||||
12.1d,
|
||||
valueAtPercentiles(12.1d, 12.1d)))));
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.DoubleValueRecorder;
|
||||
import io.opentelemetry.metrics.DoubleValueRecorder.BoundDoubleValueRecorder;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -64,7 +65,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
DoubleValueRecorderSdk doubleMeasure =
|
||||
testSdk
|
||||
.doubleValueRecorderBuilder("testMeasure")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own measure")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -78,7 +79,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
"My very own measure",
|
||||
"ms",
|
||||
Type.SUMMARY,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -89,7 +90,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
DoubleValueRecorderSdk doubleMeasure =
|
||||
testSdk
|
||||
.doubleValueRecorderBuilder("testMeasure")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own measure")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -105,7 +106,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
"My very own measure",
|
||||
"ms",
|
||||
Type.SUMMARY,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -121,15 +122,14 @@ public class DoubleValueRecorderSdkTest {
|
|||
assertThat(metricDataList)
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testMeasure", "", "1", Type.SUMMARY, Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testMeasure", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
Labels.empty(),
|
||||
1,
|
||||
12.1d,
|
||||
valueAtPercentiles(12.1d, 12.1d)))));
|
||||
|
|
@ -137,8 +137,8 @@ public class DoubleValueRecorderSdkTest {
|
|||
|
||||
@Test
|
||||
public void collectMetrics_WithMultipleCollects() {
|
||||
LabelSetSdk labelSet = LabelSetSdk.create("K", "V");
|
||||
LabelSetSdk emptyLabelSet = LabelSetSdk.create();
|
||||
Labels labelSet = Labels.of("K", "V");
|
||||
Labels emptyLabelSet = Labels.empty();
|
||||
long startTime = testClock.now();
|
||||
DoubleValueRecorderSdk doubleMeasure =
|
||||
testSdk.doubleValueRecorderBuilder("testMeasure").build();
|
||||
|
|
@ -162,14 +162,14 @@ public class DoubleValueRecorderSdkTest {
|
|||
SummaryPoint.create(
|
||||
startTime,
|
||||
firstCollect,
|
||||
emptyLabelSet.getLabels(),
|
||||
emptyLabelSet,
|
||||
2,
|
||||
-1.0d,
|
||||
valueAtPercentiles(-13.1d, 12.1d)),
|
||||
SummaryPoint.create(
|
||||
startTime,
|
||||
firstCollect,
|
||||
labelSet.getLabels(),
|
||||
labelSet,
|
||||
3,
|
||||
323.3d,
|
||||
valueAtPercentiles(-121.5d, 321.5d)));
|
||||
|
|
@ -188,14 +188,14 @@ public class DoubleValueRecorderSdkTest {
|
|||
SummaryPoint.create(
|
||||
startTime,
|
||||
secondCollect,
|
||||
emptyLabelSet.getLabels(),
|
||||
emptyLabelSet,
|
||||
3,
|
||||
16.0d,
|
||||
valueAtPercentiles(-13.1d, 17d)),
|
||||
SummaryPoint.create(
|
||||
startTime,
|
||||
secondCollect,
|
||||
labelSet.getLabels(),
|
||||
labelSet,
|
||||
4,
|
||||
545.3d,
|
||||
valueAtPercentiles(-121.5, 321.5d)));
|
||||
|
|
@ -263,7 +263,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap("K", "V"),
|
||||
Labels.of("K", "V"),
|
||||
8_000,
|
||||
80_000,
|
||||
valueAtPercentiles(9.0, 11.0)));
|
||||
|
|
@ -300,28 +300,28 @@ public class DoubleValueRecorderSdkTest {
|
|||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[0], values[0]),
|
||||
Labels.of(keys[0], values[0]),
|
||||
4_000,
|
||||
40_000d,
|
||||
valueAtPercentiles(9.0, 11.0)),
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[1], values[1]),
|
||||
Labels.of(keys[1], values[1]),
|
||||
4_000,
|
||||
40_000d,
|
||||
valueAtPercentiles(9.0, 11.0)),
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[2], values[2]),
|
||||
Labels.of(keys[2], values[2]),
|
||||
4_000,
|
||||
40_000d,
|
||||
valueAtPercentiles(9.0, 11.0)),
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[3], values[3]),
|
||||
Labels.of(keys[3], values[3]),
|
||||
4_000,
|
||||
40_000d,
|
||||
valueAtPercentiles(9.0, 11.0)));
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.common.InstrumentType;
|
||||
|
|
@ -40,7 +41,7 @@ public class InstrumentRegistryTest {
|
|||
"name",
|
||||
"description",
|
||||
"1",
|
||||
Collections.singletonMap("key_2", "value_2"),
|
||||
Labels.of("key_2", "value_2"),
|
||||
InstrumentType.COUNTER,
|
||||
InstrumentValueType.LONG);
|
||||
private static final InstrumentDescriptor OTHER_INSTRUMENT_DESCRIPTOR =
|
||||
|
|
@ -48,7 +49,7 @@ public class InstrumentRegistryTest {
|
|||
"name",
|
||||
"other_description",
|
||||
"1",
|
||||
Collections.singletonMap("key_2", "value_2"),
|
||||
Labels.of("key_2", "value_2"),
|
||||
InstrumentType.COUNTER,
|
||||
InstrumentValueType.LONG);
|
||||
private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE =
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.LongCounter;
|
||||
import io.opentelemetry.metrics.LongCounter.BoundLongCounter;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -60,7 +61,7 @@ public class LongCounterSdkTest {
|
|||
LongCounterSdk longCounter =
|
||||
testSdk
|
||||
.longCounterBuilder("testCounter")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -74,7 +75,7 @@ public class LongCounterSdkTest {
|
|||
"My very own counter",
|
||||
"ms",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.singletonMap("sk1", "sv1")));
|
||||
Labels.of("sk1", "sv1")));
|
||||
assertThat(metricData.getResource()).isEqualTo(RESOURCE);
|
||||
assertThat(metricData.getInstrumentationLibraryInfo()).isEqualTo(INSTRUMENTATION_LIBRARY_INFO);
|
||||
assertThat(metricData.getPoints()).isEmpty();
|
||||
|
|
@ -93,17 +94,13 @@ public class LongCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(1);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
12));
|
||||
LongPoint.create(testClock.now() - SECOND_NANOS, testClock.now(), Labels.empty(), 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithMultipleCollects() {
|
||||
LabelSetSdk labelSet = LabelSetSdk.create("K", "V");
|
||||
LabelSetSdk emptyLabelSet = LabelSetSdk.create();
|
||||
Labels labelSet = Labels.of("K", "V");
|
||||
Labels emptyLabelSet = Labels.empty();
|
||||
long startTime = testClock.now();
|
||||
LongCounterSdk longCounter = testSdk.longCounterBuilder("testCounter").build();
|
||||
BoundLongCounter boundCounter = longCounter.bind("K", "V");
|
||||
|
|
@ -124,8 +121,8 @@ public class LongCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(startTime, firstCollect, labelSet.getLabels(), 555),
|
||||
LongPoint.create(startTime, firstCollect, emptyLabelSet.getLabels(), 33));
|
||||
LongPoint.create(startTime, firstCollect, labelSet, 555),
|
||||
LongPoint.create(startTime, firstCollect, emptyLabelSet, 33));
|
||||
|
||||
// Repeat to prove we keep previous values.
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
|
|
@ -139,8 +136,8 @@ public class LongCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(startTime, secondCollect, labelSet.getLabels(), 777),
|
||||
LongPoint.create(startTime, secondCollect, emptyLabelSet.getLabels(), 44));
|
||||
LongPoint.create(startTime, secondCollect, labelSet, 777),
|
||||
LongPoint.create(startTime, secondCollect, emptyLabelSet, 44));
|
||||
} finally {
|
||||
boundCounter.unbind();
|
||||
}
|
||||
|
|
@ -213,8 +210,7 @@ public class LongCounterSdkTest {
|
|||
assertThat(metricDataList).hasSize(1);
|
||||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(
|
||||
testClock.now(), testClock.now(), Collections.singletonMap("K", "V"), 160_000));
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.of("K", "V"), 160_000));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -242,25 +238,13 @@ public class LongCounterSdkTest {
|
|||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[0], values[0]),
|
||||
20_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[0], values[0]), 20_000),
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[1], values[1]),
|
||||
20_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[1], values[1]), 20_000),
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[2], values[2]),
|
||||
20_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[2], values[2]), 20_000),
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[3], values[3]),
|
||||
20_000));
|
||||
testClock.now(), testClock.now(), Labels.of(keys[3], values[3]), 20_000));
|
||||
}
|
||||
|
||||
private static class OperationUpdaterWithBinding extends OperationUpdater {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -60,7 +61,7 @@ public class LongSumObserverSdkTest {
|
|||
LongSumObserverSdk longSumObserver =
|
||||
testSdk
|
||||
.longSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own LongSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -72,7 +73,7 @@ public class LongSumObserverSdkTest {
|
|||
LongSumObserverSdk longSumObserver =
|
||||
testSdk
|
||||
.longSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own LongSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -91,7 +92,7 @@ public class LongSumObserverSdkTest {
|
|||
"My own LongSumObserver",
|
||||
"ms",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -111,37 +112,27 @@ public class LongSumObserverSdkTest {
|
|||
assertThat(longSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12))));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(longSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.LongUpDownCounter;
|
||||
import io.opentelemetry.metrics.LongUpDownCounter.BoundLongUpDownCounter;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -61,7 +62,7 @@ public class LongUpDownCounterSdkTest {
|
|||
LongUpDownCounterSdk longUpDownCounter =
|
||||
testSdk
|
||||
.longUpDownCounterBuilder("testCounter")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -75,7 +76,7 @@ public class LongUpDownCounterSdkTest {
|
|||
"My very own counter",
|
||||
"ms",
|
||||
Type.NON_MONOTONIC_LONG,
|
||||
Collections.singletonMap("sk1", "sv1")));
|
||||
Labels.of("sk1", "sv1")));
|
||||
assertThat(metricData.getResource()).isEqualTo(RESOURCE);
|
||||
assertThat(metricData.getInstrumentationLibraryInfo()).isEqualTo(INSTRUMENTATION_LIBRARY_INFO);
|
||||
assertThat(metricData.getPoints()).isEmpty();
|
||||
|
|
@ -95,17 +96,13 @@ public class LongUpDownCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(1);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
12));
|
||||
LongPoint.create(testClock.now() - SECOND_NANOS, testClock.now(), Labels.empty(), 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithMultipleCollects() {
|
||||
LabelSetSdk labelSet = LabelSetSdk.create("K", "V");
|
||||
LabelSetSdk emptyLabelSet = LabelSetSdk.create();
|
||||
Labels labelSet = Labels.of("K", "V");
|
||||
Labels emptyLabelSet = Labels.empty();
|
||||
long startTime = testClock.now();
|
||||
LongUpDownCounterSdk longUpDownCounter =
|
||||
testSdk.longUpDownCounterBuilder("testCounter").build();
|
||||
|
|
@ -127,8 +124,8 @@ public class LongUpDownCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(startTime, firstCollect, labelSet.getLabels(), 555),
|
||||
LongPoint.create(startTime, firstCollect, emptyLabelSet.getLabels(), 33));
|
||||
LongPoint.create(startTime, firstCollect, labelSet, 555),
|
||||
LongPoint.create(startTime, firstCollect, emptyLabelSet, 33));
|
||||
|
||||
// Repeat to prove we keep previous values.
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
|
|
@ -142,8 +139,8 @@ public class LongUpDownCounterSdkTest {
|
|||
assertThat(metricData.getPoints()).hasSize(2);
|
||||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(startTime, secondCollect, labelSet.getLabels(), 777),
|
||||
LongPoint.create(startTime, secondCollect, emptyLabelSet.getLabels(), 44));
|
||||
LongPoint.create(startTime, secondCollect, labelSet, 777),
|
||||
LongPoint.create(startTime, secondCollect, emptyLabelSet, 44));
|
||||
} finally {
|
||||
boundCounter.unbind();
|
||||
}
|
||||
|
|
@ -203,8 +200,7 @@ public class LongUpDownCounterSdkTest {
|
|||
assertThat(metricDataList).hasSize(1);
|
||||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(
|
||||
testClock.now(), testClock.now(), Collections.singletonMap("K", "V"), 160_000));
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.of("K", "V"), 160_000));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -235,25 +231,13 @@ public class LongUpDownCounterSdkTest {
|
|||
assertThat(metricDataList.get(0).getPoints())
|
||||
.containsExactly(
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[0], values[0]),
|
||||
20_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[0], values[0]), 20_000),
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[1], values[1]),
|
||||
20_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[1], values[1]), 20_000),
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[2], values[2]),
|
||||
20_000),
|
||||
testClock.now(), testClock.now(), Labels.of(keys[2], values[2]), 20_000),
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[3], values[3]),
|
||||
20_000));
|
||||
testClock.now(), testClock.now(), Labels.of(keys[3], values[3]), 20_000));
|
||||
}
|
||||
|
||||
private static class OperationUpdaterWithBinding extends OperationUpdater {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -60,7 +61,7 @@ public class LongUpDownSumObserverSdkTest {
|
|||
LongUpDownSumObserverSdk longUpDownSumObserver =
|
||||
testSdk
|
||||
.longUpDownSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own LongUpDownSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -72,7 +73,7 @@ public class LongUpDownSumObserverSdkTest {
|
|||
LongUpDownSumObserverSdk longUpDownSumObserver =
|
||||
testSdk
|
||||
.longUpDownSumObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own LongUpDownSumObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -91,7 +92,7 @@ public class LongUpDownSumObserverSdkTest {
|
|||
"My own LongUpDownSumObserver",
|
||||
"ms",
|
||||
Type.NON_MONOTONIC_LONG,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -112,37 +113,27 @@ public class LongUpDownSumObserverSdkTest {
|
|||
assertThat(longUpDownSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.NON_MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12))));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(longUpDownSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver",
|
||||
"",
|
||||
"1",
|
||||
Type.NON_MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
12))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -63,7 +64,7 @@ public class LongValueObserverSdkTest {
|
|||
LongValueObserverSdk longValueObserver =
|
||||
testSdk
|
||||
.longValueObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own LongValueObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -75,7 +76,7 @@ public class LongValueObserverSdkTest {
|
|||
LongValueObserverSdk longValueObserver =
|
||||
testSdk
|
||||
.longValueObserverBuilder("testObserver")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My own LongValueObserver")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -94,7 +95,7 @@ public class LongValueObserverSdkTest {
|
|||
"My own LongValueObserver",
|
||||
"ms",
|
||||
Type.SUMMARY,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -115,15 +116,14 @@ public class LongValueObserverSdkTest {
|
|||
assertThat(longValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver", "", "1", Type.SUMMARY, Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
1,
|
||||
12,
|
||||
valueAtPercentiles(12, 12)))));
|
||||
|
|
@ -131,15 +131,14 @@ public class LongValueObserverSdkTest {
|
|||
assertThat(longValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testObserver", "", "1", Type.SUMMARY, Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.singletonMap("k", "v"),
|
||||
Labels.of("k", "v"),
|
||||
1,
|
||||
12,
|
||||
valueAtPercentiles(12, 12)))));
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.LongValueRecorder;
|
||||
import io.opentelemetry.metrics.LongValueRecorder.BoundLongValueRecorder;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -64,7 +65,7 @@ public class LongValueRecorderSdkTest {
|
|||
LongValueRecorderSdk longMeasure =
|
||||
testSdk
|
||||
.longValueRecorderBuilder("testMeasure")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -78,7 +79,7 @@ public class LongValueRecorderSdkTest {
|
|||
"My very own counter",
|
||||
"ms",
|
||||
Type.SUMMARY,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -89,7 +90,7 @@ public class LongValueRecorderSdkTest {
|
|||
LongValueRecorderSdk longMeasure =
|
||||
testSdk
|
||||
.longValueRecorderBuilder("testMeasure")
|
||||
.setConstantLabels(Collections.singletonMap("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("ms")
|
||||
.build();
|
||||
|
|
@ -106,7 +107,7 @@ public class LongValueRecorderSdkTest {
|
|||
"My very own counter",
|
||||
"ms",
|
||||
Type.SUMMARY,
|
||||
Collections.singletonMap("sk1", "sv1")),
|
||||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
|
|
@ -121,15 +122,14 @@ public class LongValueRecorderSdkTest {
|
|||
assertThat(metricDataList)
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testMeasure", "", "1", Type.SUMMARY, Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testMeasure", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
Labels.empty(),
|
||||
1,
|
||||
12,
|
||||
valueAtPercentiles(12, 12)))));
|
||||
|
|
@ -137,8 +137,8 @@ public class LongValueRecorderSdkTest {
|
|||
|
||||
@Test
|
||||
public void collectMetrics_WithMultipleCollects() {
|
||||
LabelSetSdk labelSet = LabelSetSdk.create("K", "V");
|
||||
LabelSetSdk emptyLabelSet = LabelSetSdk.create();
|
||||
Labels labelSet = Labels.of("K", "V");
|
||||
Labels emptyLabelSet = Labels.empty();
|
||||
long startTime = testClock.now();
|
||||
LongValueRecorderSdk longMeasure = testSdk.longValueRecorderBuilder("testMeasure").build();
|
||||
BoundLongValueRecorder boundMeasure = longMeasure.bind("K", "V");
|
||||
|
|
@ -160,19 +160,9 @@ public class LongValueRecorderSdkTest {
|
|||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
SummaryPoint.create(
|
||||
startTime,
|
||||
firstCollect,
|
||||
emptyLabelSet.getLabels(),
|
||||
2,
|
||||
-2,
|
||||
valueAtPercentiles(-14, 12)),
|
||||
startTime, firstCollect, emptyLabelSet, 2, -2, valueAtPercentiles(-14, 12)),
|
||||
SummaryPoint.create(
|
||||
startTime,
|
||||
firstCollect,
|
||||
labelSet.getLabels(),
|
||||
3,
|
||||
323,
|
||||
valueAtPercentiles(-121, 321)));
|
||||
startTime, firstCollect, labelSet, 3, 323, valueAtPercentiles(-121, 321)));
|
||||
|
||||
// Repeat to prove we keep previous values.
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
|
|
@ -187,19 +177,9 @@ public class LongValueRecorderSdkTest {
|
|||
assertThat(metricData.getPoints())
|
||||
.containsExactly(
|
||||
SummaryPoint.create(
|
||||
startTime,
|
||||
secondCollect,
|
||||
emptyLabelSet.getLabels(),
|
||||
3,
|
||||
15,
|
||||
valueAtPercentiles(-14, 17)),
|
||||
startTime, secondCollect, emptyLabelSet, 3, 15, valueAtPercentiles(-14, 17)),
|
||||
SummaryPoint.create(
|
||||
startTime,
|
||||
secondCollect,
|
||||
labelSet.getLabels(),
|
||||
4,
|
||||
545,
|
||||
valueAtPercentiles(-121, 321)));
|
||||
startTime, secondCollect, labelSet, 4, 545, valueAtPercentiles(-121, 321)));
|
||||
} finally {
|
||||
boundMeasure.unbind();
|
||||
}
|
||||
|
|
@ -265,7 +245,7 @@ public class LongValueRecorderSdkTest {
|
|||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap("K", "V"),
|
||||
Labels.of("K", "V"),
|
||||
16_000,
|
||||
160_000,
|
||||
valueAtPercentiles(9, 11)));
|
||||
|
|
@ -305,28 +285,28 @@ public class LongValueRecorderSdkTest {
|
|||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[0], values[0]),
|
||||
Labels.of(keys[0], values[0]),
|
||||
2_000,
|
||||
20_000,
|
||||
valueAtPercentiles(9, 11)),
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[1], values[1]),
|
||||
Labels.of(keys[1], values[1]),
|
||||
2_000,
|
||||
20_000,
|
||||
valueAtPercentiles(9, 11)),
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[2], values[2]),
|
||||
Labels.of(keys[2], values[2]),
|
||||
2_000,
|
||||
20_000,
|
||||
valueAtPercentiles(9, 11)),
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.singletonMap(keys[3], values[3]),
|
||||
Labels.of(keys[3], values[3]),
|
||||
2_000,
|
||||
20_000,
|
||||
valueAtPercentiles(9, 11)));
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.Clock;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
|
|
@ -105,34 +106,16 @@ public class MeterSdkRegistryTest {
|
|||
assertThat(meterRegistry.getMetricProducer().getAllMetrics())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testLongCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Resource.getEmpty(),
|
||||
meterSdk1.getInstrumentationLibraryInfo(),
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
10))),
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.empty(), 10))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testLongCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Resource.getEmpty(),
|
||||
meterSdk2.getInstrumentationLibraryInfo(),
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
10))));
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.empty(), 10))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ package io.opentelemetry.sdk.metrics;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.BatchRecorder;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
|
|
@ -62,7 +62,7 @@ public class MeterSdkTest {
|
|||
LongCounterSdk longCounter =
|
||||
testSdk
|
||||
.longCounterBuilder("testLongCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -71,7 +71,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.longCounterBuilder("testLongCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -87,7 +87,7 @@ public class MeterSdkTest {
|
|||
LongUpDownCounterSdk longUpDownCounter =
|
||||
testSdk
|
||||
.longUpDownCounterBuilder("testLongUpDownCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -96,7 +96,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.longUpDownCounterBuilder("testLongUpDownCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -112,7 +112,7 @@ public class MeterSdkTest {
|
|||
LongValueRecorderSdk longValueRecorder =
|
||||
testSdk
|
||||
.longValueRecorderBuilder("testLongValueRecorder")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -121,7 +121,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.longValueRecorderBuilder("testLongValueRecorder")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -137,7 +137,7 @@ public class MeterSdkTest {
|
|||
LongSumObserverSdk longObserver =
|
||||
testSdk
|
||||
.longSumObserverBuilder("testLongSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -146,7 +146,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.longSumObserverBuilder("testLongSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -162,7 +162,7 @@ public class MeterSdkTest {
|
|||
LongUpDownSumObserverSdk longObserver =
|
||||
testSdk
|
||||
.longUpDownSumObserverBuilder("testLongUpDownSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -171,7 +171,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.longUpDownSumObserverBuilder("testLongUpDownSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -187,7 +187,7 @@ public class MeterSdkTest {
|
|||
DoubleCounterSdk doubleCounter =
|
||||
testSdk
|
||||
.doubleCounterBuilder("testDoubleCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -196,7 +196,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.doubleCounterBuilder("testDoubleCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -212,7 +212,7 @@ public class MeterSdkTest {
|
|||
DoubleUpDownCounterSdk doubleUpDownCounter =
|
||||
testSdk
|
||||
.doubleUpDownCounterBuilder("testDoubleUpDownCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -221,7 +221,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.doubleUpDownCounterBuilder("testDoubleUpDownCounter")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -237,7 +237,7 @@ public class MeterSdkTest {
|
|||
DoubleValueRecorderSdk doubleValueRecorder =
|
||||
testSdk
|
||||
.doubleValueRecorderBuilder("testDoubleValueRecorder")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own ValueRecorder")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -246,7 +246,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.doubleValueRecorderBuilder("testDoubleValueRecorder")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own ValueRecorder")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -262,7 +262,7 @@ public class MeterSdkTest {
|
|||
DoubleSumObserverSdk doubleObserver =
|
||||
testSdk
|
||||
.doubleSumObserverBuilder("testDoubleSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -271,7 +271,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.doubleSumObserverBuilder("testDoubleSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -287,7 +287,7 @@ public class MeterSdkTest {
|
|||
DoubleUpDownSumObserverSdk doubleObserver =
|
||||
testSdk
|
||||
.doubleUpDownSumObserverBuilder("testDoubleUpDownSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build();
|
||||
|
|
@ -296,7 +296,7 @@ public class MeterSdkTest {
|
|||
assertThat(
|
||||
testSdk
|
||||
.doubleUpDownSumObserverBuilder("testDoubleUpDownSumObserver")
|
||||
.setConstantLabels(ImmutableMap.of("sk1", "sv1"))
|
||||
.setConstantLabels(Labels.of("sk1", "sv1"))
|
||||
.setDescription("My very own counter")
|
||||
.setUnit("metric tonnes")
|
||||
.build())
|
||||
|
|
@ -333,67 +333,40 @@ public class MeterSdkTest {
|
|||
assertThat(testSdk.collectAll())
|
||||
.containsExactly(
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testLongCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
10))),
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.empty(), 10))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testDoubleCounter",
|
||||
"",
|
||||
"1",
|
||||
Type.MONOTONIC_DOUBLE,
|
||||
Collections.<String, String>emptyMap()),
|
||||
"testDoubleCounter", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
10.1))),
|
||||
DoublePoint.create(testClock.now(), testClock.now(), Labels.empty(), 10.1))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testLongValueRecorder",
|
||||
"",
|
||||
"1",
|
||||
Type.SUMMARY,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testLongValueRecorder", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
Labels.empty(),
|
||||
1,
|
||||
10,
|
||||
Arrays.asList(
|
||||
ValueAtPercentile.create(0, 10), ValueAtPercentile.create(100, 10))))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testDoubleValueRecorder",
|
||||
"",
|
||||
"1",
|
||||
Type.SUMMARY,
|
||||
Collections.<String, String>emptyMap()),
|
||||
Descriptor.create("testDoubleValueRecorder", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
Collections.<String, String>emptyMap(),
|
||||
Labels.empty(),
|
||||
1,
|
||||
10.1d,
|
||||
Arrays.asList(
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
|
@ -66,17 +66,18 @@ public class DoubleLastValueAggregatorTest {
|
|||
}
|
||||
|
||||
private static DoublePoint getPoint(Aggregator aggregator) {
|
||||
Point point = aggregator.toPoint(12345, 12358, Collections.singletonMap("key", "value"));
|
||||
Point point = aggregator.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNotNull();
|
||||
assertThat(point.getStartEpochNanos()).isEqualTo(12345);
|
||||
assertThat(point.getEpochNanos()).isEqualTo(12358);
|
||||
assertThat(point.getLabels()).containsExactly("key", "value");
|
||||
assertThat(point.getLabels().size()).isEqualTo(1);
|
||||
assertThat(point.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(point).isInstanceOf(DoublePoint.class);
|
||||
return (DoublePoint) point;
|
||||
}
|
||||
|
||||
private static void assertNullPoint(Aggregator aggregator) {
|
||||
Point point = aggregator.toPoint(12345, 12358, Collections.singletonMap("key", "value"));
|
||||
Point point = aggregator.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNull();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
|
@ -34,40 +34,22 @@ public class DoubleMinMaxSumCountTest {
|
|||
public void testRecordings() {
|
||||
Aggregator aggregator = DoubleMinMaxSumCount.getFactory().getAggregator();
|
||||
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap())).isNull();
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty())).isNull();
|
||||
|
||||
aggregator.recordDouble(100);
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
1,
|
||||
100,
|
||||
createPercentiles(100d, 100d)));
|
||||
SummaryPoint.create(0, 100, Labels.empty(), 1, 100, createPercentiles(100d, 100d)));
|
||||
|
||||
aggregator.recordDouble(50);
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
2,
|
||||
150,
|
||||
createPercentiles(50d, 100d)));
|
||||
SummaryPoint.create(0, 100, Labels.empty(), 2, 150, createPercentiles(50d, 100d)));
|
||||
|
||||
aggregator.recordDouble(-75);
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
3,
|
||||
75,
|
||||
createPercentiles(-75d, 100d)));
|
||||
SummaryPoint.create(0, 100, Labels.empty(), 3, 75, createPercentiles(-75d, 100d)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -78,17 +60,11 @@ public class DoubleMinMaxSumCountTest {
|
|||
Aggregator mergedToAggregator = DoubleMinMaxSumCount.getFactory().getAggregator();
|
||||
aggregator.mergeToAndReset(mergedToAggregator);
|
||||
|
||||
assertThat(mergedToAggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(mergedToAggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
1,
|
||||
100,
|
||||
createPercentiles(100d, 100d)));
|
||||
SummaryPoint.create(0, 100, Labels.empty(), 1, 100, createPercentiles(100d, 100d)));
|
||||
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap())).isNull();
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty())).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -134,12 +110,11 @@ public class DoubleMinMaxSumCountTest {
|
|||
// make sure everything gets merged when all the aggregation is done.
|
||||
aggregator.mergeToAndReset(summarizer);
|
||||
|
||||
SummaryPoint actual =
|
||||
(SummaryPoint) summarizer.toPoint(0, 100, Collections.<String, String>emptyMap());
|
||||
SummaryPoint actual = (SummaryPoint) summarizer.toPoint(0, 100, Labels.empty());
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual.getStartEpochNanos()).isEqualTo(0);
|
||||
assertThat(actual.getEpochNanos()).isEqualTo(100);
|
||||
assertThat(actual.getLabels()).isEqualTo(Collections.emptyMap());
|
||||
assertThat(actual.getLabels()).isEqualTo(Labels.empty());
|
||||
assertThat(actual.getCount()).isEqualTo(numberOfThreads * numberOfUpdates);
|
||||
assertThat(actual.getSum()).isWithin(0.001).of(102000d);
|
||||
List<ValueAtPercentile> percentileValues = actual.getPercentileValues();
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
|
@ -81,11 +81,12 @@ public class DoubleSumAggregatorTest {
|
|||
}
|
||||
|
||||
private static DoublePoint getPoint(Aggregator aggregator) {
|
||||
Point point = aggregator.toPoint(12345, 12358, Collections.singletonMap("key", "value"));
|
||||
Point point = aggregator.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNotNull();
|
||||
assertThat(point.getStartEpochNanos()).isEqualTo(12345);
|
||||
assertThat(point.getEpochNanos()).isEqualTo(12358);
|
||||
assertThat(point.getLabels()).containsExactly("key", "value");
|
||||
assertThat(point.getLabels().size()).isEqualTo(1);
|
||||
assertThat(point.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(point).isInstanceOf(DoublePoint.class);
|
||||
return (DoublePoint) point;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
|
@ -66,17 +66,18 @@ public class LongLastValueAggregatorTest {
|
|||
}
|
||||
|
||||
private static LongPoint getPoint(Aggregator aggregator) {
|
||||
Point point = aggregator.toPoint(12345, 12358, Collections.singletonMap("key", "value"));
|
||||
Point point = aggregator.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNotNull();
|
||||
assertThat(point.getStartEpochNanos()).isEqualTo(12345);
|
||||
assertThat(point.getEpochNanos()).isEqualTo(12358);
|
||||
assertThat(point.getLabels()).containsExactly("key", "value");
|
||||
assertThat(point.getLabels().size()).isEqualTo(1);
|
||||
assertThat(point.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(point).isInstanceOf(LongPoint.class);
|
||||
return (LongPoint) point;
|
||||
}
|
||||
|
||||
private static void assertNullPoint(Aggregator aggregator) {
|
||||
Point point = aggregator.toPoint(12345, 12358, Collections.singletonMap("key", "value"));
|
||||
Point point = aggregator.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNull();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
|
@ -34,40 +34,23 @@ public class LongMinMaxSumCountTest {
|
|||
public void testRecordings() {
|
||||
Aggregator aggregator = LongMinMaxSumCount.getFactory().getAggregator();
|
||||
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap())).isNull();
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty())).isNull();
|
||||
|
||||
aggregator.recordLong(100);
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
1,
|
||||
100,
|
||||
createPercentileValues(100L, 100L)));
|
||||
0, 100, Labels.empty(), 1, 100, createPercentileValues(100L, 100L)));
|
||||
|
||||
aggregator.recordLong(50);
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
2,
|
||||
150,
|
||||
createPercentileValues(50L, 100L)));
|
||||
SummaryPoint.create(0, 100, Labels.empty(), 2, 150, createPercentileValues(50L, 100L)));
|
||||
|
||||
aggregator.recordLong(-75);
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
3,
|
||||
75,
|
||||
createPercentileValues(-75L, 100L)));
|
||||
SummaryPoint.create(0, 100, Labels.empty(), 3, 75, createPercentileValues(-75L, 100L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -78,17 +61,12 @@ public class LongMinMaxSumCountTest {
|
|||
Aggregator mergedToAggregator = LongMinMaxSumCount.getFactory().getAggregator();
|
||||
aggregator.mergeToAndReset(mergedToAggregator);
|
||||
|
||||
assertThat(mergedToAggregator.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(mergedToAggregator.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
1,
|
||||
100,
|
||||
createPercentileValues(100L, 100L)));
|
||||
0, 100, Labels.empty(), 1, 100, createPercentileValues(100L, 100L)));
|
||||
|
||||
assertThat(aggregator.toPoint(0, 100, Collections.<String, String>emptyMap())).isNull();
|
||||
assertThat(aggregator.toPoint(0, 100, Labels.empty())).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -134,12 +112,12 @@ public class LongMinMaxSumCountTest {
|
|||
// make sure everything gets merged when all the aggregation is done.
|
||||
aggregator.mergeToAndReset(summarizer);
|
||||
|
||||
assertThat(summarizer.toPoint(0, 100, Collections.<String, String>emptyMap()))
|
||||
assertThat(summarizer.toPoint(0, 100, Labels.empty()))
|
||||
.isEqualTo(
|
||||
SummaryPoint.create(
|
||||
0,
|
||||
100,
|
||||
Collections.<String, String>emptyMap(),
|
||||
Labels.empty(),
|
||||
numberOfThreads * numberOfUpdates,
|
||||
101000,
|
||||
createPercentileValues(1L, 23L)));
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
|
@ -81,11 +81,12 @@ public class LongSumAggregatorTest {
|
|||
}
|
||||
|
||||
private static LongPoint getPoint(Aggregator aggregator) {
|
||||
Point point = aggregator.toPoint(12345, 12358, Collections.singletonMap("key", "value"));
|
||||
Point point = aggregator.toPoint(12345, 12358, Labels.of("key", "value"));
|
||||
assertThat(point).isNotNull();
|
||||
assertThat(point.getStartEpochNanos()).isEqualTo(12345);
|
||||
assertThat(point.getEpochNanos()).isEqualTo(12358);
|
||||
assertThat(point.getLabels()).containsExactly("key", "value");
|
||||
assertThat(point.getLabels().size()).isEqualTo(1);
|
||||
assertThat(point.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(point).isInstanceOf(LongPoint.class);
|
||||
return (LongPoint) point;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package io.opentelemetry.sdk.metrics.aggregator;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import java.util.Collections;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
|
@ -38,6 +38,6 @@ public class NoopAggregatorTest {
|
|||
aggregator.recordLong(12);
|
||||
aggregator.recordDouble(12.1);
|
||||
aggregator.mergeToAndReset(aggregator);
|
||||
assertThat(aggregator.toPoint(1, 2, Collections.<String, String>emptyMap())).isNull();
|
||||
assertThat(aggregator.toPoint(1, 2, Labels.empty())).isNull();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ package io.opentelemetry.sdk.metrics.data;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import java.util.Collections;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
|
@ -41,41 +41,41 @@ public class MetricDataDescriptorTest {
|
|||
@Test
|
||||
public void testGet() {
|
||||
Descriptor descriptor =
|
||||
Descriptor.create(
|
||||
METRIC_NAME, DESCRIPTION, UNIT, TYPE, Collections.singletonMap(KEY, VALUE));
|
||||
Descriptor.create(METRIC_NAME, DESCRIPTION, UNIT, TYPE, Labels.of(KEY, VALUE));
|
||||
assertThat(descriptor.getName()).isEqualTo(METRIC_NAME);
|
||||
assertThat(descriptor.getDescription()).isEqualTo(DESCRIPTION);
|
||||
assertThat(descriptor.getUnit()).isEqualTo(UNIT);
|
||||
assertThat(descriptor.getType()).isEqualTo(TYPE);
|
||||
assertThat(descriptor.getConstantLabels()).containsExactly(KEY, VALUE);
|
||||
assertThat(descriptor.getConstantLabels().size()).isEqualTo(1);
|
||||
assertThat(descriptor.getConstantLabels().get(KEY)).isEqualTo(VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_NullName() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("name");
|
||||
Descriptor.create(null, DESCRIPTION, UNIT, TYPE, Collections.singletonMap(KEY, VALUE));
|
||||
Descriptor.create(null, DESCRIPTION, UNIT, TYPE, Labels.of(KEY, VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_NullDescription() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("description");
|
||||
Descriptor.create(METRIC_NAME, null, UNIT, TYPE, Collections.singletonMap(KEY, VALUE));
|
||||
Descriptor.create(METRIC_NAME, null, UNIT, TYPE, Labels.of(KEY, VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_NullUnit() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("unit");
|
||||
Descriptor.create(METRIC_NAME, DESCRIPTION, null, TYPE, Collections.singletonMap(KEY, VALUE));
|
||||
Descriptor.create(METRIC_NAME, DESCRIPTION, null, TYPE, Labels.of(KEY, VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create_NullType() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("type");
|
||||
Descriptor.create(METRIC_NAME, DESCRIPTION, UNIT, null, Collections.singletonMap(KEY, VALUE));
|
||||
Descriptor.create(METRIC_NAME, DESCRIPTION, UNIT, null, Labels.of(KEY, VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.opentelemetry.sdk.metrics.data;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
|
|
@ -47,14 +48,14 @@ public class MetricDataTest {
|
|||
"metric_description",
|
||||
"ms",
|
||||
Descriptor.Type.MONOTONIC_LONG,
|
||||
Collections.singletonMap("key_const", "value_const"));
|
||||
Labels.of("key_const", "value_const"));
|
||||
private static final Descriptor DOUBLE_METRIC_DESCRIPTOR =
|
||||
Descriptor.create(
|
||||
"metric_name",
|
||||
"metric_description",
|
||||
"ms",
|
||||
Descriptor.Type.NON_MONOTONIC_DOUBLE,
|
||||
Collections.singletonMap("key_const", "value_const"));
|
||||
Labels.of("key_const", "value_const"));
|
||||
private static final long START_EPOCH_NANOS = TimeUnit.MILLISECONDS.toNanos(1000);
|
||||
private static final long EPOCH_NANOS = TimeUnit.MILLISECONDS.toNanos(2000);
|
||||
private static final long LONG_VALUE = 10;
|
||||
|
|
@ -65,15 +66,14 @@ public class MetricDataTest {
|
|||
ValueAtPercentile.create(100.0, DOUBLE_VALUE);
|
||||
private static final LongPoint LONG_POINT =
|
||||
MetricData.LongPoint.create(
|
||||
START_EPOCH_NANOS, EPOCH_NANOS, Collections.singletonMap("key", "value"), LONG_VALUE);
|
||||
START_EPOCH_NANOS, EPOCH_NANOS, Labels.of("key", "value"), LONG_VALUE);
|
||||
private static final DoublePoint DOUBLE_POINT =
|
||||
DoublePoint.create(
|
||||
START_EPOCH_NANOS, EPOCH_NANOS, Collections.singletonMap("key", "value"), DOUBLE_VALUE);
|
||||
DoublePoint.create(START_EPOCH_NANOS, EPOCH_NANOS, Labels.of("key", "value"), DOUBLE_VALUE);
|
||||
private static final SummaryPoint SUMMARY_POINT =
|
||||
SummaryPoint.create(
|
||||
START_EPOCH_NANOS,
|
||||
EPOCH_NANOS,
|
||||
Collections.singletonMap("key", "value"),
|
||||
Labels.of("key", "value"),
|
||||
LONG_VALUE,
|
||||
DOUBLE_VALUE,
|
||||
Arrays.asList(
|
||||
|
|
@ -140,7 +140,8 @@ public class MetricDataTest {
|
|||
public void metricData_LongPoints() {
|
||||
assertThat(LONG_POINT.getStartEpochNanos()).isEqualTo(START_EPOCH_NANOS);
|
||||
assertThat(LONG_POINT.getEpochNanos()).isEqualTo(EPOCH_NANOS);
|
||||
assertThat(LONG_POINT.getLabels()).containsExactly("key", "value");
|
||||
assertThat(LONG_POINT.getLabels().size()).isEqualTo(1);
|
||||
assertThat(LONG_POINT.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(LONG_POINT.getValue()).isEqualTo(LONG_VALUE);
|
||||
MetricData metricData =
|
||||
MetricData.create(
|
||||
|
|
@ -155,7 +156,8 @@ public class MetricDataTest {
|
|||
public void metricData_SummaryPoints() {
|
||||
assertThat(SUMMARY_POINT.getStartEpochNanos()).isEqualTo(START_EPOCH_NANOS);
|
||||
assertThat(SUMMARY_POINT.getEpochNanos()).isEqualTo(EPOCH_NANOS);
|
||||
assertThat(SUMMARY_POINT.getLabels()).containsExactly("key", "value");
|
||||
assertThat(SUMMARY_POINT.getLabels().size()).isEqualTo(1);
|
||||
assertThat(SUMMARY_POINT.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(SUMMARY_POINT.getCount()).isEqualTo(LONG_VALUE);
|
||||
assertThat(SUMMARY_POINT.getSum()).isEqualTo(DOUBLE_VALUE);
|
||||
assertThat(SUMMARY_POINT.getPercentileValues())
|
||||
|
|
@ -173,7 +175,8 @@ public class MetricDataTest {
|
|||
public void metricData_DoublePoints() {
|
||||
assertThat(DOUBLE_POINT.getStartEpochNanos()).isEqualTo(START_EPOCH_NANOS);
|
||||
assertThat(DOUBLE_POINT.getEpochNanos()).isEqualTo(EPOCH_NANOS);
|
||||
assertThat(DOUBLE_POINT.getLabels()).containsExactly("key", "value");
|
||||
assertThat(DOUBLE_POINT.getLabels().size()).isEqualTo(1);
|
||||
assertThat(DOUBLE_POINT.getLabels().get("key")).isEqualTo("value");
|
||||
assertThat(DOUBLE_POINT.getValue()).isEqualTo(DOUBLE_VALUE);
|
||||
MetricData metricData =
|
||||
MetricData.create(
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package io.opentelemetry.sdk.metrics.export;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.common.export.ConfigBuilderTest.ConfigTester;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
|
|
@ -45,15 +46,10 @@ import org.mockito.MockitoAnnotations;
|
|||
public class IntervalMetricReaderTest {
|
||||
private static final MetricData.Descriptor METRIC_DESCRIPTOR =
|
||||
MetricData.Descriptor.create(
|
||||
"my metric",
|
||||
"my metric description",
|
||||
"us",
|
||||
Type.MONOTONIC_LONG,
|
||||
Collections.<String, String>emptyMap());
|
||||
"my metric", "my metric description", "us", Type.MONOTONIC_LONG, Labels.empty());
|
||||
|
||||
private static final List<Point> LONG_POINT_LIST =
|
||||
Collections.<Point>singletonList(
|
||||
LongPoint.create(1000, 3000, Collections.<String, String>emptyMap(), 1234567));
|
||||
Collections.<Point>singletonList(LongPoint.create(1000, 3000, Labels.empty(), 1234567));
|
||||
|
||||
private static final MetricData METRIC_DATA =
|
||||
MetricData.create(
|
||||
|
|
|
|||
Loading…
Reference in New Issue