1
1
package no.nav.helse.rapids_rivers
2
2
3
- import com.fasterxml.jackson.databind.ObjectMapper
4
- import com.fasterxml.jackson.databind.SerializationFeature
5
- import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
6
- import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7
3
import com.github.navikt.tbd_libs.kafka.AivenConfig
8
4
import com.github.navikt.tbd_libs.kafka.ConsumerProducerFactory
9
- import com.github.navikt.tbd_libs.naisful.NaisEndpoints
10
- import com.github.navikt.tbd_libs.naisful.defaultStatusPagesConfig
11
- import com.github.navikt.tbd_libs.naisful.naisApp
12
5
import com.github.navikt.tbd_libs.rapids_and_rivers.JsonMessage
13
6
import com.github.navikt.tbd_libs.rapids_and_rivers.KafkaRapid
14
7
import com.github.navikt.tbd_libs.rapids_and_rivers.createDefaultKafkaRapidFromEnv
@@ -18,12 +11,10 @@ import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
18
11
import io.ktor.server.application.*
19
12
import io.ktor.server.cio.*
20
13
import io.ktor.server.engine.*
21
- import io.ktor.server.plugins.statuspages.StatusPagesConfig
22
14
import io.micrometer.core.instrument.Clock
23
15
import io.micrometer.core.instrument.MeterRegistry
24
16
import io.micrometer.core.instrument.MultiGauge
25
17
import io.micrometer.core.instrument.Tags
26
- import io.micrometer.core.instrument.Timer
27
18
import io.micrometer.prometheusmetrics.PrometheusConfig
28
19
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
29
20
import io.prometheus.metrics.model.registry.PrometheusRegistry
@@ -142,9 +133,6 @@ class RapidApplication internal constructor(
142
133
env : Map <String , String >,
143
134
consumerProducerFactory : ConsumerProducerFactory = ConsumerProducerFactory (AivenConfig .default),
144
135
meterRegistry : PrometheusMeterRegistry = PrometheusMeterRegistry (PrometheusConfig .DEFAULT , PrometheusRegistry .defaultRegistry, Clock .SYSTEM ),
145
- objectMapper : ObjectMapper = jacksonObjectMapper()
146
- .registerModule(JavaTimeModule ())
147
- .disable(SerializationFeature .WRITE_DATES_AS_TIMESTAMPS ),
148
136
builder : Builder .() -> Unit = {},
149
137
configure : (EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >, KafkaRapid ) -> Unit = { _, _ -> }
150
138
): RapidsConnection {
@@ -157,8 +145,7 @@ class RapidApplication internal constructor(
157
145
appName = env[" RAPID_APP_NAME" ] ? : generateAppName(env),
158
146
instanceId = generateInstanceId(env),
159
147
rapid = kafkaRapid,
160
- meterRegistry = meterRegistry,
161
- objectMapper = objectMapper
148
+ meterRegistry = meterRegistry
162
149
)
163
150
.apply (builder)
164
151
.build(configure)
@@ -181,8 +168,7 @@ class RapidApplication internal constructor(
181
168
private val appName : String? ,
182
169
private val instanceId : String ,
183
170
private val rapid : KafkaRapid ,
184
- private val meterRegistry : PrometheusMeterRegistry ,
185
- private val objectMapper : ObjectMapper
171
+ private val meterRegistry : PrometheusMeterRegistry
186
172
) {
187
173
188
174
init {
@@ -193,12 +179,9 @@ class RapidApplication internal constructor(
193
179
private var ktor: EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >? = null
194
180
private val modules = mutableListOf<Application .() - > Unit > ()
195
181
private var naisEndpoints = NaisEndpoints .Default
196
- private var statusPagesConfig: StatusPagesConfig .() -> Unit = { defaultStatusPagesConfig() }
197
- private var callIdHeader: String = " callId"
198
182
private val isAliveChecks = mutableSetOf< () -> Boolean > (rapid::isRunning)
199
183
private val isReadyChecks = mutableSetOf< () -> Boolean > (rapid::isReady)
200
- private var timersConfig: Timer .Builder .(ApplicationCall , Throwable ? ) -> Unit = { _, _ -> }
201
- private var mdcEntries: Map <String , (ApplicationCall ) - > String? > = emptyMap()
184
+ private val stopHook = PreStopHook (rapid)
202
185
203
186
fun withHttpPort (httpPort : Int ) = apply {
204
187
this .httpPort = httpPort
@@ -208,24 +191,12 @@ class RapidApplication internal constructor(
208
191
this .ktor = ktor
209
192
}
210
193
211
- fun withKtorModule (module : Application .() -> Unit ) = apply {
212
- this .modules.add(module)
213
- }
214
-
215
- fun withStatusPagesConfig (statusPagesConfig : StatusPagesConfig .() -> Unit ) = apply {
216
- this .statusPagesConfig = statusPagesConfig
194
+ fun withKtor (ktor : (PreStopHook , KafkaRapid ) -> EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >) = apply {
195
+ this .ktor = ktor(stopHook, rapid)
217
196
}
218
197
219
- fun withTimersConfig (timersConfig : Timer .Builder .(ApplicationCall , Throwable ? ) -> Unit ) = apply {
220
- this .timersConfig = timersConfig
221
- }
222
-
223
- fun withMdcEntries (mdcEntries : Map <String , (ApplicationCall ) - > String? >) = apply {
224
- this .mdcEntries = mdcEntries
225
- }
226
-
227
- fun withCallIdHeader (headerName : String ) = apply {
228
- callIdHeader = headerName
198
+ fun withKtorModule (module : Application .() -> Unit ) = apply {
199
+ this .modules.add(module)
229
200
}
230
201
231
202
fun withIsAliveEndpoint (isAliveEndpoint : String ) = apply {
@@ -255,42 +226,30 @@ class RapidApplication internal constructor(
255
226
fun build (configure : (EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration >, KafkaRapid ) -> Unit = { _, _ -> }, cioConfiguration : CIOApplicationEngine .Configuration .() -> Unit = { } ): RapidsConnection {
256
227
val app = ktor ? : defaultKtorApp(cioConfiguration)
257
228
configure(app, rapid)
229
+ with (meterRegistry) {
230
+ val pkg = RapidApplication .javaClass.`package`
231
+ val title = pkg?.implementationTitle ? : " unknown"
232
+ val version = pkg?.implementationVersion ? : " unknown"
233
+ MultiGauge .builder(" rapids.and.rivers.info" )
234
+ .description(" Rapids and rivers version info" )
235
+ .tag(" title" , title)
236
+ .tag(" version" , version)
237
+ .register(this )
238
+ .register(listOf (MultiGauge .Row .of(Tags .of(emptyList()), 1 )))
239
+ }
258
240
return RapidApplication (app, rapid, appName, instanceId)
259
241
}
260
242
261
243
private fun defaultKtorApp (cioConfiguration : CIOApplicationEngine .Configuration .() -> Unit ): EmbeddedServer <CIOApplicationEngine , CIOApplicationEngine .Configuration > {
262
- val stopHook = PreStopHook (rapid)
263
- val applicationLogger = LoggerFactory .getLogger(RapidApplication ::class .java)
264
- return naisApp(
244
+ return ktorApplication(
265
245
meterRegistry = meterRegistry,
266
- objectMapper = objectMapper,
267
- applicationLogger = applicationLogger,
268
- callLogger = applicationLogger,
269
246
naisEndpoints = naisEndpoints,
270
- callIdHeaderName = callIdHeader,
271
247
port = httpPort,
272
248
aliveCheck = { isAliveChecks.all { it() } },
273
249
readyCheck = { isReadyChecks.all { it() } },
274
250
preStopHook = stopHook::handlePreStopRequest,
275
251
cioConfiguration = cioConfiguration,
276
- statusPagesConfig = statusPagesConfig,
277
- timersConfig = timersConfig,
278
- mdcEntries = mdcEntries,
279
- applicationModule = {
280
- modules.forEach { it() }
281
-
282
- with (meterRegistry) {
283
- val pkg = RapidApplication .javaClass.`package`
284
- val title = pkg?.implementationTitle ? : " unknown"
285
- val version = pkg?.implementationVersion ? : " unknown"
286
- MultiGauge .builder(" rapids.and.rivers.info" )
287
- .description(" Rapids and rivers version info" )
288
- .tag(" title" , title)
289
- .tag(" version" , version)
290
- .register(this )
291
- .register(listOf (MultiGauge .Row .of(Tags .of(emptyList()), 1 )))
292
- }
293
- }
252
+ modules = modules
294
253
)
295
254
}
296
255
0 commit comments