-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding disk buffering, part 4 (#221)
* Creating and initializing SignalDiskExporter * Renaming test functions * Verifying rum set up with disk buffering enabled * Exporting all available signals from disk in DefaultExportScheduler * Setting up disk buffering export scheduler * Adding javadocs * Reorganizing fields * Update instrumentation/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalDiskExporter.kt Co-authored-by: Manoel Aranda Neto <[email protected]> * Update instrumentation/src/main/java/io/opentelemetry/android/features/diskbuffering/scheduler/DefaultExportScheduler.kt Co-authored-by: jason plumb <[email protected]> * Inverting "if" as suggested in the reviews. * Renaming function to scheduleDiskTelemetryReader * Fixing compilation * Adapting disk buffering to new APIs --------- Co-authored-by: Manoel Aranda Neto <[email protected]> Co-authored-by: jason plumb <[email protected]>
- Loading branch information
1 parent
16b450c
commit 3632f6a
Showing
10 changed files
with
519 additions
and
61 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
115 changes: 115 additions & 0 deletions
115
...n/src/main/java/io/opentelemetry/android/features/diskbuffering/SignalFromDiskExporter.kt
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,115 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.features.diskbuffering | ||
|
||
import androidx.annotation.WorkerThread | ||
import io.opentelemetry.contrib.disk.buffering.LogRecordFromDiskExporter | ||
import io.opentelemetry.contrib.disk.buffering.MetricFromDiskExporter | ||
import io.opentelemetry.contrib.disk.buffering.SpanFromDiskExporter | ||
import java.io.IOException | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* Entrypoint to read and export previously cached signals. | ||
*/ | ||
class SignalFromDiskExporter | ||
@JvmOverloads | ||
internal constructor( | ||
private val spanFromDiskExporter: SpanFromDiskExporter?, | ||
private val metricFromDiskExporter: MetricFromDiskExporter?, | ||
private val logRecordFromDiskExporter: LogRecordFromDiskExporter?, | ||
private val exportTimeoutInMillis: Long = TimeUnit.SECONDS.toMillis(5), | ||
) { | ||
/** | ||
* A batch contains all the signals that arrived in one call to [SpanDiskExporter.export]. So if | ||
* that function is called 5 times, then there will be 5 batches in disk. This function reads | ||
* and exports ONE batch every time is called. | ||
* | ||
* @return TRUE if it found data in disk and the exporter succeeded. FALSE if any of those conditions were | ||
* not met. | ||
*/ | ||
@WorkerThread | ||
@Throws(IOException::class) | ||
fun exportBatchOfSpans(): Boolean { | ||
return spanFromDiskExporter?.exportStoredBatch( | ||
exportTimeoutInMillis, | ||
TimeUnit.MILLISECONDS, | ||
) ?: false | ||
} | ||
|
||
/** | ||
* A batch contains all the signals that arrived in one call to [MetricDiskExporter.export]. So if | ||
* that function is called 5 times, then there will be 5 batches in disk. This function reads | ||
* and exports ONE batch every time is called. | ||
* | ||
* @return TRUE if it found data in disk and the exporter succeeded. FALSE if any of those conditions were | ||
* not met. | ||
*/ | ||
@WorkerThread | ||
@Throws(IOException::class) | ||
fun exportBatchOfMetrics(): Boolean { | ||
return metricFromDiskExporter?.exportStoredBatch( | ||
exportTimeoutInMillis, | ||
TimeUnit.MILLISECONDS, | ||
) ?: false | ||
} | ||
|
||
/** | ||
* A batch contains all the signals that arrived in one call to [LogRecordDiskExporter.export]. So if | ||
* that function is called 5 times, then there will be 5 batches in disk. This function reads | ||
* and exports ONE batch every time is called. | ||
* | ||
* @return TRUE if it found data in disk and the exporter succeeded. FALSE if any of those conditions were | ||
* not met. | ||
*/ | ||
@WorkerThread | ||
@Throws(IOException::class) | ||
fun exportBatchOfLogs(): Boolean { | ||
return logRecordFromDiskExporter?.exportStoredBatch( | ||
exportTimeoutInMillis, | ||
TimeUnit.MILLISECONDS, | ||
) ?: false | ||
} | ||
|
||
/** | ||
* Convenience method that attempts to export all kinds of signals from disk. | ||
* | ||
* @return TRUE if at least one of the signals were successfully exported, FALSE if no signal | ||
* of any kind was exported. | ||
*/ | ||
@WorkerThread | ||
@Throws(IOException::class) | ||
fun exportBatchOfEach(): Boolean { | ||
var atLeastOneWorked = exportBatchOfSpans() | ||
if (exportBatchOfMetrics()) { | ||
atLeastOneWorked = true | ||
} | ||
if (exportBatchOfLogs()) { | ||
atLeastOneWorked = true | ||
} | ||
return atLeastOneWorked | ||
} | ||
|
||
companion object { | ||
private var instance: SignalFromDiskExporter? = null | ||
|
||
@JvmStatic | ||
fun get(): SignalFromDiskExporter? { | ||
return instance | ||
} | ||
|
||
@JvmStatic | ||
fun set(signalFromDiskExporter: SignalFromDiskExporter) { | ||
check(instance == null) { "An instance is already set. You can only set it once." } | ||
instance = signalFromDiskExporter | ||
} | ||
|
||
@JvmStatic | ||
fun resetForTesting() { | ||
instance = null | ||
} | ||
} | ||
} |
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
Oops, something went wrong.