Skip to content

Commit 6e24f35

Browse files
authored
[disk-buffering] Simplify MetricToDiskExporter creation (#1672)
1 parent 3db20f7 commit 6e24f35

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

disk-buffering/src/main/java/io/opentelemetry/contrib/disk/buffering/MetricToDiskExporter.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import io.opentelemetry.sdk.metrics.InstrumentType;
1313
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
1414
import io.opentelemetry.sdk.metrics.data.MetricData;
15+
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
1516
import io.opentelemetry.sdk.metrics.export.MetricExporter;
1617
import java.io.IOException;
1718
import java.util.Collection;
18-
import java.util.function.Function;
1919

2020
/**
2121
* This class implements a {@link MetricExporter} that delegates to an instance of {@code
@@ -24,22 +24,17 @@
2424
public class MetricToDiskExporter implements MetricExporter {
2525

2626
private final ToDiskExporter<MetricData> delegate;
27-
private final Function<InstrumentType, AggregationTemporality> typeToTemporality;
27+
private final AggregationTemporalitySelector aggregationTemporalitySelector;
2828

2929
/**
3030
* Creates a new MetricToDiskExporter that will buffer Metric telemetry on disk storage.
3131
*
3232
* @param delegate - The MetricExporter to delegate to if disk writing fails.
3333
* @param config - The StorageConfiguration that specifies how storage is managed.
34-
* @param typeToTemporality - The function that maps an InstrumentType into an
35-
* AggregationTemporality.
3634
* @return A new MetricToDiskExporter instance.
3735
* @throws IOException if the delegate ToDiskExporter could not be created.
3836
*/
39-
public static MetricToDiskExporter create(
40-
MetricExporter delegate,
41-
StorageConfiguration config,
42-
Function<InstrumentType, AggregationTemporality> typeToTemporality)
37+
public static MetricToDiskExporter create(MetricExporter delegate, StorageConfiguration config)
4338
throws IOException {
4439
ToDiskExporter<MetricData> toDisk =
4540
ToDiskExporter.<MetricData>builder()
@@ -48,15 +43,14 @@ public static MetricToDiskExporter create(
4843
.setSerializer(SignalSerializer.ofMetrics())
4944
.setExportFunction(delegate::export)
5045
.build();
51-
return new MetricToDiskExporter(toDisk, typeToTemporality);
46+
return new MetricToDiskExporter(toDisk, delegate);
5247
}
5348

5449
// VisibleForTesting
5550
MetricToDiskExporter(
56-
ToDiskExporter<MetricData> delegate,
57-
Function<InstrumentType, AggregationTemporality> typeToTemporality) {
51+
ToDiskExporter<MetricData> delegate, AggregationTemporalitySelector selector) {
5852
this.delegate = delegate;
59-
this.typeToTemporality = typeToTemporality;
53+
this.aggregationTemporalitySelector = selector;
6054
}
6155

6256
@Override
@@ -81,6 +75,6 @@ public CompletableResultCode shutdown() {
8175

8276
@Override
8377
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) {
84-
return typeToTemporality.apply(instrumentType);
78+
return aggregationTemporalitySelector.getAggregationTemporality(instrumentType);
8579
}
8680
}

disk-buffering/src/test/java/io/opentelemetry/contrib/disk/buffering/IntegrationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ void setUp() throws IOException {
8585
memoryMetricExporter = InMemoryMetricExporter.create();
8686
ToDiskExporter<MetricData> toDiskMetricExporter =
8787
buildToDiskExporter(SignalSerializer.ofMetrics(), memoryMetricExporter::export);
88-
metricToDiskExporter =
89-
new MetricToDiskExporter(
90-
toDiskMetricExporter, memoryMetricExporter::getAggregationTemporality);
88+
metricToDiskExporter = new MetricToDiskExporter(toDiskMetricExporter, memoryMetricExporter);
9189
meterProvider = createMeterProvider(metricToDiskExporter);
9290
meter = meterProvider.get("MetricInstrumentationScope");
9391

0 commit comments

Comments
 (0)