forked from open-telemetry/opentelemetry-java-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[disk-buffering] - Single responsibility for disk exporters (open-tel…
- Loading branch information
1 parent
12bd584
commit 396b640
Showing
45 changed files
with
1,823 additions
and
1,077 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
95 changes: 0 additions & 95 deletions
95
...uffering/src/main/java/io/opentelemetry/contrib/disk/buffering/LogRecordDiskExporter.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...ring/src/main/java/io/opentelemetry/contrib/disk/buffering/LogRecordFromDiskExporter.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,46 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.disk.buffering; | ||
|
||
import io.opentelemetry.contrib.disk.buffering.internal.StorageConfiguration; | ||
import io.opentelemetry.contrib.disk.buffering.internal.exporter.FromDiskExporter; | ||
import io.opentelemetry.contrib.disk.buffering.internal.exporter.FromDiskExporterImpl; | ||
import io.opentelemetry.contrib.disk.buffering.internal.serialization.serializers.SignalSerializer; | ||
import io.opentelemetry.sdk.logs.data.LogRecordData; | ||
import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class LogRecordFromDiskExporter implements FromDiskExporter { | ||
|
||
private final FromDiskExporterImpl<LogRecordData> delegate; | ||
|
||
public static LogRecordFromDiskExporter create( | ||
LogRecordExporter exporter, StorageConfiguration config) throws IOException { | ||
FromDiskExporterImpl<LogRecordData> delegate = | ||
FromDiskExporterImpl.<LogRecordData>builder() | ||
.setFolderName("logs") | ||
.setStorageConfiguration(config) | ||
.setDeserializer(SignalSerializer.ofLogs()) | ||
.setExportFunction(exporter::export) | ||
.build(); | ||
return new LogRecordFromDiskExporter(delegate); | ||
} | ||
|
||
private LogRecordFromDiskExporter(FromDiskExporterImpl<LogRecordData> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public boolean exportStoredBatch(long timeout, TimeUnit unit) throws IOException { | ||
return delegate.exportStoredBatch(timeout, unit); | ||
} | ||
|
||
@Override | ||
public void shutdown() throws IOException { | ||
delegate.shutdown(); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...fering/src/main/java/io/opentelemetry/contrib/disk/buffering/LogRecordToDiskExporter.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,68 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.contrib.disk.buffering; | ||
|
||
import io.opentelemetry.contrib.disk.buffering.internal.StorageConfiguration; | ||
import io.opentelemetry.contrib.disk.buffering.internal.exporter.ToDiskExporter; | ||
import io.opentelemetry.contrib.disk.buffering.internal.serialization.serializers.SignalSerializer; | ||
import io.opentelemetry.sdk.common.CompletableResultCode; | ||
import io.opentelemetry.sdk.logs.data.LogRecordData; | ||
import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
/** | ||
* This class implements a {@link LogRecordExporter} that delegates to an instance of {@code | ||
* ToDiskExporter<LogRecordData>}. | ||
*/ | ||
public class LogRecordToDiskExporter implements LogRecordExporter { | ||
private final ToDiskExporter<LogRecordData> delegate; | ||
|
||
/** | ||
* Creates a new LogRecordToDiskExporter that will buffer LogRecordData telemetry on disk storage. | ||
* | ||
* @param delegate - The LogRecordExporter to delegate to if disk writing fails. | ||
* @param config - The StorageConfiguration that specifies how storage is managed. | ||
* @return A new LogRecordToDiskExporter instance. | ||
* @throws IOException if the delegate ToDiskExporter could not be created. | ||
*/ | ||
public static LogRecordToDiskExporter create( | ||
LogRecordExporter delegate, StorageConfiguration config) throws IOException { | ||
ToDiskExporter<LogRecordData> toDisk = | ||
ToDiskExporter.<LogRecordData>builder() | ||
.setFolderName("logs") | ||
.setStorageConfiguration(config) | ||
.setSerializer(SignalSerializer.ofLogs()) | ||
.setExportFunction(delegate::export) | ||
.build(); | ||
return new LogRecordToDiskExporter(toDisk); | ||
} | ||
|
||
// Visible for testing | ||
LogRecordToDiskExporter(ToDiskExporter<LogRecordData> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public CompletableResultCode export(Collection<LogRecordData> logs) { | ||
return delegate.export(logs); | ||
} | ||
|
||
@Override | ||
public CompletableResultCode flush() { | ||
return CompletableResultCode.ofSuccess(); | ||
} | ||
|
||
@Override | ||
public CompletableResultCode shutdown() { | ||
try { | ||
delegate.shutdown(); | ||
return CompletableResultCode.ofSuccess(); | ||
} catch (IOException e) { | ||
return CompletableResultCode.ofFailure(); | ||
} | ||
} | ||
} |
Oops, something went wrong.