Skip to content

Commit

Permalink
code review: jaadocs, factory method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Polyakov committed Feb 17, 2021
1 parent 08d24f1 commit aeb5ea0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ static <T> Aggregator<T> getAggregator(
}

static LabelsProcessor getLabelsProcessor(
MeterProviderSharedState meterProviderSharedState, InstrumentDescriptor descriptor) {
MeterProviderSharedState meterProviderSharedState,
MeterSharedState meterSharedState,
InstrumentDescriptor descriptor) {
return meterProviderSharedState
.getViewRegistry()
.findView(descriptor)
.getLabelsProcessorFactory()
.create();
.create(
meterProviderSharedState.getResource(),
meterSharedState.getInstrumentationLibraryInfo(),
descriptor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static <T> SynchronousInstrumentAccumulator<T> create(
return new SynchronousInstrumentAccumulator<>(
aggregator,
new InstrumentProcessor<>(aggregator, meterProviderSharedState.getStartEpochNanos()),
getLabelsProcessor(meterProviderSharedState, descriptor));
getLabelsProcessor(meterProviderSharedState, meterSharedState, descriptor));
}

SynchronousInstrumentAccumulator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import io.opentelemetry.api.metrics.common.LabelsBuilder;
import io.opentelemetry.context.Context;

public class BaggageLabelsProcessor implements LabelsProcessor {
/**
* A label processor which extracts labels from {@link io.opentelemetry.api.baggage.Baggage}.
* Delegates actual extraction implementation to {@link BaggageMetricsLabelsExtractor}
*/
public final class BaggageLabelsProcessor implements LabelsProcessor {
private final BaggageMetricsLabelsExtractor baggageMetricsLabelsExtractor;

public BaggageLabelsProcessor(BaggageMetricsLabelsExtractor baggageMetricsLabelsExtractor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@

public interface LabelsProcessor {
/**
* Called when bind() method is called. Allows to manipulate labels which this instrument is bound
* to. Particular use case includes enriching lables and/or adding more labels depending on the
* Context
* Called when bound synchronous instrument is created or metrics are recorded for non-bound
* synchronous instrument. Allows to manipulate labels which this instrument is bound to in case
* of binding operation or labels used for recording values in case of non-bound synchronous
* instrument. Particular use case includes enriching labels and/or adding more labels depending
* on the Context
*
* <p>Please note, this is an experimental API. In case of bound instruments, it will be only
* invoked upon instrument binding and not when measurements are recorded.
*
* @param ctx context of the operation
* @param labels immutable labels. When processors are chained output labels of the previous one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@

package io.opentelemetry.sdk.metrics.processor;

import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.common.InstrumentDescriptor;
import io.opentelemetry.sdk.resources.Resource;

public interface LabelsProcessorFactory {
static LabelsProcessorFactory noop() {
return NoopLabelsProcessor::new;
return (resource, instrumentationLibraryInfo, descriptor) -> new NoopLabelsProcessor();
}

static LabelsProcessorFactory baggageExtractor(BaggageMetricsLabelsExtractor labelsExtractor) {
return () -> new BaggageLabelsProcessor(labelsExtractor);
return (resource, instrumentationLibraryInfo, descriptor) ->
new BaggageLabelsProcessor(labelsExtractor);
}

/**
* Returns a new {@link LabelsProcessorFactory}.
*
* @return new {@link LabelsProcessorFactory}
*/
LabelsProcessor create();
LabelsProcessor create(
Resource resource,
InstrumentationLibraryInfo instrumentationLibraryInfo,
InstrumentDescriptor descriptor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public class SynchronousInstrumentAccumulatorTest {
AggregatorFactory.lastValue()
.create(
Resource.getEmpty(), InstrumentationLibraryInfo.create("test", "1.0"), DESCRIPTOR);
private final LabelsProcessor labelsProcessor = LabelsProcessorFactory.noop().create();
private final LabelsProcessor labelsProcessor =
LabelsProcessorFactory.noop()
.create(
Resource.getEmpty(), InstrumentationLibraryInfo.create("test", "1.0"), DESCRIPTOR);

@Test
void sameAggregator_ForSameLabelSet() {
Expand Down

0 comments on commit aeb5ea0

Please sign in to comment.