Skip to content

Commit

Permalink
chore: Minor dependency updates (#3245)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Kleinbölting <[email protected]>
Co-authored-by: Christian Kleinbölting <[email protected]>
  • Loading branch information
3 people authored May 15, 2024
1 parent 7424aa9 commit 2bacf50
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import zio.URLayer
import zio.ZIO
import zio.ZLayer

import org.knora.webapi.testcontainers.TestContainerOps.StartableOps
import org.knora.webapi.testcontainers.TestContainerOps.toZio

final class DspIngestTestContainer extends GenericContainer[DspIngestTestContainer](s"daschswiss/dsp-ingest:latest")

Expand Down Expand Up @@ -43,5 +43,5 @@ object DspIngestTestContainer {
)

val layer: URLayer[SharedVolumes.Images, DspIngestTestContainer] =
ZLayer.scoped(ZIO.service[SharedVolumes.Images].flatMap(make(_).toZio)) >+> initDspIngest
ZLayer.scoped(ZIO.serviceWithZIO[SharedVolumes.Images](make(_).toZio)) >+> initDspIngest
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.net.http.HttpRequest.BodyPublishers
import java.net.http.HttpResponse.BodyHandlers

import org.knora.webapi.http.version.BuildInfo
import org.knora.webapi.testcontainers.TestContainerOps.StartableOps
import org.knora.webapi.testcontainers.TestContainerOps.toLayer

final class FusekiTestContainer extends GenericContainer[FusekiTestContainer](BuildInfo.fuseki) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.net.Inet6Address
import java.net.InetAddress

import org.knora.webapi.http.version.BuildInfo
import org.knora.webapi.testcontainers.TestContainerOps.StartableOps
import org.knora.webapi.testcontainers.TestContainerOps.toZio

final class SipiTestContainer
extends GenericContainer[SipiTestContainer](s"daschswiss/knora-sipi:${BuildInfo.version}") {
Expand Down Expand Up @@ -83,7 +83,7 @@ object SipiTestContainer {
)

val layer: URLayer[SharedVolumes.Images, SipiTestContainer] = {
val container = ZLayer.scoped(ZIO.service[SharedVolumes.Images].flatMap(make(_).toZio))
val container = ZLayer.scoped(ZIO.serviceWithZIO[SharedVolumes.Images](make(_).toZio))
(container >>> initSipi).orDie
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ import zio.*

object ZioTestContainers {

def toZio[T <: Startable](self: T): URIO[Scope, T] = { // using `logError.ignore` because there's no point to try to recover if starting/stopping the container fails
val acquire = ZIO.attemptBlocking(self.start()).logError.ignore.as(self)
val release = (container: T) => ZIO.attemptBlocking(container.stop()).logError.ignore
def toZio[T <: Startable](self: T): URIO[Scope, T] = {
val acquire = ZIO.attemptBlocking(self.start()).orDie.as(self)
val release = (container: T) => ZIO.succeed(container.stop())
ZIO.acquireRelease(acquire)(release)
}

def toLayer[T <: Startable: Tag](container: T): ULayer[T] =
ZLayer.scoped(toZio(container))
def toLayer[T <: Startable: Tag](self: T): ULayer[T] = ZLayer.scoped(toZio(self))
}

object TestContainerOps {
implicit final class StartableOps[T <: Startable](private val self: T) extends AnyVal {
extension [T <: Startable](self: T) {
def toZio: URIO[Scope, T] = ZioTestContainers.toZio(self)
def toLayer(implicit ev: Tag[T]): ULayer[T] = ZioTestContainers.toLayer(self)
}
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Dependencies {
val ZioMetricsConnectorsVersion = "2.3.1"
val ZioPreludeVersion = "1.0.0-RC24"
val ZioSchemaVersion = "0.2.0"
val ZioVersion = "2.0.22"
val ZioVersion = "2.1.1"

// ZIO
val zio = "dev.zio" %% "zio" % ZioVersion
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.10.0
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ addSbtPlugin("com.github.sbt" % "sbt-javaagent" % "0.1.8")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
22 changes: 6 additions & 16 deletions webapi/src/main/scala/org/knora/webapi/util/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,22 @@ object Logger {
label("spans", bracketed(spans)) +
(space + label("cause", cause).highlight).filter(LogFilter.causeNonEmpty)

private val textLogger: ZLayer[Any, Nothing, Unit] = consoleLogger(
ConsoleLoggerConfig(logFormatText, logFilter),
)

private val logFormatJson: LogFormat =
LogFormat.label("name", LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat()) +
LogFormat.default +
LogFormat.annotations +
LogFormat.spans

private val jsonLogger: ZLayer[Any, Nothing, Unit] = consoleJsonLogger(
ConsoleLoggerConfig(logFormatJson, logFilter),
)
private val textLogger: ULayer[Unit] = consoleLogger(ConsoleLoggerConfig(logFormatText, logFilter))
private val jsonLogger: ULayer[Unit] = consoleJsonLogger(ConsoleLoggerConfig(logFormatJson, logFilter))

private val useJsonLogger = sys.env.getOrElse("DSP_API_LOG_APPENDER", "TEXT") == "JSON"

private val logger: ZLayer[Any, Nothing, Unit] =
if (useJsonLogger) jsonLogger
else textLogger
private val logger: ULayer[Unit] = if (useJsonLogger) jsonLogger else textLogger

def fromEnv(): ZLayer[Any, Nothing, Unit & Unit] =
Runtime.removeDefaultLoggers >>> logger >+> Slf4jBridge.initialize
def fromEnv(): ULayer[Unit] = Runtime.removeDefaultLoggers >>> logger >+> Slf4jBridge.initialize

def json(): ZLayer[Any, Nothing, Unit & Unit] =
Runtime.removeDefaultLoggers >>> jsonLogger >+> Slf4jBridge.initialize
def json(): ULayer[Unit] = Runtime.removeDefaultLoggers >>> jsonLogger >+> Slf4jBridge.initialize

def text(): ZLayer[Any, Nothing, Unit & Unit] =
Runtime.removeDefaultLoggers >>> textLogger >+> Slf4jBridge.initialize
def text(): ULayer[Unit] = Runtime.removeDefaultLoggers >>> textLogger >+> Slf4jBridge.initialize
}

0 comments on commit 2bacf50

Please sign in to comment.