Skip to content

Commit

Permalink
chore: refactor service benchmark telemetry provider to use new abstr…
Browse files Browse the repository at this point in the history
…actions
  • Loading branch information
ianbotsf committed Apr 24, 2024
1 parent 38c6da9 commit 5329277
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 64 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ coroutines-version = "1.7.3"
atomicfu-version = "0.23.1"

# smithy-kotlin codegen and runtime are versioned separately
smithy-kotlin-runtime-version = "1.1.5"
smithy-kotlin-codegen-version = "0.31.5"
smithy-kotlin-runtime-version = "1.1.6-SNAPSHOT"
smithy-kotlin-codegen-version = "0.31.6-SNAPSHOT"

# codegen
smithy-version = "1.47.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ package aws.sdk.kotlin.benchmarks.service.telemetry

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.collections.Attributes
import aws.smithy.kotlin.runtime.telemetry.TelemetryProvider
import aws.smithy.kotlin.runtime.telemetry.AbstractTelemetryProvider
import aws.smithy.kotlin.runtime.telemetry.context.Context
import aws.smithy.kotlin.runtime.telemetry.context.ContextManager
import aws.smithy.kotlin.runtime.telemetry.logging.LoggerProvider
import aws.smithy.kotlin.runtime.telemetry.metrics.*
import aws.smithy.kotlin.runtime.telemetry.trace.TracerProvider

private val capturedMetrics = mapOf(
"smithy.client.call.attempt_overhead_duration" to "Overhead",
Expand All @@ -23,45 +20,11 @@ private val capturedMetrics = mapOf(
)

@ExperimentalApi
class BenchmarkTelemetryProvider(private val metricAggregator: MetricAggregator) : TelemetryProvider {
override val contextManager = ContextManager.None
override val loggerProvider = LoggerProvider.None
override val tracerProvider = TracerProvider.None

override val meterProvider = object : MeterProvider {
override fun getOrCreateMeter(scope: String) = object : Meter {
override fun createUpDownCounter(name: String, units: String?, description: String?) =
NoOpUpDownCounter

override fun createAsyncUpDownCounter(
name: String,
callback: LongUpDownCounterCallback,
units: String?,
description: String?,
) = NoOpAsyncMeasurementHandle

override fun createMonotonicCounter(name: String, units: String?, description: String?) =
NoOpMonotonicCounter

override fun createLongHistogram(name: String, units: String?, description: String?) =
NoOpLongHistogram

class BenchmarkTelemetryProvider(private val metricAggregator: MetricAggregator) : AbstractTelemetryProvider() {
override val meterProvider = object : AbstractMeterProvider() {
override fun getOrCreateMeter(scope: String) = object : AbstractMeter() {
override fun createDoubleHistogram(name: String, units: String?, description: String?) =
capturedMetrics[name]?.let { BenchmarkDoubleHistogram(it, units) } ?: NoOpDoubleHistogram

override fun createLongGauge(
name: String,
callback: LongGaugeCallback,
units: String?,
description: String?,
) = NoOpAsyncMeasurementHandle

override fun createDoubleGauge(
name: String,
callback: DoubleGaugeCallback,
units: String?,
description: String?,
) = NoOpAsyncMeasurementHandle
capturedMetrics[name]?.let { BenchmarkDoubleHistogram(it, units) } ?: Histogram.DoubleNone
}
}

Expand Down Expand Up @@ -92,23 +55,3 @@ class BenchmarkTelemetryProvider(private val metricAggregator: MetricAggregator)
}
}
}

private object NoOpAsyncMeasurementHandle : AsyncMeasurementHandle {
override fun stop() { }
}

private object NoOpDoubleHistogram : DoubleHistogram {
override fun record(value: Double, attributes: Attributes, context: Context?) { }
}

private object NoOpLongHistogram : LongHistogram {
override fun record(value: Long, attributes: Attributes, context: Context?) { }
}

private object NoOpMonotonicCounter : MonotonicCounter {
override fun add(value: Long, attributes: Attributes, context: Context?) { }
}

private object NoOpUpDownCounter : UpDownCounter {
override fun add(value: Long, attributes: Attributes, context: Context?) { }
}

0 comments on commit 5329277

Please sign in to comment.