Rename accumulator to processor to match Go (#2255)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
56235a1114
commit
feedef2366
|
|
@ -18,15 +18,15 @@ abstract class AbstractAsynchronousInstrument<T extends AsynchronousInstrument.R
|
||||||
extends AbstractInstrument implements AsynchronousInstrument<T> {
|
extends AbstractInstrument implements AsynchronousInstrument<T> {
|
||||||
@Nullable private final Callback<T> metricUpdater;
|
@Nullable private final Callback<T> metricUpdater;
|
||||||
private final ReentrantLock collectLock = new ReentrantLock();
|
private final ReentrantLock collectLock = new ReentrantLock();
|
||||||
private final InstrumentAccumulator instrumentAccumulator;
|
private final InstrumentProcessor instrumentProcessor;
|
||||||
|
|
||||||
AbstractAsynchronousInstrument(
|
AbstractAsynchronousInstrument(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<T> metricUpdater) {
|
@Nullable Callback<T> metricUpdater) {
|
||||||
super(descriptor);
|
super(descriptor);
|
||||||
this.metricUpdater = metricUpdater;
|
this.metricUpdater = metricUpdater;
|
||||||
this.instrumentAccumulator = instrumentAccumulator;
|
this.instrumentProcessor = instrumentProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -36,14 +36,14 @@ abstract class AbstractAsynchronousInstrument<T extends AsynchronousInstrument.R
|
||||||
}
|
}
|
||||||
collectLock.lock();
|
collectLock.lock();
|
||||||
try {
|
try {
|
||||||
metricUpdater.update(newResult(instrumentAccumulator));
|
metricUpdater.update(newResult(instrumentProcessor));
|
||||||
return instrumentAccumulator.completeCollectionCycle();
|
return instrumentProcessor.completeCollectionCycle();
|
||||||
} finally {
|
} finally {
|
||||||
collectLock.unlock();
|
collectLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract T newResult(InstrumentAccumulator instrumentAccumulator);
|
abstract T newResult(InstrumentProcessor instrumentProcessor);
|
||||||
|
|
||||||
abstract static class Builder<B extends AbstractInstrument.Builder<?>>
|
abstract static class Builder<B extends AbstractInstrument.Builder<?>>
|
||||||
extends AbstractInstrument.Builder<B> {
|
extends AbstractInstrument.Builder<B> {
|
||||||
|
|
@ -60,29 +60,29 @@ abstract class AbstractAsynchronousInstrument<T extends AsynchronousInstrument.R
|
||||||
extends AbstractAsynchronousInstrument<LongResult> {
|
extends AbstractAsynchronousInstrument<LongResult> {
|
||||||
AbstractLongAsynchronousInstrument(
|
AbstractLongAsynchronousInstrument(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<LongResult> metricUpdater) {
|
@Nullable Callback<LongResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
LongResultSdk newResult(InstrumentAccumulator instrumentAccumulator) {
|
LongResultSdk newResult(InstrumentProcessor instrumentProcessor) {
|
||||||
return new LongResultSdk(instrumentAccumulator);
|
return new LongResultSdk(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class LongResultSdk implements LongResult {
|
private static final class LongResultSdk implements LongResult {
|
||||||
|
|
||||||
private final InstrumentAccumulator instrumentAccumulator;
|
private final InstrumentProcessor instrumentProcessor;
|
||||||
|
|
||||||
private LongResultSdk(InstrumentAccumulator instrumentAccumulator) {
|
private LongResultSdk(InstrumentProcessor instrumentProcessor) {
|
||||||
this.instrumentAccumulator = instrumentAccumulator;
|
this.instrumentProcessor = instrumentProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void observe(long sum, Labels labels) {
|
public void observe(long sum, Labels labels) {
|
||||||
Aggregator aggregator = instrumentAccumulator.getAggregator();
|
Aggregator aggregator = instrumentProcessor.getAggregator();
|
||||||
aggregator.recordLong(sum);
|
aggregator.recordLong(sum);
|
||||||
instrumentAccumulator.batch(labels, aggregator, /* mappedAggregator= */ false);
|
instrumentProcessor.batch(labels, aggregator, /* mappedAggregator= */ false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,29 +91,29 @@ abstract class AbstractAsynchronousInstrument<T extends AsynchronousInstrument.R
|
||||||
extends AbstractAsynchronousInstrument<DoubleResult> {
|
extends AbstractAsynchronousInstrument<DoubleResult> {
|
||||||
AbstractDoubleAsynchronousInstrument(
|
AbstractDoubleAsynchronousInstrument(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<DoubleResult> metricUpdater) {
|
@Nullable Callback<DoubleResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
DoubleResultSdk newResult(InstrumentAccumulator instrumentAccumulator) {
|
DoubleResultSdk newResult(InstrumentProcessor instrumentProcessor) {
|
||||||
return new DoubleResultSdk(instrumentAccumulator);
|
return new DoubleResultSdk(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class DoubleResultSdk implements DoubleResult {
|
private static final class DoubleResultSdk implements DoubleResult {
|
||||||
|
|
||||||
private final InstrumentAccumulator instrumentAccumulator;
|
private final InstrumentProcessor instrumentProcessor;
|
||||||
|
|
||||||
private DoubleResultSdk(InstrumentAccumulator instrumentAccumulator) {
|
private DoubleResultSdk(InstrumentProcessor instrumentProcessor) {
|
||||||
this.instrumentAccumulator = instrumentAccumulator;
|
this.instrumentProcessor = instrumentProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void observe(double sum, Labels labels) {
|
public void observe(double sum, Labels labels) {
|
||||||
Aggregator aggregator = instrumentAccumulator.getAggregator();
|
Aggregator aggregator = instrumentProcessor.getAggregator();
|
||||||
aggregator.recordDouble(sum);
|
aggregator.recordDouble(sum);
|
||||||
instrumentAccumulator.batch(labels, aggregator, /* mappedAggregator= */ false);
|
instrumentProcessor.batch(labels, aggregator, /* mappedAggregator= */ false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ abstract class AbstractInstrument implements Instrument {
|
||||||
return meterSharedState.getInstrumentRegistry().register(instrument);
|
return meterSharedState.getInstrumentRegistry().register(instrument);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected InstrumentAccumulator getBatcher(InstrumentDescriptor descriptor) {
|
protected InstrumentProcessor getBatcher(InstrumentDescriptor descriptor) {
|
||||||
return meterSdk.createBatcher(descriptor, meterProviderSharedState, meterSharedState);
|
return meterSdk.createBatcher(descriptor, meterProviderSharedState, meterSharedState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@ abstract class AbstractSynchronousInstrument<B extends AbstractBoundInstrument>
|
||||||
extends AbstractInstrument {
|
extends AbstractInstrument {
|
||||||
private final ConcurrentHashMap<Labels, B> boundLabels;
|
private final ConcurrentHashMap<Labels, B> boundLabels;
|
||||||
private final ReentrantLock collectLock;
|
private final ReentrantLock collectLock;
|
||||||
private final InstrumentAccumulator instrumentAccumulator;
|
private final InstrumentProcessor instrumentProcessor;
|
||||||
|
|
||||||
AbstractSynchronousInstrument(
|
AbstractSynchronousInstrument(
|
||||||
InstrumentDescriptor descriptor, InstrumentAccumulator instrumentAccumulator) {
|
InstrumentDescriptor descriptor, InstrumentProcessor instrumentProcessor) {
|
||||||
super(descriptor);
|
super(descriptor);
|
||||||
boundLabels = new ConcurrentHashMap<>();
|
boundLabels = new ConcurrentHashMap<>();
|
||||||
collectLock = new ReentrantLock();
|
collectLock = new ReentrantLock();
|
||||||
this.instrumentAccumulator = instrumentAccumulator;
|
this.instrumentProcessor = instrumentProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public B bind(Labels labels) {
|
public B bind(Labels labels) {
|
||||||
|
|
@ -36,7 +36,7 @@ abstract class AbstractSynchronousInstrument<B extends AbstractBoundInstrument>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Missing entry or no longer mapped, try to add a new entry.
|
// Missing entry or no longer mapped, try to add a new entry.
|
||||||
binding = newBinding(instrumentAccumulator);
|
binding = newBinding(instrumentProcessor);
|
||||||
while (true) {
|
while (true) {
|
||||||
B oldBound = boundLabels.putIfAbsent(labels, binding);
|
B oldBound = boundLabels.putIfAbsent(labels, binding);
|
||||||
if (oldBound != null) {
|
if (oldBound != null) {
|
||||||
|
|
@ -68,14 +68,13 @@ abstract class AbstractSynchronousInstrument<B extends AbstractBoundInstrument>
|
||||||
// acquire but because we requested a specific value only one will succeed.
|
// acquire but because we requested a specific value only one will succeed.
|
||||||
boundLabels.remove(entry.getKey(), entry.getValue());
|
boundLabels.remove(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
instrumentAccumulator.batch(
|
instrumentProcessor.batch(entry.getKey(), entry.getValue().getAggregator(), !unmappedEntry);
|
||||||
entry.getKey(), entry.getValue().getAggregator(), !unmappedEntry);
|
|
||||||
}
|
}
|
||||||
return instrumentAccumulator.completeCollectionCycle();
|
return instrumentProcessor.completeCollectionCycle();
|
||||||
} finally {
|
} finally {
|
||||||
collectLock.unlock();
|
collectLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract B newBinding(InstrumentAccumulator instrumentAccumulator);
|
abstract B newBinding(InstrumentProcessor instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ final class DoubleCounterSdk extends AbstractSynchronousInstrument<BoundInstrume
|
||||||
implements DoubleCounter {
|
implements DoubleCounter {
|
||||||
|
|
||||||
private DoubleCounterSdk(
|
private DoubleCounterSdk(
|
||||||
InstrumentDescriptor descriptor, InstrumentAccumulator instrumentAccumulator) {
|
InstrumentDescriptor descriptor, InstrumentProcessor instrumentProcessor) {
|
||||||
super(descriptor, instrumentAccumulator);
|
super(descriptor, instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -35,15 +35,15 @@ final class DoubleCounterSdk extends AbstractSynchronousInstrument<BoundInstrume
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
BoundInstrument newBinding(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument newBinding(InstrumentProcessor instrumentProcessor) {
|
||||||
return new BoundInstrument(instrumentAccumulator);
|
return new BoundInstrument(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class BoundInstrument extends AbstractBoundInstrument
|
static final class BoundInstrument extends AbstractBoundInstrument
|
||||||
implements DoubleCounter.BoundDoubleCounter {
|
implements DoubleCounter.BoundDoubleCounter {
|
||||||
|
|
||||||
BoundInstrument(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument(InstrumentProcessor instrumentProcessor) {
|
||||||
super(instrumentAccumulator.getAggregator());
|
super(instrumentProcessor.getAggregator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ final class DoubleSumObserverSdk extends AbstractDoubleAsynchronousInstrument
|
||||||
|
|
||||||
DoubleSumObserverSdk(
|
DoubleSumObserverSdk(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<DoubleResult> metricUpdater) {
|
@Nullable Callback<DoubleResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Builder
|
static final class Builder
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ final class DoubleUpDownCounterSdk extends AbstractSynchronousInstrument<BoundIn
|
||||||
implements DoubleUpDownCounter {
|
implements DoubleUpDownCounter {
|
||||||
|
|
||||||
private DoubleUpDownCounterSdk(
|
private DoubleUpDownCounterSdk(
|
||||||
InstrumentDescriptor descriptor, InstrumentAccumulator instrumentAccumulator) {
|
InstrumentDescriptor descriptor, InstrumentProcessor instrumentProcessor) {
|
||||||
super(descriptor, instrumentAccumulator);
|
super(descriptor, instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -32,15 +32,15 @@ final class DoubleUpDownCounterSdk extends AbstractSynchronousInstrument<BoundIn
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
BoundInstrument newBinding(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument newBinding(InstrumentProcessor instrumentProcessor) {
|
||||||
return new BoundInstrument(instrumentAccumulator);
|
return new BoundInstrument(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class BoundInstrument extends AbstractBoundInstrument
|
static final class BoundInstrument extends AbstractBoundInstrument
|
||||||
implements BoundDoubleUpDownCounter {
|
implements BoundDoubleUpDownCounter {
|
||||||
|
|
||||||
BoundInstrument(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument(InstrumentProcessor instrumentProcessor) {
|
||||||
super(instrumentAccumulator.getAggregator());
|
super(instrumentProcessor.getAggregator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ final class DoubleUpDownSumObserverSdk extends AbstractDoubleAsynchronousInstrum
|
||||||
|
|
||||||
DoubleUpDownSumObserverSdk(
|
DoubleUpDownSumObserverSdk(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<DoubleResult> metricUpdater) {
|
@Nullable Callback<DoubleResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Builder
|
static final class Builder
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ final class DoubleValueObserverSdk extends AbstractDoubleAsynchronousInstrument
|
||||||
|
|
||||||
DoubleValueObserverSdk(
|
DoubleValueObserverSdk(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<DoubleResult> metricUpdater) {
|
@Nullable Callback<DoubleResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Builder
|
static final class Builder
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ final class DoubleValueRecorderSdk extends AbstractSynchronousInstrument<BoundIn
|
||||||
implements DoubleValueRecorder {
|
implements DoubleValueRecorder {
|
||||||
|
|
||||||
private DoubleValueRecorderSdk(
|
private DoubleValueRecorderSdk(
|
||||||
InstrumentDescriptor descriptor, InstrumentAccumulator instrumentAccumulator) {
|
InstrumentDescriptor descriptor, InstrumentProcessor instrumentProcessor) {
|
||||||
super(descriptor, instrumentAccumulator);
|
super(descriptor, instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -32,15 +32,15 @@ final class DoubleValueRecorderSdk extends AbstractSynchronousInstrument<BoundIn
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
BoundInstrument newBinding(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument newBinding(InstrumentProcessor instrumentProcessor) {
|
||||||
return new BoundInstrument(instrumentAccumulator);
|
return new BoundInstrument(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class BoundInstrument extends AbstractBoundInstrument
|
static final class BoundInstrument extends AbstractBoundInstrument
|
||||||
implements BoundDoubleValueRecorder {
|
implements BoundDoubleValueRecorder {
|
||||||
|
|
||||||
BoundInstrument(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument(InstrumentProcessor instrumentProcessor) {
|
||||||
super(instrumentAccumulator.getAggregator());
|
super(instrumentProcessor.getAggregator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@code InstrumentAccumulator} represents an internal instance of an {@code Accumulator} for a
|
* An {@code InstrumentProcessor} represents an internal instance of an {@code Accumulator} for a
|
||||||
* specific {code Instrument}. It records individual measurements (via the {@code Aggregator}). It
|
* specific {code Instrument}. It records individual measurements (via the {@code Aggregator}). It
|
||||||
* batches together {@code Aggregator}s for the similar sets of labels.
|
* batches together {@code Aggregator}s for the similar sets of labels.
|
||||||
*
|
*
|
||||||
|
|
@ -29,7 +29,7 @@ import java.util.Objects;
|
||||||
* cycle must be protected by a lock. A collection cycle is defined by multiple calls to {@link
|
* cycle must be protected by a lock. A collection cycle is defined by multiple calls to {@link
|
||||||
* #batch(Labels, Aggregator, boolean)} followed by one {@link #completeCollectionCycle()};
|
* #batch(Labels, Aggregator, boolean)} followed by one {@link #completeCollectionCycle()};
|
||||||
*/
|
*/
|
||||||
final class InstrumentAccumulator {
|
final class InstrumentProcessor {
|
||||||
private final InstrumentDescriptor descriptor;
|
private final InstrumentDescriptor descriptor;
|
||||||
private final Aggregation aggregation;
|
private final Aggregation aggregation;
|
||||||
private final Resource resource;
|
private final Resource resource;
|
||||||
|
|
@ -45,12 +45,12 @@ final class InstrumentAccumulator {
|
||||||
* aggregation. "Cumulative" means that all metrics that are generated will be considered for the
|
* aggregation. "Cumulative" means that all metrics that are generated will be considered for the
|
||||||
* lifetime of the Instrument being aggregated.
|
* lifetime of the Instrument being aggregated.
|
||||||
*/
|
*/
|
||||||
static InstrumentAccumulator getCumulativeAllLabels(
|
static InstrumentProcessor getCumulativeAllLabels(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
MeterProviderSharedState meterProviderSharedState,
|
MeterProviderSharedState meterProviderSharedState,
|
||||||
MeterSharedState meterSharedState,
|
MeterSharedState meterSharedState,
|
||||||
Aggregation aggregation) {
|
Aggregation aggregation) {
|
||||||
return new InstrumentAccumulator(
|
return new InstrumentProcessor(
|
||||||
descriptor,
|
descriptor,
|
||||||
aggregation,
|
aggregation,
|
||||||
meterProviderSharedState.getResource(),
|
meterProviderSharedState.getResource(),
|
||||||
|
|
@ -64,12 +64,12 @@ final class InstrumentAccumulator {
|
||||||
* aggregation. "Delta" means that all metrics that are generated are only for the most recent
|
* aggregation. "Delta" means that all metrics that are generated are only for the most recent
|
||||||
* collection interval.
|
* collection interval.
|
||||||
*/
|
*/
|
||||||
static InstrumentAccumulator getDeltaAllLabels(
|
static InstrumentProcessor getDeltaAllLabels(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
MeterProviderSharedState meterProviderSharedState,
|
MeterProviderSharedState meterProviderSharedState,
|
||||||
MeterSharedState meterSharedState,
|
MeterSharedState meterSharedState,
|
||||||
Aggregation aggregation) {
|
Aggregation aggregation) {
|
||||||
return new InstrumentAccumulator(
|
return new InstrumentProcessor(
|
||||||
descriptor,
|
descriptor,
|
||||||
aggregation,
|
aggregation,
|
||||||
meterProviderSharedState.getResource(),
|
meterProviderSharedState.getResource(),
|
||||||
|
|
@ -78,7 +78,7 @@ final class InstrumentAccumulator {
|
||||||
/* delta= */ true);
|
/* delta= */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InstrumentAccumulator(
|
private InstrumentProcessor(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
Aggregation aggregation,
|
Aggregation aggregation,
|
||||||
Resource resource,
|
Resource resource,
|
||||||
|
|
@ -113,7 +113,7 @@ final class InstrumentAccumulator {
|
||||||
* @param aggregator the {@link Aggregator} used to aggregate individual events for the given
|
* @param aggregator the {@link Aggregator} used to aggregate individual events for the given
|
||||||
* {@code LabelSetSdk}.
|
* {@code LabelSetSdk}.
|
||||||
* @param mappedAggregator {@code true} if the {@code Aggregator} is still in used by a binding.
|
* @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.
|
* If {@code false} the {@code InstrumentProcessor} can reuse the {@code Aggregator} instance.
|
||||||
*/
|
*/
|
||||||
void batch(Labels labelSet, Aggregator aggregator, boolean mappedAggregator) {
|
void batch(Labels labelSet, Aggregator aggregator, boolean mappedAggregator) {
|
||||||
if (!aggregator.hasRecordings()) {
|
if (!aggregator.hasRecordings()) {
|
||||||
|
|
@ -183,7 +183,7 @@ final class InstrumentAccumulator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstrumentAccumulator allLabels = (InstrumentAccumulator) o;
|
InstrumentProcessor allLabels = (InstrumentProcessor) o;
|
||||||
|
|
||||||
if (startEpochNanos != allLabels.startEpochNanos) {
|
if (startEpochNanos != allLabels.startEpochNanos) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -14,9 +14,8 @@ import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
|
||||||
final class LongCounterSdk extends AbstractSynchronousInstrument<BoundInstrument>
|
final class LongCounterSdk extends AbstractSynchronousInstrument<BoundInstrument>
|
||||||
implements LongCounter {
|
implements LongCounter {
|
||||||
|
|
||||||
private LongCounterSdk(
|
private LongCounterSdk(InstrumentDescriptor descriptor, InstrumentProcessor instrumentProcessor) {
|
||||||
InstrumentDescriptor descriptor, InstrumentAccumulator instrumentAccumulator) {
|
super(descriptor, instrumentProcessor);
|
||||||
super(descriptor, instrumentAccumulator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -35,15 +34,15 @@ final class LongCounterSdk extends AbstractSynchronousInstrument<BoundInstrument
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
BoundInstrument newBinding(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument newBinding(InstrumentProcessor instrumentProcessor) {
|
||||||
return new BoundInstrument(instrumentAccumulator);
|
return new BoundInstrument(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class BoundInstrument extends AbstractBoundInstrument
|
static final class BoundInstrument extends AbstractBoundInstrument
|
||||||
implements LongCounter.BoundLongCounter {
|
implements LongCounter.BoundLongCounter {
|
||||||
|
|
||||||
BoundInstrument(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument(InstrumentProcessor instrumentProcessor) {
|
||||||
super(instrumentAccumulator.getAggregator());
|
super(instrumentProcessor.getAggregator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ final class LongSumObserverSdk extends AbstractLongAsynchronousInstrument
|
||||||
implements LongSumObserver {
|
implements LongSumObserver {
|
||||||
LongSumObserverSdk(
|
LongSumObserverSdk(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<LongResult> metricUpdater) {
|
@Nullable Callback<LongResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Builder
|
static final class Builder
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ final class LongUpDownCounterSdk extends AbstractSynchronousInstrument<BoundInst
|
||||||
implements LongUpDownCounter {
|
implements LongUpDownCounter {
|
||||||
|
|
||||||
private LongUpDownCounterSdk(
|
private LongUpDownCounterSdk(
|
||||||
InstrumentDescriptor descriptor, InstrumentAccumulator instrumentAccumulator) {
|
InstrumentDescriptor descriptor, InstrumentProcessor instrumentProcessor) {
|
||||||
super(descriptor, instrumentAccumulator);
|
super(descriptor, instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -32,15 +32,15 @@ final class LongUpDownCounterSdk extends AbstractSynchronousInstrument<BoundInst
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
BoundInstrument newBinding(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument newBinding(InstrumentProcessor instrumentProcessor) {
|
||||||
return new BoundInstrument(instrumentAccumulator);
|
return new BoundInstrument(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class BoundInstrument extends AbstractBoundInstrument
|
static final class BoundInstrument extends AbstractBoundInstrument
|
||||||
implements BoundLongUpDownCounter {
|
implements BoundLongUpDownCounter {
|
||||||
|
|
||||||
BoundInstrument(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument(InstrumentProcessor instrumentProcessor) {
|
||||||
super(instrumentAccumulator.getAggregator());
|
super(instrumentProcessor.getAggregator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ final class LongUpDownSumObserverSdk extends AbstractLongAsynchronousInstrument
|
||||||
implements LongUpDownSumObserver {
|
implements LongUpDownSumObserver {
|
||||||
LongUpDownSumObserverSdk(
|
LongUpDownSumObserverSdk(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<LongResult> metricUpdater) {
|
@Nullable Callback<LongResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Builder
|
static final class Builder
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ final class LongValueObserverSdk extends AbstractLongAsynchronousInstrument
|
||||||
|
|
||||||
LongValueObserverSdk(
|
LongValueObserverSdk(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
InstrumentAccumulator instrumentAccumulator,
|
InstrumentProcessor instrumentProcessor,
|
||||||
@Nullable Callback<LongResult> metricUpdater) {
|
@Nullable Callback<LongResult> metricUpdater) {
|
||||||
super(descriptor, instrumentAccumulator, metricUpdater);
|
super(descriptor, instrumentProcessor, metricUpdater);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class Builder
|
static final class Builder
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ final class LongValueRecorderSdk extends AbstractSynchronousInstrument<BoundInst
|
||||||
implements LongValueRecorder {
|
implements LongValueRecorder {
|
||||||
|
|
||||||
private LongValueRecorderSdk(
|
private LongValueRecorderSdk(
|
||||||
InstrumentDescriptor descriptor, InstrumentAccumulator instrumentAccumulator) {
|
InstrumentDescriptor descriptor, InstrumentProcessor instrumentProcessor) {
|
||||||
super(descriptor, instrumentAccumulator);
|
super(descriptor, instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -32,15 +32,15 @@ final class LongValueRecorderSdk extends AbstractSynchronousInstrument<BoundInst
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
BoundInstrument newBinding(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument newBinding(InstrumentProcessor instrumentProcessor) {
|
||||||
return new BoundInstrument(instrumentAccumulator);
|
return new BoundInstrument(instrumentProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final class BoundInstrument extends AbstractBoundInstrument
|
static final class BoundInstrument extends AbstractBoundInstrument
|
||||||
implements BoundLongValueRecorder {
|
implements BoundLongValueRecorder {
|
||||||
|
|
||||||
BoundInstrument(InstrumentAccumulator instrumentAccumulator) {
|
BoundInstrument(InstrumentProcessor instrumentProcessor) {
|
||||||
super(instrumentAccumulator.getAggregator());
|
super(instrumentProcessor.getAggregator());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,9 @@ final class MeterSdk implements Meter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link InstrumentAccumulator}, by using the {@link ViewRegistry} to do the actual
|
* Creates a {@link InstrumentProcessor}, by using the {@link ViewRegistry} to do the actual work.
|
||||||
* work.
|
|
||||||
*/
|
*/
|
||||||
InstrumentAccumulator createBatcher(
|
InstrumentProcessor createBatcher(
|
||||||
InstrumentDescriptor descriptor,
|
InstrumentDescriptor descriptor,
|
||||||
MeterProviderSharedState meterProviderSharedState,
|
MeterProviderSharedState meterProviderSharedState,
|
||||||
MeterSharedState meterSharedState) {
|
MeterSharedState meterSharedState) {
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ class ViewRegistry {
|
||||||
aggregationChooser.addView(selector, specification);
|
aggregationChooser.addView(selector, specification);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a new {@link InstrumentAccumulator} for use in metric recording aggregation. */
|
/** Create a new {@link InstrumentProcessor} for use in metric recording aggregation. */
|
||||||
InstrumentAccumulator createBatcher(
|
InstrumentProcessor createBatcher(
|
||||||
MeterProviderSharedState meterProviderSharedState,
|
MeterProviderSharedState meterProviderSharedState,
|
||||||
MeterSharedState meterSharedState,
|
MeterSharedState meterSharedState,
|
||||||
InstrumentDescriptor descriptor) {
|
InstrumentDescriptor descriptor) {
|
||||||
|
|
@ -55,10 +55,10 @@ class ViewRegistry {
|
||||||
Aggregation aggregation = specification.aggregation();
|
Aggregation aggregation = specification.aggregation();
|
||||||
|
|
||||||
if (Temporality.CUMULATIVE == specification.temporality()) {
|
if (Temporality.CUMULATIVE == specification.temporality()) {
|
||||||
return InstrumentAccumulator.getCumulativeAllLabels(
|
return InstrumentProcessor.getCumulativeAllLabels(
|
||||||
descriptor, meterProviderSharedState, meterSharedState, aggregation);
|
descriptor, meterProviderSharedState, meterSharedState, aggregation);
|
||||||
} else if (Temporality.DELTA == specification.temporality()) {
|
} else if (Temporality.DELTA == specification.temporality()) {
|
||||||
return InstrumentAccumulator.getDeltaAllLabels(
|
return InstrumentProcessor.getDeltaAllLabels(
|
||||||
descriptor, meterProviderSharedState, meterSharedState, aggregation);
|
descriptor, meterProviderSharedState, meterSharedState, aggregation);
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("unsupported Temporality: " + specification.temporality());
|
throw new IllegalStateException("unsupported Temporality: " + specification.temporality());
|
||||||
|
|
|
||||||
|
|
@ -55,17 +55,17 @@ class ViewRegistryTest {
|
||||||
AggregationConfiguration specification =
|
AggregationConfiguration specification =
|
||||||
AggregationConfiguration.create(
|
AggregationConfiguration.create(
|
||||||
Aggregations.count(), AggregationConfiguration.Temporality.CUMULATIVE);
|
Aggregations.count(), AggregationConfiguration.Temporality.CUMULATIVE);
|
||||||
InstrumentAccumulator expectedInstrumentAccumulator =
|
InstrumentProcessor expectedInstrumentProcessor =
|
||||||
InstrumentAccumulator.getCumulativeAllLabels(
|
InstrumentProcessor.getCumulativeAllLabels(
|
||||||
descriptor, providerSharedState, meterSharedState, Aggregations.count());
|
descriptor, providerSharedState, meterSharedState, Aggregations.count());
|
||||||
|
|
||||||
when(chooser.chooseAggregation(descriptor)).thenReturn(specification);
|
when(chooser.chooseAggregation(descriptor)).thenReturn(specification);
|
||||||
|
|
||||||
InstrumentAccumulator result =
|
InstrumentProcessor result =
|
||||||
viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor);
|
viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor);
|
||||||
|
|
||||||
assertThat(result.generatesDeltas()).isFalse();
|
assertThat(result.generatesDeltas()).isFalse();
|
||||||
assertThat(result).isEqualTo(expectedInstrumentAccumulator);
|
assertThat(result).isEqualTo(expectedInstrumentProcessor);
|
||||||
|
|
||||||
assertThat(result).isNotNull();
|
assertThat(result).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
@ -87,17 +87,17 @@ class ViewRegistryTest {
|
||||||
AggregationConfiguration specification =
|
AggregationConfiguration specification =
|
||||||
AggregationConfiguration.create(
|
AggregationConfiguration.create(
|
||||||
Aggregations.count(), AggregationConfiguration.Temporality.DELTA);
|
Aggregations.count(), AggregationConfiguration.Temporality.DELTA);
|
||||||
InstrumentAccumulator expectedInstrumentAccumulator =
|
InstrumentProcessor expectedInstrumentProcessor =
|
||||||
InstrumentAccumulator.getDeltaAllLabels(
|
InstrumentProcessor.getDeltaAllLabels(
|
||||||
descriptor, providerSharedState, meterSharedState, Aggregations.count());
|
descriptor, providerSharedState, meterSharedState, Aggregations.count());
|
||||||
|
|
||||||
when(chooser.chooseAggregation(descriptor)).thenReturn(specification);
|
when(chooser.chooseAggregation(descriptor)).thenReturn(specification);
|
||||||
|
|
||||||
InstrumentAccumulator result =
|
InstrumentProcessor result =
|
||||||
viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor);
|
viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor);
|
||||||
|
|
||||||
assertThat(result.generatesDeltas()).isTrue();
|
assertThat(result.generatesDeltas()).isTrue();
|
||||||
assertThat(result).isEqualTo(expectedInstrumentAccumulator);
|
assertThat(result).isEqualTo(expectedInstrumentProcessor);
|
||||||
|
|
||||||
assertThat(result).isNotNull();
|
assertThat(result).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue