Skip to content

Commit

Permalink
install micrometer metrics in main module
Browse files Browse the repository at this point in the history
  • Loading branch information
anderssonw committed Jun 4, 2024
1 parent ec53a03 commit d04e846
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/main/kotlin/no/kartverket/matrikkel/bygning/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import no.kartverket.matrikkel.bygning.routes.v1.probeRouting
import no.kartverket.matrikkel.bygning.services.BygningService
import no.kartverket.matrikkel.bygning.services.HealthService

val appMicrometerRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)

fun main(args: Array<String>) {
embeddedServer(Netty, port = 8081, host = "0.0.0.0", module = Application::internalModule).start(wait = false)

Expand All @@ -46,23 +48,25 @@ fun Application.module() {
}
}

install(MicrometerMetrics) {
registry = appMicrometerRegistry
}

DatabaseSingleton.init()
val dbConnection = DatabaseSingleton.getConnection() ?: throw RuntimeException("Kunne ikke koble til database")
val dbConnection = DatabaseSingleton.getConnection()
val bygningRepository = BygningRepository(dbConnection)
val bygningService = BygningService(bygningRepository)

baseRoutesV1(bygningService)
}

fun Application.internalModule() {
val appMicrometerRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT)

install(MicrometerMetrics) {
registry = appMicrometerRegistry
}

DatabaseSingleton.init()
val dbConnection = DatabaseSingleton.getConnection() ?: throw RuntimeException("Kunne ikke koble til database")
val dbConnection = DatabaseSingleton.getConnection()
val healthRepository = HealthRepository(dbConnection)
val healthService = HealthService(healthRepository)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ object DatabaseSingleton {
}
}

fun getConnection(): Connection? {
return connection
fun getConnection(): Connection {
if (connection != null) {
return connection as Connection
}

throw RuntimeException("Kunne ikke koble til database")
}
}

0 comments on commit d04e846

Please sign in to comment.