summaryrefslogtreecommitdiff
path: root/opendc-telemetry
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-05-06 14:01:36 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-05-06 18:37:36 +0200
commit260e2228afea08868e8f7f07233b1861b2d7f0c7 (patch)
tree2e9938f63c42e5d02fe203e049377d1d17b5d782 /opendc-telemetry
parent0e8ad565a78dd194e687003e5ccc8ccf9b28667f (diff)
refactor(telemetry): Remove dependency on OpenTelemetry SDK
This change removes the dependency on the OpenTelemetry SDK. Instead, we'll only expose metrics via the OpenTelemetry API in the future via adapter classes.
Diffstat (limited to 'opendc-telemetry')
-rw-r--r--opendc-telemetry/build.gradle.kts27
-rw-r--r--opendc-telemetry/opendc-telemetry-api/build.gradle.kts32
-rw-r--r--opendc-telemetry/opendc-telemetry-sdk/build.gradle.kts37
-rw-r--r--opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/OtelClockAdapter.kt39
-rw-r--r--opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/metrics/export/CoroutineMetricReader.kt106
5 files changed, 0 insertions, 241 deletions
diff --git a/opendc-telemetry/build.gradle.kts b/opendc-telemetry/build.gradle.kts
deleted file mode 100644
index 6473a29e..00000000
--- a/opendc-telemetry/build.gradle.kts
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-description = "Telemetry processing for OpenDC"
-
-subprojects {
- group = "org.opendc.telemetry"
-}
diff --git a/opendc-telemetry/opendc-telemetry-api/build.gradle.kts b/opendc-telemetry/opendc-telemetry-api/build.gradle.kts
deleted file mode 100644
index 32a36d68..00000000
--- a/opendc-telemetry/opendc-telemetry-api/build.gradle.kts
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-description = "Telemetry API for OpenDC"
-
-/* Build configuration */
-plugins {
- `kotlin-library-conventions`
-}
-
-dependencies {
- api(libs.opentelemetry.api)
-}
diff --git a/opendc-telemetry/opendc-telemetry-sdk/build.gradle.kts b/opendc-telemetry/opendc-telemetry-sdk/build.gradle.kts
deleted file mode 100644
index 4b3241bc..00000000
--- a/opendc-telemetry/opendc-telemetry-sdk/build.gradle.kts
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-description = "Telemetry SDK for OpenDC"
-
-/* Build configuration */
-plugins {
- `kotlin-library-conventions`
-}
-
-dependencies {
- api(projects.opendcTelemetry.opendcTelemetryApi)
- api(libs.kotlinx.coroutines)
- api(libs.opentelemetry.sdk.main)
- api(libs.opentelemetry.sdk.metrics)
-
- implementation(libs.kotlin.logging)
-}
diff --git a/opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/OtelClockAdapter.kt b/opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/OtelClockAdapter.kt
deleted file mode 100644
index cd191652..00000000
--- a/opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/OtelClockAdapter.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.telemetry.sdk
-
-import io.opentelemetry.sdk.common.Clock
-
-/**
- * An adapter class that bridges a [java.time.Clock] to a [Clock]
- */
-public class OtelClockAdapter(private val clock: java.time.Clock) : Clock {
- override fun now(): Long = nanoTime()
-
- override fun nanoTime(): Long = clock.millis() * 1_000_000L
-}
-
-/**
- * Convert the specified [java.time.Clock] to a [Clock].
- */
-public fun java.time.Clock.toOtelClock(): Clock = OtelClockAdapter(this)
diff --git a/opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/metrics/export/CoroutineMetricReader.kt b/opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/metrics/export/CoroutineMetricReader.kt
deleted file mode 100644
index ca5da079..00000000
--- a/opendc-telemetry/opendc-telemetry-sdk/src/main/kotlin/org/opendc/telemetry/sdk/metrics/export/CoroutineMetricReader.kt
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.telemetry.sdk.metrics.export
-
-import io.opentelemetry.sdk.common.CompletableResultCode
-import io.opentelemetry.sdk.metrics.data.AggregationTemporality
-import io.opentelemetry.sdk.metrics.export.MetricExporter
-import io.opentelemetry.sdk.metrics.export.MetricProducer
-import io.opentelemetry.sdk.metrics.export.MetricReader
-import io.opentelemetry.sdk.metrics.export.MetricReaderFactory
-import kotlinx.coroutines.*
-import mu.KotlinLogging
-import java.time.Duration
-
-/**
- * A helper class to read the metrics from a list of [MetricProducer]s and automatically export the metrics every
- * export interval.
- *
- * The reader runs in a [CoroutineScope] which enables collection of metrics in environments with a custom clock.
- *
- * @param scope The [CoroutineScope] to run the reader in.
- * @param producer The metric producer to gather metrics from.
- * @param exporter The export to export the metrics to.
- * @param exportInterval The export interval.
- */
-public class CoroutineMetricReader private constructor(
- scope: CoroutineScope,
- private val producer: MetricProducer,
- private val exporter: MetricExporter,
- private val exportInterval: Duration
-) : MetricReader {
- private val logger = KotlinLogging.logger {}
-
- /**
- * The background job that is responsible for collecting the metrics every cycle.
- */
- private val job = scope.launch {
- val intervalMs = exportInterval.toMillis()
-
- try {
- while (isActive) {
- delay(intervalMs)
-
- try {
- val metrics = producer.collectAllMetrics()
- val result = exporter.export(metrics)
- result.whenComplete {
- if (!result.isSuccess) {
- logger.warn { "Exporter failed" }
- }
- }
- } catch (cause: Throwable) {
- logger.warn(cause) { "Exporter threw an Exception" }
- }
- }
- } finally {
- exporter.shutdown()
- }
- }
-
- override fun getPreferredTemporality(): AggregationTemporality = AggregationTemporality.CUMULATIVE
-
- override fun flush(): CompletableResultCode {
- return exporter.flush()
- }
-
- override fun shutdown(): CompletableResultCode {
- job.cancel()
- return CompletableResultCode.ofSuccess()
- }
-
- public companion object {
- /**
- * Construct a [MetricReaderFactory] for this metric reader.
- */
- public operator fun invoke(
- scope: CoroutineScope,
- exporter: MetricExporter,
- exportInterval: Duration = Duration.ofMinutes(5)
- ): MetricReaderFactory {
- return MetricReaderFactory { producer ->
- CoroutineMetricReader(scope, producer, exporter, exportInterval)
- }
- }
- }
-}