-
Notifications
You must be signed in to change notification settings - Fork 849
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduction of View and first version of LabelsProessor
- Loading branch information
Anton Polyakov
committed
Feb 11, 2021
1 parent
339bbb8
commit c02d042
Showing
12 changed files
with
163 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/processor/BaggageLabelsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.opentelemetry.sdk.metrics.processor; | ||
|
||
import io.opentelemetry.api.metrics.common.Labels; | ||
import io.opentelemetry.api.metrics.common.LabelsBuilder; | ||
import io.opentelemetry.context.Context; | ||
|
||
public class BaggageLabelsProcessor implements LabelsProcessor { | ||
private final BaggageMetricsLabelsExtractor baggageMetricsLabelsExtractor; | ||
|
||
public BaggageLabelsProcessor(BaggageMetricsLabelsExtractor baggageMetricsLabelsExtractor) { | ||
this.baggageMetricsLabelsExtractor = baggageMetricsLabelsExtractor; | ||
} | ||
|
||
@Override | ||
public Labels onLabelsBound(Context ctx, Labels labels) { | ||
LabelsBuilder labelsBuilder = labels.toBuilder(); | ||
baggageMetricsLabelsExtractor.fromBaggage(ctx).forEach(labelsBuilder::put); | ||
|
||
return labelsBuilder.build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...s/src/main/java/io/opentelemetry/sdk/metrics/processor/BaggageMetricsLabelsExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.opentelemetry.sdk.metrics.processor; | ||
|
||
import io.opentelemetry.api.metrics.common.Labels; | ||
import io.opentelemetry.context.Context; | ||
|
||
public interface BaggageMetricsLabelsExtractor { | ||
|
||
Labels fromBaggage(Context ctx); | ||
} |
18 changes: 18 additions & 0 deletions
18
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/processor/LabelsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.opentelemetry.sdk.metrics.processor; | ||
|
||
import io.opentelemetry.api.metrics.common.Labels; | ||
import io.opentelemetry.context.Context; | ||
|
||
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 | ||
* | ||
* @param ctx context of the operation | ||
* @param labels immutable labels. When processors are chained output labels of the previous one is passed as | ||
* an input to the next one. Last labels returned by a chain of processors are used for bind() operation. | ||
* @return labels to be used as an input to the next processor in chain or bind() operation if this is the last processor | ||
*/ | ||
Labels onLabelsBound(Context ctx, Labels labels); | ||
} |
17 changes: 17 additions & 0 deletions
17
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/processor/LabelsProcessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.opentelemetry.sdk.metrics.processor; | ||
|
||
public interface LabelsProcessorFactory { | ||
static LabelsProcessorFactory noop() { | ||
return NoopLabelsProcessor::new; | ||
} | ||
static LabelsProcessorFactory baggageExtractor(BaggageMetricsLabelsExtractor labelsExtractor) { | ||
return () -> new BaggageLabelsProcessor(labelsExtractor); | ||
} | ||
|
||
/** | ||
* Returns a new {@link LabelsProcessorFactory} | ||
* | ||
* @return new {@link LabelsProcessorFactory} | ||
*/ | ||
LabelsProcessor create(); | ||
} |
12 changes: 12 additions & 0 deletions
12
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/processor/NoopLabelsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.opentelemetry.sdk.metrics.processor; | ||
|
||
import io.opentelemetry.api.metrics.common.Labels; | ||
import io.opentelemetry.context.Context; | ||
|
||
public class NoopLabelsProcessor implements LabelsProcessor { | ||
|
||
@Override | ||
public Labels onLabelsBound(Context c, Labels labels) { | ||
return labels; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/View.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.opentelemetry.sdk.metrics.view; | ||
|
||
import com.google.auto.value.AutoValue; | ||
import io.opentelemetry.sdk.metrics.aggregator.AggregatorFactory; | ||
import io.opentelemetry.sdk.metrics.processor.LabelsProcessorFactory; | ||
import javax.annotation.concurrent.Immutable; | ||
|
||
@AutoValue | ||
@Immutable | ||
public abstract class View { | ||
public abstract AggregatorFactory getAggregatorFactory(); | ||
|
||
public abstract LabelsProcessorFactory getLabelsProcessorFactory(); | ||
|
||
public static Builder builder() { | ||
return new AutoValue_View.Builder().setLabelsProcessorFactory(LabelsProcessorFactory.noop()); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
public abstract Builder setAggregatorFactory(AggregatorFactory aggregatorFactory); | ||
public abstract Builder setLabelsProcessorFactory(LabelsProcessorFactory labelsProcessorFactory); | ||
|
||
public abstract View build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters