Metrics SDK odds and ends (#4273)
* Metrics SDK odds and ends * Make InstrumentSelectorBuilder contructor package private * Fix build * Improve documentation for SdkMeterProviderBuilder defaults
This commit is contained in:
parent
211db4478e
commit
59697eedc0
|
|
@ -61,10 +61,10 @@ public final class SdkMeterProvider implements MeterProvider, Closeable {
|
|||
Clock clock,
|
||||
Resource resource,
|
||||
ViewRegistry viewRegistry,
|
||||
ExemplarFilter exemplarSampler,
|
||||
ExemplarFilter exemplarFilter,
|
||||
long minimumCollectionIntervalNanos) {
|
||||
this.sharedState =
|
||||
MeterProviderSharedState.create(clock, resource, viewRegistry, exemplarSampler);
|
||||
MeterProviderSharedState.create(clock, resource, viewRegistry, exemplarFilter);
|
||||
this.registry =
|
||||
new ComponentRegistry<>(
|
||||
instrumentationLibraryInfo -> new SdkMeter(sharedState, instrumentationLibraryInfo));
|
||||
|
|
|
|||
|
|
@ -25,13 +25,27 @@ import java.util.concurrent.TimeUnit;
|
|||
/** Builder class for the {@link SdkMeterProvider}. */
|
||||
public final class SdkMeterProviderBuilder {
|
||||
|
||||
/**
|
||||
* By default, the exemplar filter is set to sample with traces.
|
||||
*
|
||||
* @see #setExemplarFilter(ExemplarFilter)
|
||||
*/
|
||||
private static final ExemplarFilter DEFAULT_EXEMPLAR_FILTER = ExemplarFilter.sampleWithTraces();
|
||||
|
||||
/**
|
||||
* By default, the minimum collection interval is 100ns.
|
||||
*
|
||||
* @see #setMinimumCollectionInterval(Duration)
|
||||
*/
|
||||
private static final long DEFAULT_MIN_COLLECTION_INTERVAL_NANOS =
|
||||
TimeUnit.MILLISECONDS.toNanos(100);
|
||||
|
||||
private Clock clock = Clock.getDefault();
|
||||
private Resource resource = Resource.getDefault();
|
||||
private final ViewRegistryBuilder viewRegistryBuilder = ViewRegistry.builder();
|
||||
private final List<MetricReaderFactory> metricReaders = new ArrayList<>();
|
||||
// Default the sampling strategy.
|
||||
private ExemplarFilter exemplarFilter = ExemplarFilter.sampleWithTraces();
|
||||
private long minimumCollectionIntervalNanos = TimeUnit.MILLISECONDS.toNanos(100);
|
||||
private ExemplarFilter exemplarFilter = DEFAULT_EXEMPLAR_FILTER;
|
||||
private long minimumCollectionIntervalNanos = DEFAULT_MIN_COLLECTION_INTERVAL_NANOS;
|
||||
|
||||
SdkMeterProviderBuilder() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public interface ExemplarData {
|
|||
/**
|
||||
* The set of key/value pairs that were filtered out by the aggregator, but recorded alongside the
|
||||
* original measurement. Only key/value pairs that were filtered out by the aggregator should be
|
||||
* included
|
||||
* included.
|
||||
*/
|
||||
Attributes getFilteredAttributes();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import java.util.function.Supplier;
|
|||
/**
|
||||
* A Reservoir sampler with fixed size that stores the given number of exemplars.
|
||||
*
|
||||
* <p>This implementation uses a un-unweighted/naive algorithm for sampler where the probability of
|
||||
* <p>This implementation uses an un-unweighted/naive algorithm for sampler where the probability of
|
||||
* sampling decrease as the number of observations continue. The collectAndReset method resets the
|
||||
* count of observations, making the probability of sampling effectively 1.0.
|
||||
*
|
||||
|
|
@ -33,7 +33,7 @@ final class FixedSizeExemplarReservoir extends AbstractFixedSizeExemplarReservoi
|
|||
* @param size The number of exemplars to preserve.
|
||||
* @param randomSupplier The random number generator to use for sampling.
|
||||
*/
|
||||
public FixedSizeExemplarReservoir(Clock clock, int size, Supplier<Random> randomSupplier) {
|
||||
FixedSizeExemplarReservoir(Clock clock, int size, Supplier<Random> randomSupplier) {
|
||||
super(clock, size);
|
||||
this.randomSupplier = randomSupplier;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ public abstract class InstrumentDescriptor {
|
|||
return new AutoValue_InstrumentDescriptor(name, description, unit, type, valueType);
|
||||
}
|
||||
|
||||
InstrumentDescriptor() {}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ public abstract class MetricDescriptor {
|
|||
return new AutoValue_MetricDescriptor(name, description, view, instrument);
|
||||
}
|
||||
|
||||
MetricDescriptor() {}
|
||||
|
||||
/**
|
||||
* The name of the descriptor, equal to {@link View#getName()} if not null, else {@link
|
||||
* InstrumentDescriptor#getName()}.
|
||||
|
|
|
|||
|
|
@ -21,6 +21,15 @@ import javax.annotation.concurrent.Immutable;
|
|||
@AutoValue
|
||||
@Immutable
|
||||
public abstract class CollectionInfo {
|
||||
|
||||
/** Construct a new collection info object storing information for collection against a reader. */
|
||||
public static CollectionInfo create(
|
||||
CollectionHandle handle, Set<CollectionHandle> allCollectors, MetricReader reader) {
|
||||
return new AutoValue_CollectionInfo(handle, allCollectors, reader);
|
||||
}
|
||||
|
||||
CollectionInfo() {}
|
||||
|
||||
/** The current collection. */
|
||||
public abstract CollectionHandle getCollector();
|
||||
/** The set of all possible collectors. */
|
||||
|
|
@ -33,10 +42,4 @@ public abstract class CollectionInfo {
|
|||
public final AggregationTemporality getPreferredAggregation() {
|
||||
return getReader().getPreferredTemporality();
|
||||
}
|
||||
|
||||
/** Construct a new collection info object storing information for collection against a reader. */
|
||||
public static CollectionInfo create(
|
||||
CollectionHandle handle, Set<CollectionHandle> allCollectors, MetricReader reader) {
|
||||
return new AutoValue_CollectionInfo(handle, allCollectors, reader);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ public abstract class MeterProviderSharedState {
|
|||
clock, resource, viewRegistry, clock.now(), exemplarFilter);
|
||||
}
|
||||
|
||||
MeterProviderSharedState() {}
|
||||
|
||||
/** Returns the clock used for measurements. */
|
||||
public abstract Clock getClock();
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ public abstract class MeterSharedState {
|
|||
return new AutoValue_MeterSharedState(instrumentationScopeInfo, new MetricStorageRegistry());
|
||||
}
|
||||
|
||||
MeterSharedState() {}
|
||||
|
||||
// only visible for testing.
|
||||
/** Returns the {@link InstrumentationScopeInfo} for this {@code Meter}. */
|
||||
public abstract InstrumentationScopeInfo getInstrumentationScopeInfo();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import javax.annotation.concurrent.Immutable;
|
|||
@Immutable
|
||||
public abstract class ImmutableView implements View {
|
||||
|
||||
ImmutableView() {}
|
||||
|
||||
/** Returns the {@link AttributesProcessor} for the {@link View}. */
|
||||
public static AttributesProcessor getAttributesProcessor(View view) {
|
||||
if (view instanceof ImmutableView) {
|
||||
|
|
|
|||
|
|
@ -19,12 +19,15 @@ import javax.annotation.concurrent.Immutable;
|
|||
@AutoValue
|
||||
@Immutable
|
||||
abstract class RegisteredView {
|
||||
/** Instrument fitler for applying this view. */
|
||||
abstract InstrumentSelector getInstrumentSelector();
|
||||
/** The view to apply. */
|
||||
abstract View getView();
|
||||
|
||||
static RegisteredView create(InstrumentSelector selector, View view) {
|
||||
return new AutoValue_RegisteredView(selector, view);
|
||||
}
|
||||
|
||||
RegisteredView() {}
|
||||
|
||||
/** Instrument fitler for applying this view. */
|
||||
abstract InstrumentSelector getInstrumentSelector();
|
||||
/** The view to apply. */
|
||||
abstract View getView();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public abstract class InstrumentSelector {
|
|||
meterSchemaUrlFilter);
|
||||
}
|
||||
|
||||
InstrumentSelector() {}
|
||||
|
||||
/**
|
||||
* Returns {@link InstrumentType} that should be selected. If null, then this specifier will not
|
||||
* be used.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ public final class InstrumentSelectorBuilder {
|
|||
private Predicate<String> meterVersionFilter = StringPredicates.ALL;
|
||||
private Predicate<String> meterSchemaUrlFilter = StringPredicates.ALL;
|
||||
|
||||
InstrumentSelectorBuilder() {}
|
||||
|
||||
/** Sets a specifier for {@link InstrumentType}. */
|
||||
public InstrumentSelectorBuilder setType(InstrumentType instrumentType) {
|
||||
requireNonNull(instrumentType, "instrumentType");
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import java.util.function.Predicate;
|
|||
public interface ViewBuilder {
|
||||
|
||||
/**
|
||||
* sets the name of the resulting metric.
|
||||
* Sets the name of the resulting metric.
|
||||
*
|
||||
* @param name metric name or {@code null} if the underlying instrument name should be used.
|
||||
* @return this Builder.
|
||||
|
|
@ -19,7 +19,7 @@ public interface ViewBuilder {
|
|||
ViewBuilder setName(String name);
|
||||
|
||||
/**
|
||||
* sets the name of the resulting metric.
|
||||
* Sets the description of the resulting metric.
|
||||
*
|
||||
* @param description metric description or {@code null} if the underlying instrument description
|
||||
* should be used.
|
||||
|
|
@ -28,7 +28,7 @@ public interface ViewBuilder {
|
|||
ViewBuilder setDescription(String description);
|
||||
|
||||
/**
|
||||
* sets {@link Aggregation}.
|
||||
* Sets {@link Aggregation}.
|
||||
*
|
||||
* @param aggregation aggregation to use.
|
||||
* @return this Builder.
|
||||
|
|
|
|||
Loading…
Reference in New Issue