Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Startup and keep instrumentation server running #2901

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion webapi/src/main/scala/org/knora/webapi/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ object Main extends ZIOApp {
* Entrypoint of our Application
*/
override def run: ZIO[Environment with ZIOAppArgs with Scope, Any, Any] =
InstrumentationServer.make *> AppServer.make *> ZIO.never
AppServer.make *> InstrumentationServer.make
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ import org.knora.webapi.instrumentation.prometheus.PrometheusApp
object InstrumentationServer {

private val instrumentationServer =
for {
(for {
index <- ZIO.serviceWith[IndexApp](_.route)
health <- ZIO.serviceWith[HealthRouteZ](_.route)
prometheus <- ZIO.serviceWith[PrometheusApp](_.route)
app = index ++ health ++ prometheus
_ <- Server.serve(app).forkDaemon
} yield ()
_ <- Server.install(app)
} yield ()) *> ZIO.never

val make: ZIO[State with AppConfig, Throwable, Unit] =
ZIO.serviceWithZIO[AppConfig] { config =>
val port = config.instrumentationServerConfig.port
val interval = config.instrumentationServerConfig.interval
val metricsConfig = MetricsConfig(interval)
ZIO.logInfo(s"Starting instrumentation http server on port: $port") *>
ZIO.logInfo(s"Starting instrumentation http server on http://localhost:$port") *>
instrumentationServer
.provideSome[State](
// HTTP Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ final case class IndexApp() {
private val indexPage =
"""<html>
|<title>Simple Server</title>
|<body>
|<p><a href="/metrics">Prometheus Metrics</a></p>
|</body
|</html>""".stripMargin
| <body>
| <p><a href="/metrics">Metrics</a></p>
| <p><a href="/health">Health</a></p>
| </body
|</html>
|""".stripMargin
}
object IndexApp {
val layer: ULayer[IndexApp] =
Expand Down