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.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
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
|
||||
* be used.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract InstrumentType getInstrumentType();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -28,10 +28,7 @@ class ViewRegistryTest {
|
|||
ViewRegistry viewRegistry =
|
||||
ViewRegistry.builder()
|
||||
.addView(
|
||||
InstrumentSelector.builder()
|
||||
.setInstrumentType(InstrumentType.COUNTER)
|
||||
.setInstrumentNameRegex(".*")
|
||||
.build(),
|
||||
InstrumentSelector.builder().setInstrumentType(InstrumentType.COUNTER).build(),
|
||||
view)
|
||||
.build();
|
||||
assertThat(
|
||||
|
|
@ -59,12 +56,7 @@ class ViewRegistryTest {
|
|||
|
||||
ViewRegistry viewRegistry =
|
||||
ViewRegistry.builder()
|
||||
.addView(
|
||||
InstrumentSelector.builder()
|
||||
.setInstrumentType(InstrumentType.COUNTER)
|
||||
.setInstrumentNameRegex("overridden")
|
||||
.build(),
|
||||
view)
|
||||
.addView(InstrumentSelector.builder().setInstrumentName("overridden").build(), view)
|
||||
.build();
|
||||
assertThat(
|
||||
viewRegistry.findViews(
|
||||
|
|
@ -93,17 +85,8 @@ class ViewRegistryTest {
|
|||
ViewRegistry viewRegistry =
|
||||
ViewRegistry.builder()
|
||||
.addView(
|
||||
InstrumentSelector.builder()
|
||||
.setInstrumentType(InstrumentType.COUNTER)
|
||||
.setInstrumentNameRegex("overridden")
|
||||
.build(),
|
||||
view2)
|
||||
.addView(
|
||||
InstrumentSelector.builder()
|
||||
.setInstrumentType(InstrumentType.COUNTER)
|
||||
.setInstrumentNameRegex(".*")
|
||||
.build(),
|
||||
view1)
|
||||
InstrumentSelector.builder().setInstrumentNameRegex("overridden").build(), view2)
|
||||
.addView(InstrumentSelector.builder().setInstrumentNameRegex(".*").build(), view1)
|
||||
.build();
|
||||
|
||||
assertThat(
|
||||
|
|
@ -131,10 +114,7 @@ class ViewRegistryTest {
|
|||
ViewRegistry viewRegistry =
|
||||
ViewRegistry.builder()
|
||||
.addView(
|
||||
InstrumentSelector.builder()
|
||||
.setInstrumentNameRegex("overrid(es|den)")
|
||||
.setInstrumentType(InstrumentType.COUNTER)
|
||||
.build(),
|
||||
InstrumentSelector.builder().setInstrumentNameRegex("overrid(es|den)").build(),
|
||||
view)
|
||||
.build();
|
||||
|
||||
|
|
@ -149,7 +129,7 @@ class ViewRegistryTest {
|
|||
assertThat(
|
||||
viewRegistry.findViews(
|
||||
InstrumentDescriptor.create(
|
||||
"overrides", "", "", InstrumentType.COUNTER, InstrumentValueType.LONG),
|
||||
"overrides", "", "", InstrumentType.UP_DOWN_COUNTER, InstrumentValueType.LONG),
|
||||
INSTRUMENTATION_LIBRARY_INFO))
|
||||
.hasSize(1)
|
||||
.element(0)
|
||||
|
|
@ -165,6 +145,48 @@ class ViewRegistryTest {
|
|||
.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
|
||||
void defaults() {
|
||||
ViewRegistry viewRegistry = ViewRegistry.builder().build();
|
||||
|
|
|
|||
Loading…
Reference in New Issue