Make InstrumentSelect#getInstrumentType() nullable (#3893)
This commit is contained in:
parent
300c4963d8
commit
bc4f8f75a2
|
|
@ -11,6 +11,7 @@ import io.opentelemetry.sdk.metrics.internal.view.StringPredicates;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,6 +37,7 @@ public abstract class InstrumentSelector {
|
||||||
* Returns {@link InstrumentType} that should be selected. If null, then this specifier will not
|
* Returns {@link InstrumentType} that should be selected. If null, then this specifier will not
|
||||||
* be used.
|
* be used.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public abstract InstrumentType getInstrumentType();
|
public abstract InstrumentType getInstrumentType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,7 @@ class ViewRegistryTest {
|
||||||
ViewRegistry viewRegistry =
|
ViewRegistry viewRegistry =
|
||||||
ViewRegistry.builder()
|
ViewRegistry.builder()
|
||||||
.addView(
|
.addView(
|
||||||
InstrumentSelector.builder()
|
InstrumentSelector.builder().setInstrumentType(InstrumentType.COUNTER).build(),
|
||||||
.setInstrumentType(InstrumentType.COUNTER)
|
|
||||||
.setInstrumentNameRegex(".*")
|
|
||||||
.build(),
|
|
||||||
view)
|
view)
|
||||||
.build();
|
.build();
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
@ -59,12 +56,7 @@ class ViewRegistryTest {
|
||||||
|
|
||||||
ViewRegistry viewRegistry =
|
ViewRegistry viewRegistry =
|
||||||
ViewRegistry.builder()
|
ViewRegistry.builder()
|
||||||
.addView(
|
.addView(InstrumentSelector.builder().setInstrumentName("overridden").build(), view)
|
||||||
InstrumentSelector.builder()
|
|
||||||
.setInstrumentType(InstrumentType.COUNTER)
|
|
||||||
.setInstrumentNameRegex("overridden")
|
|
||||||
.build(),
|
|
||||||
view)
|
|
||||||
.build();
|
.build();
|
||||||
assertThat(
|
assertThat(
|
||||||
viewRegistry.findViews(
|
viewRegistry.findViews(
|
||||||
|
|
@ -93,17 +85,8 @@ class ViewRegistryTest {
|
||||||
ViewRegistry viewRegistry =
|
ViewRegistry viewRegistry =
|
||||||
ViewRegistry.builder()
|
ViewRegistry.builder()
|
||||||
.addView(
|
.addView(
|
||||||
InstrumentSelector.builder()
|
InstrumentSelector.builder().setInstrumentNameRegex("overridden").build(), view2)
|
||||||
.setInstrumentType(InstrumentType.COUNTER)
|
.addView(InstrumentSelector.builder().setInstrumentNameRegex(".*").build(), view1)
|
||||||
.setInstrumentNameRegex("overridden")
|
|
||||||
.build(),
|
|
||||||
view2)
|
|
||||||
.addView(
|
|
||||||
InstrumentSelector.builder()
|
|
||||||
.setInstrumentType(InstrumentType.COUNTER)
|
|
||||||
.setInstrumentNameRegex(".*")
|
|
||||||
.build(),
|
|
||||||
view1)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
@ -131,10 +114,7 @@ class ViewRegistryTest {
|
||||||
ViewRegistry viewRegistry =
|
ViewRegistry viewRegistry =
|
||||||
ViewRegistry.builder()
|
ViewRegistry.builder()
|
||||||
.addView(
|
.addView(
|
||||||
InstrumentSelector.builder()
|
InstrumentSelector.builder().setInstrumentNameRegex("overrid(es|den)").build(),
|
||||||
.setInstrumentNameRegex("overrid(es|den)")
|
|
||||||
.setInstrumentType(InstrumentType.COUNTER)
|
|
||||||
.build(),
|
|
||||||
view)
|
view)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
@ -149,7 +129,7 @@ class ViewRegistryTest {
|
||||||
assertThat(
|
assertThat(
|
||||||
viewRegistry.findViews(
|
viewRegistry.findViews(
|
||||||
InstrumentDescriptor.create(
|
InstrumentDescriptor.create(
|
||||||
"overrides", "", "", InstrumentType.COUNTER, InstrumentValueType.LONG),
|
"overrides", "", "", InstrumentType.UP_DOWN_COUNTER, InstrumentValueType.LONG),
|
||||||
INSTRUMENTATION_LIBRARY_INFO))
|
INSTRUMENTATION_LIBRARY_INFO))
|
||||||
.hasSize(1)
|
.hasSize(1)
|
||||||
.element(0)
|
.element(0)
|
||||||
|
|
@ -165,6 +145,48 @@ class ViewRegistryTest {
|
||||||
.isSameAs(ViewRegistry.DEFAULT_VIEW);
|
.isSameAs(ViewRegistry.DEFAULT_VIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void selection_typeAndName() {
|
||||||
|
View view = View.builder().setAggregation(Aggregation.lastValue()).build();
|
||||||
|
|
||||||
|
ViewRegistry viewRegistry =
|
||||||
|
ViewRegistry.builder()
|
||||||
|
.addView(
|
||||||
|
InstrumentSelector.builder()
|
||||||
|
.setInstrumentType(InstrumentType.COUNTER)
|
||||||
|
.setInstrumentName("overrides")
|
||||||
|
.build(),
|
||||||
|
view)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertThat(
|
||||||
|
viewRegistry.findViews(
|
||||||
|
InstrumentDescriptor.create(
|
||||||
|
"overrides", "", "", InstrumentType.COUNTER, InstrumentValueType.LONG),
|
||||||
|
INSTRUMENTATION_LIBRARY_INFO))
|
||||||
|
.hasSize(1)
|
||||||
|
.element(0)
|
||||||
|
.isEqualTo(view);
|
||||||
|
// this one hasn't been configured, so it gets the default still..
|
||||||
|
assertThat(
|
||||||
|
viewRegistry.findViews(
|
||||||
|
InstrumentDescriptor.create(
|
||||||
|
"overrides", "", "", InstrumentType.UP_DOWN_COUNTER, InstrumentValueType.LONG),
|
||||||
|
INSTRUMENTATION_LIBRARY_INFO))
|
||||||
|
.hasSize(1)
|
||||||
|
.element(0)
|
||||||
|
.isEqualTo(ViewRegistry.DEFAULT_VIEW);
|
||||||
|
// this one hasn't been configured, so it gets the default still..
|
||||||
|
assertThat(
|
||||||
|
viewRegistry.findViews(
|
||||||
|
InstrumentDescriptor.create(
|
||||||
|
"default", "", "", InstrumentType.COUNTER, InstrumentValueType.LONG),
|
||||||
|
INSTRUMENTATION_LIBRARY_INFO))
|
||||||
|
.hasSize(1)
|
||||||
|
.element(0)
|
||||||
|
.isEqualTo(ViewRegistry.DEFAULT_VIEW);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void defaults() {
|
void defaults() {
|
||||||
ViewRegistry viewRegistry = ViewRegistry.builder().build();
|
ViewRegistry viewRegistry = ViewRegistry.builder().build();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue