diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index deabdc18..b9a0d2ea 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -118,6 +118,7 @@ See Clock in the https://rocketraman.github.io/bootable/[documentation]. * `boot-clock` binds the application's clock once, as a `kotlin.time.Clock` and a `java.time.Clock`. * The `java.time.Clock` wraps the `kotlin.time.Clock`, in UTC, so a test that replaces one replaces both. * The modules that take a `kotlin.time.Clock` binding, if there is one, take this one. +* The Inara `PeriodicModule`, `KubernetesLeaderElectionModule`, `DbSchedulerModule`, `OpenTelemetryModule`, and `ServiceStartTracingModule` require the `ClockModule`, in place of a clock parameter of their builders. * `asJavaClock()` and `asKotlinClock()` wrap either clock as the other. * Koin, Metro, and Inara flavors, and a deprecated Kodein flavor. diff --git a/boot-client-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/client/http/ktor/HttpClientTelemetryTest.kt b/boot-client-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/client/http/ktor/HttpClientTelemetryTest.kt index 9ee18355..8ab44abc 100644 --- a/boot-client-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/client/http/ktor/HttpClientTelemetryTest.kt +++ b/boot-client-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/client/http/ktor/HttpClientTelemetryTest.kt @@ -12,6 +12,8 @@ import com.github.rocketraman.bootable.boot.setOfAppServices import com.github.rocketraman.bootable.boot.startPlan import com.github.rocketraman.bootable.client.http.ktor.koin.httpClientTelemetryModule as koinHttpClientTelemetryModule import com.github.rocketraman.bootable.client.http.ktor.koin.ktorClientModule as koinKtorClientModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.common.HostPort @@ -261,6 +263,7 @@ object TestTelemetryBindings { interface InaraTestModule : ConfigModule, BootableModule, + ClockModule, OpenTelemetryModule, KtorClientModule, HttpClientTelemetryModule { @@ -339,6 +342,7 @@ val HttpClientTelemetryWiringTest by testSuite { val module = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), ktorClientModule = ktorClientModule(Downstream()), httpClientTelemetryModule = httpClientTelemetryModule(), diff --git a/boot-clock/src/inara/kotlin/com/github/rocketraman/bootable/clock/ClockModule.kt b/boot-clock/src/inara/kotlin/com/github/rocketraman/bootable/clock/ClockModule.kt index 923103d1..b7f31c87 100644 --- a/boot-clock/src/inara/kotlin/com/github/rocketraman/bootable/clock/ClockModule.kt +++ b/boot-clock/src/inara/kotlin/com/github/rocketraman/bootable/clock/ClockModule.kt @@ -8,9 +8,9 @@ import org.kodein.di.inara.DIModule import kotlin.time.Clock /** - * The Inara module that provides the application's clock, as a `kotlin.time.Clock` and as a `java.time.Clock`, for - * the application's own modules to require. Compose [clockModule], with `Clock.System`, or, in a test, with a clock - * of its own. + * The Inara module that provides the application's clock, as a `kotlin.time.Clock` and as a `java.time.Clock`. The + * Bootable modules that need a clock require it, such as `PeriodicModule`, and so can the application's own modules. + * Compose [clockModule], with `Clock.System`, or, in a test, with a clock of its own. */ @DIModule interface ClockModule { diff --git a/boot-clock/src/test/kotlin/com/github/rocketraman/bootable/clock/ClockWiringTest.kt b/boot-clock/src/test/kotlin/com/github/rocketraman/bootable/clock/ClockWiringTest.kt index 0794f54e..43f5e729 100644 --- a/boot-clock/src/test/kotlin/com/github/rocketraman/bootable/clock/ClockWiringTest.kt +++ b/boot-clock/src/test/kotlin/com/github/rocketraman/bootable/clock/ClockWiringTest.kt @@ -52,18 +52,16 @@ class TestClockBindings(private val clock: TestClock) { @DIModule(composed = true) interface ClockAppModule : ClockModule, LeaderElectionModule, OpenTelemetryApiModule, PeriodicModule -// a call resolves to the Kodein flavor's clockModule, of the same signature; a reference of this type to Inara's +// the Kodein and Inara flavors' clockModule have the same signature: a reference of each type picks one +private val kodeinClockModule: (Clock) -> DI.Module = ::clockModule private val inaraClockModule: (Clock) -> ClockModule = ::clockModule -private fun clockAppModule(clock: Clock = Clock.System): ClockAppModule { - val clockModule = inaraClockModule(clock) - return ClockAppModule( - clockModule = clockModule, - leaderElectionModule = AlwaysLeaderModule, - openTelemetryApiModule = NoopOpenTelemetryModule, - periodicModule = periodicModule(clockModule.clock), - ) -} +private fun clockAppModule(clock: Clock = Clock.System) = ClockAppModule( + clockModule = inaraClockModule(clock), + leaderElectionModule = AlwaysLeaderModule, + openTelemetryApiModule = NoopOpenTelemetryModule, + periodicModule = periodicModule(), +) /** Checks [javaClock] wraps [clock], by moving [clock]. */ private fun checkWraps(javaClock: JClock, clock: TestClock) { @@ -77,7 +75,7 @@ val ClockWiringTest by testSuite { test("binds the system clock, as both clocks, for the modules that take a clock") { val di = DI { import(bootableModule) - import(clockModule()) + import(kodeinClockModule(Clock.System)) import(periodicModule) }.direct assert(di.instance() == Clock.System) @@ -89,7 +87,7 @@ val ClockWiringTest by testSuite { val testClock = TestClock() val di = DI { import(bootableModule) - import(clockModule()) + import(kodeinClockModule(Clock.System)) import(periodicModule) bindSingleton(overrides = true) { testClock } }.direct @@ -100,7 +98,7 @@ val ClockWiringTest by testSuite { test("binds the clock it is given") { val testClock = TestClock() - val di = DI { import(clockModule(testClock)) }.direct + val di = DI { import(kodeinClockModule(testClock)) }.direct assert(di.instance() === testClock) checkWraps(di.instance(), testClock) } diff --git a/boot-db-jdbc-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/JdbcTracingTest.kt b/boot-db-jdbc-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/JdbcTracingTest.kt index 5b54c1c5..04e5d2a3 100644 --- a/boot-db-jdbc-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/JdbcTracingTest.kt +++ b/boot-db-jdbc-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/JdbcTracingTest.kt @@ -9,6 +9,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule @@ -189,6 +191,7 @@ object TestBindings { interface InaraTestModule : ConfigModule, BootableModule, + ClockModule, OpenTelemetryModule, JdbcDataSourceModule, HikariPoolModule, @@ -202,6 +205,7 @@ private val inaraJdbcTracingModule: (JdbcTelemetryBuilder.() -> Unit) -> JdbcTra private fun inaraTestModule(configure: JdbcTelemetryBuilder.() -> Unit = {}) = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), jdbcDataSourceModule = jdbcDataSourceModule(JdbcGenericConfigSource), hikariPoolModule = hikariPoolModule(), diff --git a/boot-db-pool-hikari-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/HikariPoolMetricsTest.kt b/boot-db-pool-hikari-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/HikariPoolMetricsTest.kt index 9a234073..8385efed 100644 --- a/boot-db-pool-hikari-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/HikariPoolMetricsTest.kt +++ b/boot-db-pool-hikari-otel/src/test/kotlin/com/github/rocketraman/bootable/db/jdbc/HikariPoolMetricsTest.kt @@ -9,6 +9,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule @@ -119,6 +121,7 @@ object TestBindings { interface InaraTestModule : ConfigModule, BootableModule, + ClockModule, OpenTelemetryModule, JdbcDataSourceModule, HikariPoolModule, @@ -130,6 +133,7 @@ interface InaraTestModule : private fun inaraTestModule() = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), jdbcDataSourceModule = jdbcDataSourceModule(JdbcGenericConfigSource), hikariPoolModule = hikariPoolModule(), diff --git a/boot-leader-k8s/src/inara/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionModule.kt b/boot-leader-k8s/src/inara/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionModule.kt index 5d5e3a1d..5bcb5e4e 100644 --- a/boot-leader-k8s/src/inara/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionModule.kt +++ b/boot-leader-k8s/src/inara/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionModule.kt @@ -3,6 +3,7 @@ package com.github.rocketraman.bootable.leader.k8s import com.github.rocketraman.bootable.boot.AppServices +import com.github.rocketraman.bootable.clock.ClockModule import com.github.rocketraman.bootable.client.http.ktor.KtorClientDefaults import com.github.rocketraman.bootable.client.http.ktor.KtorClientModule import com.github.rocketraman.bootable.client.http.ktor.NamedClientDefaults @@ -10,7 +11,6 @@ import com.github.rocketraman.bootable.config.config import com.github.rocketraman.bootable.leader.LeaderElectionModule import org.kodein.di.inara.Binding import org.kodein.di.inara.DIModule -import kotlin.time.Clock /** * The Inara module that provides the application's `LeaderElection`, as a [LeaderElectionModule], with a @@ -22,17 +22,20 @@ import kotlin.time.Clock * by default, or else the default client, of the [KtorClientModule] it requires. In a cluster, that client trusts the * API server with no TLS config of the application's: see [kubernetesClientDefaults]. * + * Its leases are timed by the clock of the [ClockModule] it requires. + * * `periodicModule()` (from boot-periodic) gates the application's periodic services on it. */ @DIModule -interface KubernetesLeaderElectionModule : LeaderElectionModule, @DIModule.Required KtorClientModule { +interface KubernetesLeaderElectionModule : + LeaderElectionModule, @DIModule.Required KtorClientModule, @DIModule.Required ClockModule { val kubernetesLeaderElectionConfig: KubernetesLeaderElectionConfig @AppServices val kubernetesLeaderElection: KubernetesLeaderElection @NamedClientDefaults val kubernetesClientDefaults: KtorClientDefaults } -/** A [KubernetesLeaderElectionModule], whose leases are timed by [clock]. */ -fun kubernetesLeaderElectionModule(clock: Clock = Clock.System): KubernetesLeaderElectionModulePart = +/** A [KubernetesLeaderElectionModule]. */ +fun kubernetesLeaderElectionModule(): KubernetesLeaderElectionModulePart = KubernetesLeaderElectionModulePart( kubernetesLeaderElectionConfig = config("leader.kubernetes"), kubernetesLeaderElection = Binding.single { diff --git a/boot-leader-k8s/src/test/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionWiringTest.kt b/boot-leader-k8s/src/test/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionWiringTest.kt index 08b1b0d6..5bfc5347 100644 --- a/boot-leader-k8s/src/test/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionWiringTest.kt +++ b/boot-leader-k8s/src/test/kotlin/com/github/rocketraman/bootable/leader/k8s/KubernetesLeaderElectionWiringTest.kt @@ -14,6 +14,8 @@ import com.github.rocketraman.bootable.client.http.ktor.KtorClientService import com.github.rocketraman.bootable.client.http.ktor.koin.ktorClientModule as koinKtorClientModule import com.github.rocketraman.bootable.client.http.ktor.ktorClientModule import com.github.rocketraman.bootable.client.http.ktor.setOfNamedClientDefaults +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule import com.github.rocketraman.bootable.leader.k8s.koin.kubernetesLeaderElectionModule as koinKubernetesLeaderElectionModule import dev.zacsweers.metro.BindingContainer @@ -59,7 +61,7 @@ object EngineBindings { /** An application's module, composed as an Inara application composes it. */ @DIModule(composed = true) -interface InaraTestModule : ConfigModule, BootableModule, KtorClientModule, KubernetesLeaderElectionModule +interface InaraTestModule : ConfigModule, BootableModule, ClockModule, KtorClientModule, KubernetesLeaderElectionModule /** The election stops, releasing its Lease, before the HTTP clients close. */ private suspend fun checkOrder(services: Set) { @@ -147,6 +149,7 @@ val KubernetesLeaderElectionWiringTest by testSuite { val module = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), ktorClientModule = ktorClientModule(JavaClientEngine()), kubernetesLeaderElectionModule = kubernetesLeaderElectionModule(), ) diff --git a/boot-periodic/src/inara/kotlin/com/github/rocketraman/bootable/periodic/PeriodicModule.kt b/boot-periodic/src/inara/kotlin/com/github/rocketraman/bootable/periodic/PeriodicModule.kt index 5038048a..ebc7aa4e 100644 --- a/boot-periodic/src/inara/kotlin/com/github/rocketraman/bootable/periodic/PeriodicModule.kt +++ b/boot-periodic/src/inara/kotlin/com/github/rocketraman/bootable/periodic/PeriodicModule.kt @@ -2,12 +2,12 @@ package com.github.rocketraman.bootable.periodic +import com.github.rocketraman.bootable.clock.ClockModule import com.github.rocketraman.bootable.leader.LeaderElectionModule import com.github.rocketraman.bootable.telemetry.otel.OpenTelemetryApiModule import org.kodein.di.inara.Binding import org.kodein.di.inara.DIModule import org.kodein.di.inara.DISet -import kotlin.time.Clock /** Marks a module member as one of the [PeriodicRunInterceptor]s of the application's periodic services. */ @DISet(of = PeriodicRunInterceptor::class) @@ -23,6 +23,7 @@ annotation class PeriodicRunInterceptors * - each run is traced, with [periodicTracing], through the OpenTelemetry of the [OpenTelemetryApiModule] it requires, * which with the `NoopOpenTelemetryModule` records nothing. * - their interceptors are the tracing, outermost, then the members marked [PeriodicRunInterceptors]. + * - they're timed by the clock of the [ClockModule] it requires. * * Add each loop to the application's services: * @@ -32,13 +33,15 @@ annotation class PeriodicRunInterceptors * ``` */ @DIModule(sets = [PeriodicRunInterceptors::class]) -interface PeriodicModule : @DIModule.Required LeaderElectionModule, @DIModule.Required OpenTelemetryApiModule { +interface PeriodicModule : + @DIModule.Required LeaderElectionModule, + @DIModule.Required OpenTelemetryApiModule, + @DIModule.Required ClockModule { val periodicServices: PeriodicServices } -/** A [PeriodicModule] on [clock], with each run traced as [tracingOptions] says. */ +/** A [PeriodicModule], with each run traced as [tracingOptions] says. */ fun periodicModule( - clock: Clock = Clock.System, tracingOptions: PeriodicTracingOptions = PeriodicTracingOptions(), ): PeriodicModulePart = PeriodicModulePart( periodicServices = Binding.single { diff --git a/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicTracingTest.kt b/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicTracingTest.kt index 98003d83..bc44cb69 100644 --- a/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicTracingTest.kt +++ b/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicTracingTest.kt @@ -10,6 +10,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule @@ -114,7 +116,8 @@ object TracingTestBindings { /** An application's module, composed as an Inara application composes it, with the SDK and a loop to trace. */ @DIModule(composed = true) -interface InaraTracingModule : ConfigModule, BootableModule, OpenTelemetryModule, LeaderElectionModule, PeriodicModule { +interface InaraTracingModule : + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, LeaderElectionModule, PeriodicModule { @OpenTelemetryCustomizers val inMemorySpans: OpenTelemetryCustomizer @AppServices val tracedLoop: PeriodicAppService } @@ -126,6 +129,7 @@ private fun inaraTracingModule( InaraTracingModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), leaderElectionModule = AlwaysLeaderModule, periodicModule = periodicModule(tracingOptions = tracingOptions), diff --git a/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicWiringTest.kt b/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicWiringTest.kt index c246caa2..8e69e70f 100644 --- a/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicWiringTest.kt +++ b/boot-periodic/src/test/kotlin/com/github/rocketraman/bootable/periodic/PeriodicWiringTest.kt @@ -10,6 +10,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigBinder import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.bindConfig @@ -84,7 +86,7 @@ object TestBindings { /** An application's module, composed as an Inara application composes it, with the loop the wiring creates. */ @DIModule(composed = true) interface InaraWiringModule : - ConfigModule, BootableModule, LeaderElectionModule, OpenTelemetryApiModule, PeriodicModule { + ConfigModule, BootableModule, ClockModule, LeaderElectionModule, OpenTelemetryApiModule, PeriodicModule { val counter: Counter @AppServices val counterLoop: PeriodicAppService } @@ -92,6 +94,7 @@ interface InaraWiringModule : private fun inaraWiringModule(leaderElectionModule: LeaderElectionModule) = InaraWiringModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), leaderElectionModule = leaderElectionModule, openTelemetryApiModule = NoopOpenTelemetryModule, periodicModule = periodicModule(), diff --git a/boot-scheduler-db/src/inara/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerModule.kt b/boot-scheduler-db/src/inara/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerModule.kt index a67bc638..da031aad 100644 --- a/boot-scheduler-db/src/inara/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerModule.kt +++ b/boot-scheduler-db/src/inara/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerModule.kt @@ -6,13 +6,13 @@ import com.github.kagkarlsson.scheduler.Scheduler import com.github.kagkarlsson.scheduler.SchedulerClient import com.github.rocketraman.bootable.boot.AppServices import com.github.rocketraman.bootable.boot.HealthChecks +import com.github.rocketraman.bootable.clock.ClockModule import com.github.rocketraman.bootable.config.config import com.github.rocketraman.bootable.db.jdbc.JdbcDataSourceModule import com.github.rocketraman.bootable.telemetry.otel.OpenTelemetryApiModule import org.kodein.di.inara.Binding import org.kodein.di.inara.DIModule import org.kodein.di.inara.DISet -import kotlin.time.Clock /** Marks a module member as one of the [DbSchedulerTaskProvider]s, the application's db-scheduler tasks. */ @DISet(of = DbSchedulerTaskProvider::class) @@ -29,22 +29,25 @@ annotation class DbSchedulerCustomizers * matches the `JdbcConfig`'s URL. * * Each execution is traced, with [dbSchedulerTracing], through the OpenTelemetry of the [OpenTelemetryApiModule] it - * requires, which with the `NoopOpenTelemetryModule` records nothing. + * requires, which with the `NoopOpenTelemetryModule` records nothing. It's timed by the clock of the [ClockModule] it + * requires. * * Add the application's tasks, recurring and one-time, with members marked [DbSchedulerTaskProviders], and adjust * db-scheduler beyond [DbSchedulerConfig] with members marked [DbSchedulerCustomizers]. */ @DIModule(sets = [DbSchedulerTaskProviders::class, DbSchedulerCustomizers::class]) -interface DbSchedulerModule : @DIModule.Required JdbcDataSourceModule, @DIModule.Required OpenTelemetryApiModule { +interface DbSchedulerModule : + @DIModule.Required JdbcDataSourceModule, + @DIModule.Required OpenTelemetryApiModule, + @DIModule.Required ClockModule { val dbSchedulerConfig: DbSchedulerConfig @AppServices val dbSchedulerService: DbSchedulerService val scheduler: Scheduler get() = dbSchedulerService.scheduler val schedulerClient: SchedulerClient get() = scheduler } -/** A [DbSchedulerModule] on [clock], with each execution traced as [tracingOptions] says. */ +/** A [DbSchedulerModule], with each execution traced as [tracingOptions] says. */ fun dbSchedulerModule( - clock: Clock = Clock.System, tracingOptions: DbSchedulerTracingOptions = DbSchedulerTracingOptions(), ): DbSchedulerModulePart = DbSchedulerModulePart( dbSchedulerConfig = config("db.scheduler"), diff --git a/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerTracingTest.kt b/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerTracingTest.kt index 86558dec..d2cc3f03 100644 --- a/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerTracingTest.kt +++ b/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerTracingTest.kt @@ -13,6 +13,8 @@ import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices import com.github.rocketraman.bootable.boot.startPlan +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule @@ -185,6 +187,7 @@ object TracingTestBindings { interface InaraTracingTestModule : ConfigModule, BootableModule, + ClockModule, OpenTelemetryModule, JdbcDataSourceModule, HikariPoolModule, @@ -197,6 +200,7 @@ interface InaraTracingTestModule : private fun inaraTracingTestModule() = InaraTracingTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), jdbcDataSourceModule = jdbcDataSourceModule(SqliteConfigSource), hikariPoolModule = hikariPoolModule(), diff --git a/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerWiringTest.kt b/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerWiringTest.kt index 1fb2dd35..0e73835e 100644 --- a/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerWiringTest.kt +++ b/boot-scheduler-db/src/test/kotlin/com/github/rocketraman/bootable/scheduler/db/DbSchedulerWiringTest.kt @@ -14,6 +14,8 @@ import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices import com.github.rocketraman.bootable.boot.startPlan +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.config @@ -87,6 +89,7 @@ object TestBindings { interface InaraWiringTestModule : ConfigModule, BootableModule, + ClockModule, OpenTelemetryApiModule, JdbcDataSourceModule, HikariPoolModule, @@ -99,6 +102,7 @@ interface InaraWiringTestModule : private fun inaraWiringTestModule() = InaraWiringTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryApiModule = NoopOpenTelemetryModule, jdbcDataSourceModule = jdbcDataSourceModule(SqliteConfigSource), hikariPoolModule = hikariPoolModule(), diff --git a/boot-server-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/server/http/ktor/KtorTelemetryTest.kt b/boot-server-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/server/http/ktor/KtorTelemetryTest.kt index 35939aff..89c27bee 100644 --- a/boot-server-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/server/http/ktor/KtorTelemetryTest.kt +++ b/boot-server-http-ktor-otel/src/test/kotlin/com/github/rocketraman/bootable/server/http/ktor/KtorTelemetryTest.kt @@ -10,6 +10,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.boot.startPlan @@ -402,6 +404,7 @@ object TestTelemetryBindings { interface InaraTestModule : ConfigModule, BootableModule, + ClockModule, OpenTelemetryModule, PrometheusTelemetryModule, KtorServerEngineModule, @@ -488,6 +491,7 @@ val KtorTelemetryWiringTest by testSuite { val module = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), prometheusTelemetryModule = prometheusTelemetryModule(), ktorServerEngineModule = NoKtorServerEngineModule, diff --git a/boot-telemetry-otel-gcp/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/GcpTelemetryTest.kt b/boot-telemetry-otel-gcp/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/GcpTelemetryTest.kt index 4f578686..09c40527 100644 --- a/boot-telemetry-otel-gcp/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/GcpTelemetryTest.kt +++ b/boot-telemetry-otel-gcp/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/GcpTelemetryTest.kt @@ -7,6 +7,8 @@ import com.github.rocketraman.bootable.boot.BootableGraph import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.config @@ -145,7 +147,7 @@ interface TestGraph : BootableGraph { /** An application's module, composed as an Inara application composes it. */ @DIModule(composed = true) -interface InaraTestModule : ConfigModule, BootableModule, OpenTelemetryModule, GcpTelemetryModule +interface InaraTestModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, GcpTelemetryModule private val expectedConfig = GcpTelemetryConfig(detectResource = false, projectId = "wiring-project") @@ -193,6 +195,7 @@ val GcpTelemetryWiringTest by testSuite { val module = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), gcpTelemetryModule = gcpTelemetryModule(), ) diff --git a/boot-telemetry-otel-micrometer-bridge/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/MicrometerBridgeTest.kt b/boot-telemetry-otel-micrometer-bridge/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/MicrometerBridgeTest.kt index 22b5fc85..373e4d2f 100644 --- a/boot-telemetry-otel-micrometer-bridge/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/MicrometerBridgeTest.kt +++ b/boot-telemetry-otel-micrometer-bridge/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/MicrometerBridgeTest.kt @@ -7,6 +7,8 @@ import com.github.rocketraman.bootable.boot.BootableGraph import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule @@ -64,7 +66,7 @@ object TestMetricsBindings { /** An application's module, composed as an Inara application composes it, with the SDK's metrics kept in memory. */ @DIModule(composed = true) -interface InaraTestModule : ConfigModule, BootableModule, OpenTelemetryModule, MicrometerBridgeModule { +interface InaraTestModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, MicrometerBridgeModule { @OpenTelemetryCustomizers val inMemoryMetrics: InMemoryMetrics } @@ -139,6 +141,7 @@ val MicrometerBridgeTest by testSuite { val module = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), micrometerBridgeModule = micrometerBridgeModule(), inMemoryMetrics = Binding.single { InMemoryMetrics() }, diff --git a/boot-telemetry-otel-prometheus/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/PrometheusTelemetryTest.kt b/boot-telemetry-otel-prometheus/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/PrometheusTelemetryTest.kt index 996cbebc..377476dd 100644 --- a/boot-telemetry-otel-prometheus/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/PrometheusTelemetryTest.kt +++ b/boot-telemetry-otel-prometheus/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/PrometheusTelemetryTest.kt @@ -9,6 +9,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.config @@ -46,7 +48,7 @@ interface TestGraph : BootableGraph { /** An application's module, composed as an Inara application composes it. */ @DIModule(composed = true) -interface InaraTestModule : ConfigModule, BootableModule, OpenTelemetryModule, PrometheusTelemetryModule +interface InaraTestModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, PrometheusTelemetryModule private val CHANNEL = AttributeKey.stringKey("channel") private val URL_PATH = AttributeKey.stringKey("url.path") @@ -218,6 +220,7 @@ val PrometheusTelemetryTest by testSuite { val module = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), prometheusTelemetryModule = prometheusTelemetryModule(), ) diff --git a/boot-telemetry-otel-signoz/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/SigNozTelemetryTest.kt b/boot-telemetry-otel-signoz/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/SigNozTelemetryTest.kt index 815cf84f..f14af277 100644 --- a/boot-telemetry-otel-signoz/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/SigNozTelemetryTest.kt +++ b/boot-telemetry-otel-signoz/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/SigNozTelemetryTest.kt @@ -7,6 +7,8 @@ import com.github.rocketraman.bootable.boot.BootableGraph import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.Masked @@ -149,7 +151,7 @@ interface TestGraph : BootableGraph { /** An application's module, composed as an Inara application composes it. */ @DIModule(composed = true) -interface InaraTestModule : ConfigModule, BootableModule, OpenTelemetryModule, SigNozTelemetryModule +interface InaraTestModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, SigNozTelemetryModule private val expectedConfig = SigNozTelemetryConfig(ingestionKey = Masked("wiring-key"), temporality = MetricsTemporality.Delta) @@ -197,6 +199,7 @@ val SigNozTelemetryWiringTest by testSuite { val module = InaraTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), sigNozTelemetryModule = sigNozTelemetryModule(), ) diff --git a/boot-telemetry-otel/src/inara/kotlin/com/github/rocketraman/bootable/telemetry/otel/OpenTelemetryModule.kt b/boot-telemetry-otel/src/inara/kotlin/com/github/rocketraman/bootable/telemetry/otel/OpenTelemetryModule.kt index e209d1ed..c38c1644 100644 --- a/boot-telemetry-otel/src/inara/kotlin/com/github/rocketraman/bootable/telemetry/otel/OpenTelemetryModule.kt +++ b/boot-telemetry-otel/src/inara/kotlin/com/github/rocketraman/bootable/telemetry/otel/OpenTelemetryModule.kt @@ -4,12 +4,12 @@ package com.github.rocketraman.bootable.telemetry.otel import com.github.rocketraman.bootable.boot.AppServices import com.github.rocketraman.bootable.boot.LifecycleControllers +import com.github.rocketraman.bootable.clock.ClockModule import com.github.rocketraman.bootable.config.ConfigModule import io.opentelemetry.api.OpenTelemetry import org.kodein.di.inara.Binding import org.kodein.di.inara.DIModule import org.kodein.di.inara.DISet -import kotlin.time.Clock /** Marks a module member as one of the [OpenTelemetryCustomizer]s of the application's OpenTelemetry SDK. */ @DISet(of = OpenTelemetryCustomizer::class) @@ -33,15 +33,19 @@ annotation class MetricsSnapshotProviders * ``` * * The scrape endpoints of pulled metrics backends are its [MetricsSnapshotProviders], for an HTTP integration to serve. + * + * The SDK's clock is the clock of the [ClockModule] it requires. A test sets the time of the telemetry with a + * `clockModule(testClock)`. */ @DIModule(sets = [OpenTelemetryCustomizers::class, MetricsSnapshotProviders::class]) -interface OpenTelemetryModule : OpenTelemetryApiModule, @DIModule.Required ConfigModule { +interface OpenTelemetryModule : + OpenTelemetryApiModule, @DIModule.Required ConfigModule, @DIModule.Required ClockModule { val telemetryConfig: TelemetryConfig @AppServices val openTelemetryService: OpenTelemetryService } -/** An [OpenTelemetryModule], whose SDK's clock is [clock]: pass a fixed clock in a test to set the time of the telemetry. */ -fun openTelemetryModule(clock: Clock = Clock.System): OpenTelemetryModulePart = OpenTelemetryModulePart( +/** An [OpenTelemetryModule]. */ +fun openTelemetryModule(): OpenTelemetryModulePart = OpenTelemetryModulePart( // qualified: the telemetryConfig member shadows the top-level function telemetryConfig = Binding.single { com.github.rocketraman.bootable.telemetry.otel.telemetryConfig(configBinder) }, openTelemetryService = Binding.single { @@ -56,10 +60,10 @@ fun openTelemetryModule(clock: Clock = Clock.System): OpenTelemetryModulePart = * [OpenTelemetryApiModule] it requires. */ @DIModule -interface ServiceStartTracingModule : @DIModule.Required OpenTelemetryApiModule { +interface ServiceStartTracingModule : @DIModule.Required OpenTelemetryApiModule, @DIModule.Required ClockModule { @LifecycleControllers val serviceStartTracing: ServiceStartTracing } -/** A [ServiceStartTracingModule], whose spans are timed by [clock], as [openTelemetryModule]'s are. */ -fun serviceStartTracingModule(clock: Clock = Clock.System): ServiceStartTracingModulePart = +/** A [ServiceStartTracingModule], whose spans are timed by the clock of the [ClockModule] it requires. */ +fun serviceStartTracingModule(): ServiceStartTracingModulePart = ServiceStartTracingModulePart(serviceStartTracing = Binding.single { ServiceStartTracing(openTelemetry, clock) }) diff --git a/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/ServiceStartTracingTest.kt b/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/ServiceStartTracingTest.kt index 8f3d27b5..a23beff4 100644 --- a/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/ServiceStartTracingTest.kt +++ b/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/ServiceStartTracingTest.kt @@ -15,6 +15,8 @@ import com.github.rocketraman.bootable.boot.StartupTimeline import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfLifecycleControllers +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule @@ -78,15 +80,17 @@ object ClockedTestBindings { /** An application's module, composed as an Inara application composes it, tracing its start. */ @DIModule(composed = true) -interface InaraStartTracingModule : ConfigModule, BootableModule, OpenTelemetryModule, ServiceStartTracingModule { +interface InaraStartTracingModule : + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, ServiceStartTracingModule { @OpenTelemetryCustomizers val inMemoryTelemetry: InMemoryTelemetry } private fun inaraStartTracingModule(clock: Clock = Clock.System) = InaraStartTracingModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), - openTelemetryModule = openTelemetryModule(clock), - serviceStartTracingModule = serviceStartTracingModule(clock), + clockModule = clockModule(clock), + openTelemetryModule = openTelemetryModule(), + serviceStartTracingModule = serviceStartTracingModule(), inMemoryTelemetry = Binding.single { InMemoryTelemetry() }, ) diff --git a/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/TelemetryWiringTest.kt b/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/TelemetryWiringTest.kt index 96f773c2..3ec03e49 100644 --- a/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/TelemetryWiringTest.kt +++ b/boot-telemetry-otel/src/test/kotlin/com/github/rocketraman/bootable/telemetry/otel/TelemetryWiringTest.kt @@ -9,6 +9,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.Masked @@ -60,7 +62,7 @@ object TestTelemetryBindings { /** An application's module, composed as an Inara application composes it, with the SDK's telemetry kept in memory. */ @DIModule(composed = true) -interface InaraTelemetryModule : ConfigModule, BootableModule, OpenTelemetryModule { +interface InaraTelemetryModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule { @OpenTelemetryCustomizers val inMemoryTelemetry: InMemoryTelemetry } @@ -69,6 +71,7 @@ internal fun inaraTelemetryModule( ) = InaraTelemetryModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule, inMemoryTelemetry = Binding.single { InMemoryTelemetry() }, ) diff --git a/boot-test-otel/src/test/kotlin/com/github/rocketraman/bootable/test/InMemoryTelemetryTest.kt b/boot-test-otel/src/test/kotlin/com/github/rocketraman/bootable/test/InMemoryTelemetryTest.kt index 3bf5c57b..3955688a 100644 --- a/boot-test-otel/src/test/kotlin/com/github/rocketraman/bootable/test/InMemoryTelemetryTest.kt +++ b/boot-test-otel/src/test/kotlin/com/github/rocketraman/bootable/test/InMemoryTelemetryTest.kt @@ -7,6 +7,8 @@ import com.github.rocketraman.bootable.boot.BootableGraph import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.koin.bootableModule as koinBootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.koin.hopliteConfigModule as koinHopliteConfigModule @@ -52,7 +54,8 @@ internal interface TelemetryGraph : BootableGraph { /** A test's module, composed as an Inara application composes it, with the in-memory telemetry. */ @DIModule(composed = true) -internal interface InaraTelemetryModule : ConfigModule, BootableModule, OpenTelemetryModule, InMemoryTelemetryModule +internal interface InaraTelemetryModule : + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, InMemoryTelemetryModule val InMemoryTelemetryTest by testSuite { test("collects the spans and metrics of the SDK it customizes, timed by the SDK's clock") { @@ -119,7 +122,8 @@ val InMemoryTelemetryTest by testSuite { val module = InaraTelemetryModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), - openTelemetryModule = openTelemetryModule(TestClock()), + clockModule = clockModule(TestClock()), + openTelemetryModule = openTelemetryModule(), inMemoryTelemetryModule = inMemoryTelemetryModule(), ) diff --git a/build.gradle.kts b/build.gradle.kts index 6f211d55..c5ab0e47 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -936,6 +936,8 @@ project("boot-leader-k8s") { "koinApi"(project(path = ":boot-client-http-ktor", configuration = "koinElements")) "inaraApi"(project(path = ":boot-client-http-ktor", configuration = "inaraElements")) "inaraApi"(project(path = ":boot-leader-common", configuration = "inaraElements")) + // the inara flavor requires the ClockModule, for the application's clock + "inaraApi"(project(path = ":boot-clock", configuration = "inaraElements")) // the election runs against a fake API server, through the Java engine testImplementation(project(":boot-client-http-ktor-java")) @@ -981,6 +983,8 @@ project("boot-periodic") { // the inara flavor requires a LeaderElectionModule and an OpenTelemetryApiModule "inaraApi"(project(path = ":boot-leader-common", configuration = "inaraElements")) "inaraApi"(project(path = ":boot-telemetry-otel-common", configuration = "inaraElements")) + // the inara flavor requires the ClockModule, for the application's clock + "inaraApi"(project(path = ":boot-clock", configuration = "inaraElements")) // the tests exercise this module's kodein, koin, metro, and inara flavors too, wired up as a consumer would testImplementation(project(path = ":boot", configuration = "kodeinElements")) @@ -1031,6 +1035,8 @@ project("boot-scheduler-db") { "koinApi"(project(path = ":boot-db-jdbc", configuration = "koinElements")) "inaraApi"(project(path = ":boot-db-jdbc", configuration = "inaraElements")) "inaraApi"(project(path = ":boot-telemetry-otel-common", configuration = "inaraElements")) + // the inara flavor requires the ClockModule, for the application's clock + "inaraApi"(project(path = ":boot-clock", configuration = "inaraElements")) // the tests run the scheduler against real databases, migrated by Flyway with this module's migrations: SQLite, // and PostgreSQL and MySQL in containers, which are skipped where Docker is unavailable, outside CI @@ -1222,6 +1228,8 @@ project("boot-telemetry-otel") { "inaraApi"(project(path = ":boot", configuration = "inaraElements")) "inaraApi"(project(path = ":boot-config-common", configuration = "inaraElements")) "inaraApi"(project(path = ":boot-telemetry-otel-common", configuration = "inaraElements")) + // the inara flavor requires the ClockModule, for the application's clock + "inaraApi"(project(path = ":boot-clock", configuration = "inaraElements")) testImplementation(rootProject.libs.opentelemetry.sdk.testing) // to check that log events in a span get its trace and span ids, as Bootable's layouts expect diff --git a/docs/modules/background/pages/periodic.adoc b/docs/modules/background/pages/periodic.adoc index 3fa77cf3..5f48a066 100644 --- a/docs/modules/background/pages/periodic.adoc +++ b/docs/modules/background/pages/periodic.adoc @@ -151,6 +151,8 @@ Compose `periodicModule()`, which provides `PeriodicServices`, and mark each loo ---- include::ROOT:example$inara/background/Periodic.kt[tag=wire] ---- ++ +Its clock is that of the `ClockModule` it requires, from xref:clock:index.adoc[`boot-clock`]. ====== A loop that needs another gate passes it to `create`, in place of the shared one. diff --git a/docs/modules/clock/pages/index.adoc b/docs/modules/clock/pages/index.adoc index c38c7520..2683bb35 100644 --- a/docs/modules/clock/pages/index.adoc +++ b/docs/modules/clock/pages/index.adoc @@ -88,7 +88,7 @@ Compose `clockModule(clock)`, a `ClockModule` that provides both clocks, `Clock. include::ROOT:example$inara/clock/Clock.kt[tag=wire] ---- + -Inara has no optional bindings, so Bootable's Inara modules take their clock as a builder parameter, such as `periodicModule(clock)`: pass them the same clock. +Bootable's Inara modules that need a clock, such as `periodicModule()`, require the `ClockModule` too, so they take their time from the same clock. ====== == Test diff --git a/docs/modules/telemetry/pages/index.adoc b/docs/modules/telemetry/pages/index.adoc index d473458f..987a1dfe 100644 --- a/docs/modules/telemetry/pages/index.adoc +++ b/docs/modules/telemetry/pages/index.adoc @@ -140,7 +140,7 @@ include::ROOT:example$inara/telemetry/Wiring.kt[tag=wire] ---- ====== -A `kotlin.time.Clock`, if one is given to `OpenTelemetryService` and `ServiceStartTracing`, or bound with Kodein, Koin, or Metro, or given to the Inara modules' builders, is the time of the spans and measurements, such as a fixed clock in a test; otherwise it is `Clock.System`. +A `kotlin.time.Clock`, if one is given to `OpenTelemetryService` and `ServiceStartTracing`, or bound with Kodein, Koin, or Metro, or composed with `clockModule(clock)` with Inara, is the time of the spans and measurements, such as a fixed clock in a test; otherwise it is `Clock.System`. When the OpenTelemetry Java agent is attached, it has already built and registered the process's SDK: `openTelemetry` is then the agent's, the config and customizers are ignored, and the agent owns the SDK's lifecycle. diff --git a/docs/modules/testing/pages/index.adoc b/docs/modules/testing/pages/index.adoc index 7bec6943..81e3c650 100644 --- a/docs/modules/testing/pages/index.adoc +++ b/docs/modules/testing/pages/index.adoc @@ -59,7 +59,7 @@ It starts at `TestClock.DEFAULT_START`, 2026-01-01T00:00:00Z, so a test's times include::ROOT:example$vanilla/testing/Helpers.kt[tag=clock] ---- -Pass it to whatever takes a `Clock`, such as `OpenTelemetryService`, `ServiceStartTracing`, or `PeriodicAppService`, or, with Kodein, Koin, or Metro, bind it as the `Clock`, which they then take their time from; with Inara, which has no optional bindings, pass it to each module's builder, such as `openTelemetryModule(clock)`. +Pass it to whatever takes a `Clock`, such as `OpenTelemetryService`, `ServiceStartTracing`, or `PeriodicAppService`, or, with Kodein, Koin, or Metro, bind it as the `Clock`, which they then take their time from; with Inara, compose `clockModule(clock)`, from `boot-clock`, which the modules that need a clock require. With xref:clock:index.adoc[`boot-clock`], give it to the application in place of the bound clock, which makes it the application's `java.time.Clock` too; `asJavaClock()` is it as a `java.time.Clock`, for a class that takes one. For a monotonic `TimeSource`, use the standard library's `kotlin.time.TestTimeSource`. @@ -297,7 +297,7 @@ With Kodein, Koin, Metro, and Inara, the SDK's config comes from the test's reso * `resetSpans()`: forgets the spans ended so far, such as those of what the test set up, so it sees only its own. * `spanExporter` and `metricReader`: OpenTelemetry's in-memory exporter and reader, for anything else. -A `TestClock`, passed to `OpenTelemetryService` or bound as the `Clock`, is the SDK's clock, so the spans' and measurements' times are the test's. +A `TestClock`, passed to `OpenTelemetryService`, bound as the `Clock`, or, with Inara, composed with `clockModule(clock)`, is the SDK's clock, so the spans' and measurements' times are the test's. See xref:telemetry:index.adoc#customizers[] for the SDK's customizers. [#example] diff --git a/docs/snippets/inara/src/main/kotlin/snippets/background/Leader.kt b/docs/snippets/inara/src/main/kotlin/snippets/background/Leader.kt index 40880a38..83bc3e15 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/background/Leader.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/background/Leader.kt @@ -5,6 +5,8 @@ import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.client.http.ktor.CioClientEngine import com.github.rocketraman.bootable.client.http.ktor.KtorClientModule import com.github.rocketraman.bootable.client.http.ktor.ktorClientModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.leader.k8s.KubernetesLeaderElectionModule @@ -18,7 +20,7 @@ import org.kodein.di.inara.DIModule // tag::wire[] @DIModule(composed = true) interface LeaderAppModule : - ConfigModule, BootableModule, KtorClientModule, KubernetesLeaderElectionModule, OpenTelemetryApiModule, + ConfigModule, BootableModule, ClockModule, KtorClientModule, KubernetesLeaderElectionModule, OpenTelemetryApiModule, PeriodicModule { // ... and the loops } @@ -26,6 +28,7 @@ interface LeaderAppModule : fun leaderAppModule() = LeaderAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), ktorClientModule = ktorClientModule(CioClientEngine()), // the HTTP clients, from http.client, on that engine // the LeaderElectionModule, from leader.kubernetes; it requires the KtorClientModule, to call the API server kubernetesLeaderElectionModule = kubernetesLeaderElectionModule(), diff --git a/docs/snippets/inara/src/main/kotlin/snippets/background/Periodic.kt b/docs/snippets/inara/src/main/kotlin/snippets/background/Periodic.kt index 290b742e..89c852db 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/background/Periodic.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/background/Periodic.kt @@ -3,6 +3,8 @@ package snippets.background import com.github.rocketraman.bootable.boot.AppServices import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.config import com.github.rocketraman.bootable.config.hopliteConfigModule @@ -19,7 +21,7 @@ import org.kodein.di.inara.DIModule // tag::wire[] @DIModule(composed = true) interface PeriodicAppModule : - ConfigModule, BootableModule, LeaderElectionModule, OpenTelemetryApiModule, PeriodicModule { + ConfigModule, BootableModule, ClockModule, LeaderElectionModule, OpenTelemetryApiModule, PeriodicModule { val notifications: Notifications @AppServices val notificationsLoop: PeriodicAppService } @@ -27,6 +29,7 @@ interface PeriodicAppModule : fun periodicAppModule() = PeriodicAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), leaderElectionModule = AlwaysLeaderModule, // required: every instance runs the loops openTelemetryApiModule = NoopOpenTelemetryModule, // required: no tracing of the runs periodicModule = periodicModule(), // periodicServices, gated on the leaderElection diff --git a/docs/snippets/inara/src/main/kotlin/snippets/background/Scheduler.kt b/docs/snippets/inara/src/main/kotlin/snippets/background/Scheduler.kt index 8becf50a..e5d38402 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/background/Scheduler.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/background/Scheduler.kt @@ -2,6 +2,8 @@ package snippets.background import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.db.flyway.FlywayMigrationModule @@ -22,7 +24,7 @@ import org.kodein.di.inara.DIModule // tag::wire[] @DIModule(composed = true) interface SchedulerAppModule : - ConfigModule, BootableModule, JdbcDataSourceModule, HikariPoolModule, FlywayMigrationModule, + ConfigModule, BootableModule, ClockModule, JdbcDataSourceModule, HikariPoolModule, FlywayMigrationModule, OpenTelemetryApiModule, DbSchedulerModule { val notifications: Notifications @DbSchedulerTaskProviders val reminders: Reminders // its tasks, to the scheduler @@ -33,6 +35,7 @@ interface SchedulerAppModule : fun schedulerAppModule() = SchedulerAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), jdbcDataSourceModule = jdbcDataSourceModule(SqliteConfigSource), hikariPoolModule = hikariPoolModule(), flywayMigrationModule = flywayMigrationModule(), // migrates the scheduler's table diff --git a/docs/snippets/inara/src/main/kotlin/snippets/background/Tracing.kt b/docs/snippets/inara/src/main/kotlin/snippets/background/Tracing.kt index fe25d255..1276e9a3 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/background/Tracing.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/background/Tracing.kt @@ -2,6 +2,8 @@ package snippets.background import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.db.jdbc.HikariPoolModule @@ -26,11 +28,12 @@ import org.kodein.di.inara.DIModule @DIModule(composed = true) interface TracedPeriodicAppModule : // OpenTelemetryModule in place of OpenTelemetryApiModule: it is one, with the SDK - ConfigModule, BootableModule, LeaderElectionModule, OpenTelemetryModule, PeriodicModule + ConfigModule, BootableModule, ClockModule, LeaderElectionModule, OpenTelemetryModule, PeriodicModule fun tracedPeriodicAppModule() = TracedPeriodicAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), leaderElectionModule = AlwaysLeaderModule, // the application's OpenTelemetry, from boot-telemetry-otel: periodicModule traces each run openTelemetryModule = openTelemetryModule(), @@ -41,6 +44,7 @@ fun tracedPeriodicAppModule() = TracedPeriodicAppModule( fun alwaysSampledPeriodicAppModule() = TracedPeriodicAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), leaderElectionModule = AlwaysLeaderModule, openTelemetryModule = openTelemetryModule(), // tag::periodic-options[] @@ -53,11 +57,13 @@ fun alwaysSampledPeriodicAppModule() = TracedPeriodicAppModule( @DIModule(composed = true) interface TracedSchedulerAppModule : // OpenTelemetryModule in place of OpenTelemetryApiModule: it is one, with the SDK - ConfigModule, BootableModule, JdbcDataSourceModule, HikariPoolModule, OpenTelemetryModule, DbSchedulerModule + ConfigModule, BootableModule, ClockModule, JdbcDataSourceModule, HikariPoolModule, OpenTelemetryModule, + DbSchedulerModule fun tracedSchedulerAppModule() = TracedSchedulerAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), jdbcDataSourceModule = jdbcDataSourceModule(SqliteConfigSource), hikariPoolModule = hikariPoolModule(), openTelemetryModule = openTelemetryModule(), // dbSchedulerModule traces each execution @@ -68,6 +74,7 @@ fun tracedSchedulerAppModule() = TracedSchedulerAppModule( fun alwaysSampledSchedulerAppModule() = TracedSchedulerAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), jdbcDataSourceModule = jdbcDataSourceModule(SqliteConfigSource), hikariPoolModule = hikariPoolModule(), openTelemetryModule = openTelemetryModule(), diff --git a/docs/snippets/inara/src/main/kotlin/snippets/database/Tracing.kt b/docs/snippets/inara/src/main/kotlin/snippets/database/Tracing.kt index fcc75727..af4f196c 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/database/Tracing.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/database/Tracing.kt @@ -2,6 +2,8 @@ package snippets.database import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.db.jdbc.HikariPoolMetricsModule @@ -20,12 +22,13 @@ import org.kodein.di.inara.DIModule // tag::tracing[] @DIModule(composed = true) interface TracedAppModule : - ConfigModule, BootableModule, JdbcDataSourceModule, HikariPoolModule, + ConfigModule, BootableModule, ClockModule, JdbcDataSourceModule, HikariPoolModule, OpenTelemetryModule, JdbcTracingModule, HikariPoolMetricsModule fun tracedAppModule() = TracedAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), jdbcDataSourceModule = jdbcDataSourceModule(SqliteConfigSource), hikariPoolModule = hikariPoolModule(), openTelemetryModule = openTelemetryModule(), // the application's OpenTelemetry, from boot-telemetry-otel diff --git a/docs/snippets/inara/src/main/kotlin/snippets/grpc/Wiring.kt b/docs/snippets/inara/src/main/kotlin/snippets/grpc/Wiring.kt index 9d9bf64f..71ca4e8a 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/grpc/Wiring.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/grpc/Wiring.kt @@ -3,6 +3,8 @@ package snippets.grpc import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.boot import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.server.grpc.GrpcServerModule @@ -36,13 +38,14 @@ fun main() = boot { // tag::telemetry[] @DIModule(composed = true) interface TracedGrpcAppModule : - ConfigModule, BootableModule, OpenTelemetryModule, GrpcServerModule, GrpcTelemetryModule { + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, GrpcServerModule, GrpcTelemetryModule { @GrpcServices val greeterService: GreeterService } fun tracedGrpcAppModule() = TracedGrpcAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), // the application's OpenTelemetry, from boot-telemetry-otel grpcServerModule = grpcServerModule(), grpcTelemetryModule = grpcTelemetryModule(), // GrpcTelemetry, from telemetry.grpc, one of the server's customizers diff --git a/docs/snippets/inara/src/main/kotlin/snippets/http/Telemetry.kt b/docs/snippets/inara/src/main/kotlin/snippets/http/Telemetry.kt index fb321b08..845351e9 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/http/Telemetry.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/http/Telemetry.kt @@ -8,6 +8,8 @@ import com.github.rocketraman.bootable.client.http.ktor.HttpClientTelemetryModul import com.github.rocketraman.bootable.client.http.ktor.KtorClientModule import com.github.rocketraman.bootable.client.http.ktor.httpClientTelemetryModule import com.github.rocketraman.bootable.client.http.ktor.ktorClientModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.config import com.github.rocketraman.bootable.config.hopliteConfigModule @@ -27,7 +29,7 @@ import org.kodein.di.inara.DIModule // tag::server[] @DIModule(composed = true) interface TracedServerAppModule : - ConfigModule, BootableModule, OpenTelemetryModule, PrometheusTelemetryModule, + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, PrometheusTelemetryModule, KtorServerEngineModule, KtorTelemetryModule, KtorHealthModule { val serverConfig: ServerConfig @AppServices val tracedServer: TracedGreetingServer @@ -36,6 +38,7 @@ interface TracedServerAppModule : fun tracedServerAppModule() = TracedServerAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), // the application's OpenTelemetry, from boot-telemetry-otel prometheusTelemetryModule = prometheusTelemetryModule(), // a pulled backend, to scrape ktorTelemetryModule = ktorTelemetryModule(), // KtorTelemetry, from telemetry.ktor @@ -50,11 +53,13 @@ fun tracedServerAppModule() = TracedServerAppModule( // tag::client[] @DIModule(composed = true) interface TracedClientAppModule : - ConfigModule, BootableModule, OpenTelemetryModule, KtorClientModule, ClientModule, HttpClientTelemetryModule + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, KtorClientModule, ClientModule, + HttpClientTelemetryModule fun tracedClientAppModule() = TracedClientAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), ktorClientModule = ktorClientModule(CioClientEngine()), clientModule = clientModule(), diff --git a/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Exporters.kt b/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Exporters.kt index 15140924..094a5333 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Exporters.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Exporters.kt @@ -3,6 +3,8 @@ package snippets.telemetry import com.github.rocketraman.bootable.boot.AppServices import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.config import com.github.rocketraman.bootable.config.hopliteConfigModule @@ -29,7 +31,7 @@ import java.util.concurrent.Executors // tag::prometheus[] @DIModule(composed = true) interface PrometheusAppModule : - ConfigModule, BootableModule, OpenTelemetryModule, PrometheusTelemetryModule, + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, PrometheusTelemetryModule, KtorServerEngineModule, KtorTelemetryModule { val statusServerConfig: StatusServerConfig @AppServices val statusServer: StatusServer // serves the scrape at /metrics @@ -38,6 +40,7 @@ interface PrometheusAppModule : fun prometheusAppModule() = PrometheusAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), prometheusTelemetryModule = prometheusTelemetryModule(), // registers its reader, and provides the scrape ktorTelemetryModule = ktorTelemetryModule(), // KtorTelemetry, which serves it; no traces of the scrapes @@ -50,11 +53,12 @@ fun prometheusAppModule() = PrometheusAppModule( // tag::signoz[] @DIModule(composed = true) -interface SigNozAppModule : ConfigModule, BootableModule, OpenTelemetryModule, SigNozTelemetryModule +interface SigNozAppModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, SigNozTelemetryModule fun sigNozAppModule() = SigNozAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), sigNozTelemetryModule = sigNozTelemetryModule(), // from telemetry.signoz ) @@ -62,11 +66,12 @@ fun sigNozAppModule() = SigNozAppModule( // tag::gcp[] @DIModule(composed = true) -interface GcpAppModule : ConfigModule, BootableModule, OpenTelemetryModule, GcpTelemetryModule +interface GcpAppModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, GcpTelemetryModule fun gcpAppModule() = GcpAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), gcpTelemetryModule = gcpTelemetryModule(), // from telemetry.gcp ) @@ -74,13 +79,15 @@ fun gcpAppModule() = GcpAppModule( // tag::micrometer-bridge[] @DIModule(composed = true) -interface MicrometerBridgeAppModule : ConfigModule, BootableModule, OpenTelemetryModule, MicrometerBridgeModule { +interface MicrometerBridgeAppModule : + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, MicrometerBridgeModule { val workExecutor: ExecutorService } fun micrometerBridgeAppModule() = MicrometerBridgeAppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), micrometerBridgeModule = micrometerBridgeModule(), // a meterRegistry member, over the application's OpenTelemetry // e.g. a library's Micrometer binder: the executor's metrics, exported with the rest diff --git a/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Wiring.kt b/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Wiring.kt index 4b112e96..659208fd 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Wiring.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/telemetry/Wiring.kt @@ -3,6 +3,8 @@ package snippets.telemetry import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.boot import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.telemetry.otel.OpenTelemetryModule @@ -13,13 +15,14 @@ import org.kodein.di.inara.DIModule // tag::wire[] @DIModule(composed = true) -interface AppModule : ConfigModule, BootableModule, OpenTelemetryModule, ServiceStartTracingModule { +interface AppModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, ServiceStartTracingModule { // ... and the services that record telemetry, given openTelemetry } fun appModule() = AppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), // the SDK, from telemetry.sdk, as the openTelemetry member serviceStartTracingModule = serviceStartTracingModule(), // the start, as one trace ) diff --git a/docs/snippets/inara/src/main/kotlin/snippets/testing/Telemetry.kt b/docs/snippets/inara/src/main/kotlin/snippets/testing/Telemetry.kt index 13309747..3f527d02 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/testing/Telemetry.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/testing/Telemetry.kt @@ -2,6 +2,8 @@ package snippets.testing import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.bootableModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.telemetry.otel.OpenTelemetryModule @@ -14,15 +16,16 @@ import org.kodein.di.inara.DIModule // tag::telemetry[] @DIModule(composed = true) interface SessionsTestModule : - ConfigModule, BootableModule, OpenTelemetryModule, InMemoryTelemetryModule, SessionsModule + ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, InMemoryTelemetryModule, SessionsModule fun openingASessionIsTracedAndCounted() { val module = SessionsTestModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(TestClock()), // the SDK's clock, and the sessions' openTelemetryModule = openTelemetryModule(), inMemoryTelemetryModule = inMemoryTelemetryModule(), // one of the SDK's customizers - sessionsModule = sessionsModule(clock = TestClock()), + sessionsModule = sessionsModule(), ) val telemetry = module.inMemoryTelemetry diff --git a/docs/snippets/inara/src/main/kotlin/snippets/testing/Wiring.kt b/docs/snippets/inara/src/main/kotlin/snippets/testing/Wiring.kt index d83cf6dc..59feb7b5 100644 --- a/docs/snippets/inara/src/main/kotlin/snippets/testing/Wiring.kt +++ b/docs/snippets/inara/src/main/kotlin/snippets/testing/Wiring.kt @@ -5,6 +5,8 @@ import com.github.rocketraman.bootable.boot.BootableModule import com.github.rocketraman.bootable.boot.boot import com.github.rocketraman.bootable.boot.bootableModule import com.github.rocketraman.bootable.boot.setOfAppServices +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.telemetry.otel.OpenTelemetryApiModule @@ -15,28 +17,28 @@ import com.github.rocketraman.bootable.test.checkShuffledStartPlans import com.github.rocketraman.bootable.test.indexOfService import org.kodein.di.inara.Binding import org.kodein.di.inara.DIModule -import kotlin.time.Clock // tag::app[] /** The application's own module, which `main` and the tests share. */ @DIModule -interface SessionsModule : @DIModule.Required OpenTelemetryApiModule { +interface SessionsModule : @DIModule.Required OpenTelemetryApiModule, @DIModule.Required ClockModule { val sessions: Sessions @AppServices val sessionReaper: SessionReaper } -/** The clock is a setting: a parameter, which a test passes. */ -fun sessionsModule(clock: Clock = Clock.System) = SessionsModulePart( +/** The clock is the application's, from the `ClockModule`, which a test replaces. */ +fun sessionsModule() = SessionsModulePart( sessions = Binding.single { Sessions(clock, openTelemetry) }, sessionReaper = Binding.single { SessionReaper(sessions) }, ) @DIModule(composed = true) -interface AppModule : ConfigModule, BootableModule, OpenTelemetryModule, SessionsModule +interface AppModule : ConfigModule, BootableModule, ClockModule, OpenTelemetryModule, SessionsModule fun appModule() = AppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), sessionsModule = sessionsModule(), ) diff --git a/examples/server-ktor-db/inara/src/main/kotlin/App.kt b/examples/server-ktor-db/inara/src/main/kotlin/App.kt index b20b4b27..9b173f65 100644 --- a/examples/server-ktor-db/inara/src/main/kotlin/App.kt +++ b/examples/server-ktor-db/inara/src/main/kotlin/App.kt @@ -7,6 +7,8 @@ import com.github.rocketraman.bootable.client.http.ktor.HttpClientTelemetryModul import com.github.rocketraman.bootable.client.http.ktor.KtorClientModule import com.github.rocketraman.bootable.client.http.ktor.httpClientTelemetryModule import com.github.rocketraman.bootable.client.http.ktor.ktorClientModule +import com.github.rocketraman.bootable.clock.ClockModule +import com.github.rocketraman.bootable.clock.clockModule import com.github.rocketraman.bootable.config.ConfigModule import com.github.rocketraman.bootable.config.hopliteConfigModule import com.github.rocketraman.bootable.config.config @@ -93,6 +95,7 @@ fun entriesModule(): EntriesModulePart = EntriesModulePart( interface AppModule : ConfigModule, BootableModule, + ClockModule, OpenTelemetryModule, ServiceStartTracingModule, PrometheusTelemetryModule, @@ -145,6 +148,7 @@ interface AppModule : fun appModule(): AppModule = AppModule( configModule = hopliteConfigModule(), bootableModule = bootableModule(), + clockModule = clockModule(), openTelemetryModule = openTelemetryModule(), serviceStartTracingModule = serviceStartTracingModule(), prometheusTelemetryModule = prometheusTelemetryModule(),