Skip to content

Commit

Permalink
chore: Update tapir to v1.8.4 (#2922)
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Nov 8, 2023
1 parent 77e144b commit 354662c
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ trait FusekiTestContainer extends GenericContainer[FusekiTestContainer] {
.map(_.map(line => line.replace("@REPOSITORY@", repositoryName)).mkString("\n"))
request = HttpRequest
.newBuilder()
.uri(baseUrl.withPath("/$/datasets").toJavaURI)
.uri(baseUrl.path("/$/datasets").toJavaURI)
.POST(BodyPublishers.ofString(fusekiConfig))
.header("Content-Type", "text/turtle; charset=utf-8")
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ object SipiTestContainer {
def portAndHost: ZIO[SipiTestContainer, Nothing, (Int, String)] = port <*> host

def resolveUrl(path: http.Path): URIO[SipiTestContainer, URL] =
ZIO.serviceWith[SipiTestContainer](_.sipiBaseUrl.withPath(path))
ZIO.serviceWith[SipiTestContainer](_.sipiBaseUrl.path(path))

def copyFileToImageFolderInContainer(prefix: String, filename: String): ZIO[SipiTestContainer, Throwable, Unit] =
ZIO.serviceWithZIO[SipiTestContainer](_.copyFileToImageFolderInContainer(prefix, filename))
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object Dependencies {
// found/added by the plugin but deleted anyway
val commonsLang3 = "org.apache.commons" % "commons-lang3" % "3.13.0"

val tapirVersion = "1.7.6"
val tapirVersion = "1.8.4"

val tapir = Seq(
"com.softwaremill.sttp.tapir" %% "tapir-pekko-http-server" % tapirVersion,
Expand Down
2 changes: 1 addition & 1 deletion webapi/scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Fetch health route status json
json=$(curl -sS --max-time 10 'http://localhost:3339/health')
json=$(curl -sS --max-time 10 'http://localhost:3333/health')
if [ $? -ne 0 ]; then
echo "Health route is not responding"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion webapi/src/main/scala/org/knora/webapi/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.knora.webapi
import zio._

import org.knora.webapi.core._
import org.knora.webapi.slice.infrastructure.MetricsServer
import org.knora.webapi.util.Logger

object Main extends ZIOApp {
Expand All @@ -30,5 +31,5 @@ object Main extends ZIOApp {
* Entrypoint of our Application
*/
override def run: ZIO[Environment with ZIOAppArgs with Scope, Any, Any] =
AppServer.make *> InstrumentationServer.make
AppServer.make *> MetricsServer.make
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final case class DspIngestClientLive(
importUrl <- ZIO.fromEither(URL.decode(s"${projectsPath(shortcode)}/import"))
token <- jwtService.createJwtForDspIngest()
request = Request
.post(Body.fromFile(fileToImport.toFile), importUrl)
.post(importUrl, Body.fromFile(fileToImport.toFile))
.addHeaders(
Headers(
Header.Authorization.Bearer(token.jwtString),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final case class ProjectImportServiceLive(
def acquire(fusekiUrl: URL, httpClient: HttpClient) =
ZIO.attempt(RDFConnectionFuseki.service(fusekiUrl.encode).httpClient(httpClient).build())
def release(connection: RDFConnection) = ZIO.attempt(connection.close()).logError.ignore
ZIO.acquireRelease(acquire(fusekiBaseUrl.withPath(s"/${config.fuseki.repositoryName}"), httpClient))(release)
ZIO.acquireRelease(acquire(fusekiBaseUrl.path(s"/${config.fuseki.repositoryName}"), httpClient))(release)
}

override def importTrigFile(file: Path): Task[Unit] = ZIO.scoped {
Expand Down Expand Up @@ -126,5 +126,5 @@ final case class ProjectImportServiceLive(
}

object ProjectImportServiceLive {
val layer = ZLayer.fromFunction(ProjectImportServiceLive.apply _)
val layer = ZLayer.derive[ProjectImportServiceLive]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.knora.webapi.core
package org.knora.webapi.slice.infrastructure

import zio._
import zio.http._
Expand All @@ -12,41 +12,28 @@ import zio.metrics.connectors.prometheus
import zio.metrics.jvm.DefaultJvmMetrics

import org.knora.webapi.config.AppConfig
import org.knora.webapi.instrumentation.health.HealthRouteZ
import org.knora.webapi.instrumentation.index.IndexApp
import org.knora.webapi.instrumentation.prometheus.PrometheusApp
import org.knora.webapi.core.State
import org.knora.webapi.slice.infrastructure.api.PrometheusApp

object InstrumentationServer {
object MetricsServer {

private val instrumentationServer =
(for {
index <- ZIO.serviceWith[IndexApp](_.route)
health <- ZIO.serviceWith[HealthRouteZ](_.route)
prometheus <- ZIO.serviceWith[PrometheusApp](_.route)
app = index ++ health ++ prometheus
_ <- Server.install(app)
} yield ()) *> ZIO.never
private val metricsServer = ZIO.serviceWithZIO[PrometheusApp](app => Server.install(app.route)) *> 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 http://localhost:$port") *>
instrumentationServer
metricsServer
.provideSome[State](
// HTTP Server
Server.defaultWithPort(port),
// HTTP routes
IndexApp.layer,
HealthRouteZ.layer,
PrometheusApp.layer,
// Metrics dependencies
prometheus.publisherLayer,
ZLayer.succeed(metricsConfig) >>> prometheus.prometheusLayer,
Runtime.enableRuntimeMetrics,
Runtime.enableFiberRoots,
DefaultJvmMetrics.live.unit
DefaultJvmMetrics.live.unit,
PrometheusApp.layer
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package org.knora.webapi.instrumentation.prometheus
package org.knora.webapi.slice.infrastructure.api

import zio._
import zio.http._
Expand All @@ -12,14 +12,9 @@ import zio.metrics.connectors.prometheus.PrometheusPublisher
/**
* Provides the '/metrics' endpoint serving the metrics in prometheus format.
*/
final case class PrometheusApp() {

val route: HttpApp[PrometheusPublisher, Nothing] =
Http
.collectZIO[Request] { case Method.GET -> Root / "metrics" =>
ZIO.serviceWithZIO[PrometheusPublisher](_.get.map(Response.text))
}
final case class PrometheusApp(prometheus: PrometheusPublisher) {
val route: HttpApp[Any] = Routes(Method.GET / "metrics" -> handler(prometheus.get.map(Response.text(_)))).toHttpApp
}
object PrometheusApp {
val layer = ZLayer.succeed(PrometheusApp())
val layer = ZLayer.derive[PrometheusApp]
}

0 comments on commit 354662c

Please sign in to comment.