From cfb1434bfa29197e23553ef8613e18410ef395b6 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Sat, 16 Nov 2024 12:54:44 +0100 Subject: [PATCH 1/5] Bump elastic4s 8.15.4 --- project/Dependencies.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 70af931..9288e0b 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -11,7 +11,7 @@ object Dependencies { val chess = "16.2.4" val ciris = "3.6.0" val decline = "2.4.1" - val elastic4s = "8.15.3" + val elastic4s = "8.15.4" val fs2 = "3.11.0" val http4s = "0.23.29" val iron = "2.5.0" From f7776984b83cb3348c42f8755dc3c5aac9d045c9 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Mon, 18 Nov 2024 15:04:46 +0100 Subject: [PATCH 2/5] wip: use http4s client --- build.sbt | 4 +++- modules/elastic/src/main/scala/ESClient.scala | 16 ++++++++++++++++ project/Dependencies.scala | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 979c26b..e6fde8e 100644 --- a/build.sbt +++ b/build.sbt @@ -49,8 +49,10 @@ lazy val elastic = project libraryDependencies ++= Seq( catsCore, catsEffect, - elastic4sJavaClient, + http4sClient, elastic4sCatsEffect, + elastic4sJavaClient, + elastic4sHttp4sClient, otel4sCore ) ) diff --git a/modules/elastic/src/main/scala/ESClient.scala b/modules/elastic/src/main/scala/ESClient.scala index 39adde0..5caff20 100644 --- a/modules/elastic/src/main/scala/ESClient.scala +++ b/modules/elastic/src/main/scala/ESClient.scala @@ -19,6 +19,7 @@ import org.typelevel.otel4s.metrics.{ Histogram, Meter } import org.typelevel.otel4s.{ Attribute, AttributeKey, Attributes } import java.util.concurrent.TimeUnit +import org.http4s.client.Client trait ESClient[F[_]]: @@ -64,6 +65,21 @@ object ESClient: ) ) + def apply(client: Client[IO], uri: String)(using meter: Meter[IO]): Resource[IO, ESClient[IO]] = + Resource + .make(IO(ElasticClient(JavaClient(ElasticProperties(uri)))))(client => IO(client.close())) + .evalMap: esClient => + meter + .histogram[Double]("db.client.operation.duration") + .withUnit("ms") + .create + .map( + apply( + esClient, + Attributes(Attribute("db.system", "elasticsearch"), Attribute("server.address", uri)) + ) + ) + def apply[F[_]: MonadCancelThrow: Functor: Executor](client: ElasticClient, baseAttributes: Attributes)( metric: Histogram[F, Double] ) = new ESClient[F]: diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 9288e0b..9c90b21 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -50,6 +50,7 @@ object Dependencies { val playWS = "com.typesafe.play" %% "play-ahc-ws-standalone" % "2.2.10" val elastic4sJavaClient = "nl.gn0s1s" %% "elastic4s-client-esjava" % V.elastic4s + val elastic4sHttp4sClient = "nl.gn0s1s" %% "elastic4s-client-http4s" % V.elastic4s val elastic4sCatsEffect = "nl.gn0s1s" %% "elastic4s-effect-cats" % V.elastic4s val mongo4catsCore = "io.github.kirill5k" %% "mongo4cats-core" % V.mongo4cats From 925d0777ec3979b7dbc4b8c55f90c2362c192770 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Sat, 30 Nov 2024 18:02:56 +0100 Subject: [PATCH 3/5] elastic4s 8.16.0 & make it works --- .../app/src/main/scala/app.resources.scala | 12 +++++-- modules/app/src/main/scala/app.scala | 14 +++++---- .../e2e/src/test/scala/IntegrationSuite.scala | 1 + modules/elastic/src/main/scala/ESClient.scala | 31 ++++++++++--------- project/Dependencies.scala | 2 +- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/modules/app/src/main/scala/app.resources.scala b/modules/app/src/main/scala/app.resources.scala index 7560511..666115b 100644 --- a/modules/app/src/main/scala/app.resources.scala +++ b/modules/app/src/main/scala/app.resources.scala @@ -2,11 +2,19 @@ package lila.search package app import cats.effect.* +import cats.effect.unsafe.IORuntime +import org.http4s.Uri +import org.http4s.ember.client.EmberClientBuilder import org.typelevel.otel4s.metrics.Meter class AppResources(val esClient: ESClient[IO]) object AppResources: - def instance(conf: AppConfig)(using Meter[IO]): Resource[IO, AppResources] = - ESClient(conf.elastic.uri).map(AppResources.apply) + def instance(conf: AppConfig)(using Meter[IO], IORuntime): Resource[IO, AppResources] = + val uri = Uri.fromString(conf.elastic.uri).fold(throw _, identity) + EmberClientBuilder + .default[IO] + .build + .evalMap(ESClient(_, uri)) + .map(AppResources.apply) diff --git a/modules/app/src/main/scala/app.scala b/modules/app/src/main/scala/app.scala index 64019ee..7c72d02 100644 --- a/modules/app/src/main/scala/app.scala +++ b/modules/app/src/main/scala/app.scala @@ -2,6 +2,7 @@ package lila.search package app import cats.effect.* +import cats.effect.unsafe.IORuntime import cats.syntax.all.* import org.typelevel.log4cats.slf4j.Slf4jFactory import org.typelevel.log4cats.{ Logger, LoggerFactory } @@ -23,12 +24,13 @@ object App extends IOApp.Simple: for given MetricExporter.Pull[IO] <- PrometheusMetricExporter.builder[IO].build.toResource given Meter[IO] <- mkMeter - config <- AppConfig.load.toResource - _ <- Logger[IO].info(s"Starting lila-search with config: $config").toResource - _ <- RuntimeMetrics.register[IO] - _ <- IOMetrics.register[IO]() - res <- AppResources.instance(config) - _ <- mkServer(res, config) + given IORuntime = runtime + config <- AppConfig.load.toResource + _ <- Logger[IO].info(s"Starting lila-search with config: $config").toResource + _ <- RuntimeMetrics.register[IO] + _ <- IOMetrics.register[IO]() + res <- AppResources.instance(config) + _ <- mkServer(res, config) yield () def mkMeter(using exporter: MetricExporter.Pull[IO]) = SdkMetrics diff --git a/modules/e2e/src/test/scala/IntegrationSuite.scala b/modules/e2e/src/test/scala/IntegrationSuite.scala index 717a2e8..a881466 100644 --- a/modules/e2e/src/test/scala/IntegrationSuite.scala +++ b/modules/e2e/src/test/scala/IntegrationSuite.scala @@ -2,6 +2,7 @@ package lila.search package app package test +import cats.effect.unsafe.implicits.global import cats.effect.{ IO, Resource } import cats.syntax.all.* import com.comcast.ip4s.* diff --git a/modules/elastic/src/main/scala/ESClient.scala b/modules/elastic/src/main/scala/ESClient.scala index 5caff20..c634477 100644 --- a/modules/elastic/src/main/scala/ESClient.scala +++ b/modules/elastic/src/main/scala/ESClient.scala @@ -1,10 +1,12 @@ package lila.search import cats.effect.* +import cats.effect.unsafe.IORuntime import cats.syntax.all.* import com.sksamuel.elastic4s.ElasticDsl.* import com.sksamuel.elastic4s.cats.effect.instances.* import com.sksamuel.elastic4s.http.JavaClient +import com.sksamuel.elastic4s.http4s.Http4sClient import com.sksamuel.elastic4s.{ ElasticClient, ElasticDsl, @@ -15,11 +17,12 @@ import com.sksamuel.elastic4s.{ Indexable, Response } +import org.http4s.Uri +import org.http4s.client.Client import org.typelevel.otel4s.metrics.{ Histogram, Meter } import org.typelevel.otel4s.{ Attribute, AttributeKey, Attributes } import java.util.concurrent.TimeUnit -import org.http4s.client.Client trait ESClient[F[_]]: @@ -65,20 +68,18 @@ object ESClient: ) ) - def apply(client: Client[IO], uri: String)(using meter: Meter[IO]): Resource[IO, ESClient[IO]] = - Resource - .make(IO(ElasticClient(JavaClient(ElasticProperties(uri)))))(client => IO(client.close())) - .evalMap: esClient => - meter - .histogram[Double]("db.client.operation.duration") - .withUnit("ms") - .create - .map( - apply( - esClient, - Attributes(Attribute("db.system", "elasticsearch"), Attribute("server.address", uri)) - ) - ) + def apply(client: Client[IO], uri: Uri)(using Meter[IO], IORuntime): IO[ESClient[IO]] = + val elasticClient = ElasticClient(Http4sClient.usingIO(client, uri)) + Meter[IO] + .histogram[Double]("db.client.operation.duration") + .withUnit("ms") + .create + .map( + apply( + elasticClient, + Attributes(Attribute("db.system", "elasticsearch"), Attribute("server.address", uri.toString())) + ) + ) def apply[F[_]: MonadCancelThrow: Functor: Executor](client: ElasticClient, baseAttributes: Attributes)( metric: Histogram[F, Double] diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 9c90b21..5c562a5 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -11,7 +11,7 @@ object Dependencies { val chess = "16.2.4" val ciris = "3.6.0" val decline = "2.4.1" - val elastic4s = "8.15.4" + val elastic4s = "8.16.0" val fs2 = "3.11.0" val http4s = "0.23.29" val iron = "2.5.0" From 10aca4b113321f897d2d1c4a1d8cc9896d2dbeb6 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Sat, 30 Nov 2024 18:58:59 +0100 Subject: [PATCH 4/5] Remove elastic4s java dependencies --- build.sbt | 3 ++- modules/app/src/main/scala/app.config.scala | 8 +++++--- .../app/src/main/scala/app.resources.scala | 4 +--- modules/app/src/main/scala/app.scala | 14 ++++++------- modules/e2e/src/test/scala/CompatSuite.scala | 3 ++- .../test/scala/ElasticSearchContainer.scala | 2 +- modules/elastic/src/main/scala/ESClient.scala | 20 +------------------ .../ingestor/src/main/scala/app.config.scala | 9 ++++++--- .../src/main/scala/app.resources.scala | 17 ++++++++++------ modules/ingestor/src/main/scala/app.scala | 2 ++ modules/ingestor/src/main/scala/cli.scala | 2 ++ project/Dependencies.scala | 1 - 12 files changed, 40 insertions(+), 45 deletions(-) diff --git a/build.sbt b/build.sbt index e6fde8e..e9e7f70 100644 --- a/build.sbt +++ b/build.sbt @@ -51,7 +51,6 @@ lazy val elastic = project catsEffect, http4sClient, elastic4sCatsEffect, - elastic4sJavaClient, elastic4sHttp4sClient, otel4sCore ) @@ -90,12 +89,14 @@ lazy val ingestor = project declineCatsEffect, ducktape, cirisCore, + cirisHtt4s, smithy4sCore, smithy4sJson, jsoniterCore, jsoniterMacro, circe, http4sServer, + http4sEmberClient, mongo4catsCore, mongo4catsCirce, log4Cats, diff --git a/modules/app/src/main/scala/app.config.scala b/modules/app/src/main/scala/app.config.scala index 14cc1d9..01b0cc4 100644 --- a/modules/app/src/main/scala/app.config.scala +++ b/modules/app/src/main/scala/app.config.scala @@ -6,6 +6,7 @@ import cats.syntax.all.* import ciris.* import ciris.http4s.* import com.comcast.ip4s.* +import org.http4s.implicits.* object AppConfig: @@ -38,8 +39,9 @@ object HttpServerConfig: private def enableDocs = env("HTTP_ENABLE_DOCS").or(prop("http.enable.docs")).as[Boolean].default(false) def config = (host, port, logger, shutdownTimeout, enableDocs).parMapN(HttpServerConfig.apply) -case class ElasticConfig(uri: String) +case class ElasticConfig(uri: org.http4s.Uri) object ElasticConfig: - private def uri = env("ELASTIC_URI").or(prop("elastic.uri")).as[String].default("http://127.0.0.1:9200") - def config = uri.map(ElasticConfig.apply) + private def uri = + env("ELASTIC_URI").or(prop("elastic.uri")).as[org.http4s.Uri].default(uri"http://127.0.0.1:9200") + def config = uri.map(ElasticConfig.apply) diff --git a/modules/app/src/main/scala/app.resources.scala b/modules/app/src/main/scala/app.resources.scala index 666115b..a8a476f 100644 --- a/modules/app/src/main/scala/app.resources.scala +++ b/modules/app/src/main/scala/app.resources.scala @@ -3,7 +3,6 @@ package app import cats.effect.* import cats.effect.unsafe.IORuntime -import org.http4s.Uri import org.http4s.ember.client.EmberClientBuilder import org.typelevel.otel4s.metrics.Meter @@ -12,9 +11,8 @@ class AppResources(val esClient: ESClient[IO]) object AppResources: def instance(conf: AppConfig)(using Meter[IO], IORuntime): Resource[IO, AppResources] = - val uri = Uri.fromString(conf.elastic.uri).fold(throw _, identity) EmberClientBuilder .default[IO] .build - .evalMap(ESClient(_, uri)) + .evalMap(ESClient(_, conf.elastic.uri)) .map(AppResources.apply) diff --git a/modules/app/src/main/scala/app.scala b/modules/app/src/main/scala/app.scala index 7c72d02..564040a 100644 --- a/modules/app/src/main/scala/app.scala +++ b/modules/app/src/main/scala/app.scala @@ -17,6 +17,7 @@ object App extends IOApp.Simple: given LoggerFactory[IO] = Slf4jFactory.create[IO] given Logger[IO] = LoggerFactory[IO].getLogger + given IORuntime = runtime override def run: IO[Unit] = app.useForever @@ -24,13 +25,12 @@ object App extends IOApp.Simple: for given MetricExporter.Pull[IO] <- PrometheusMetricExporter.builder[IO].build.toResource given Meter[IO] <- mkMeter - given IORuntime = runtime - config <- AppConfig.load.toResource - _ <- Logger[IO].info(s"Starting lila-search with config: $config").toResource - _ <- RuntimeMetrics.register[IO] - _ <- IOMetrics.register[IO]() - res <- AppResources.instance(config) - _ <- mkServer(res, config) + config <- AppConfig.load.toResource + _ <- Logger[IO].info(s"Starting lila-search with config: $config").toResource + _ <- RuntimeMetrics.register[IO] + _ <- IOMetrics.register[IO]() + res <- AppResources.instance(config) + _ <- mkServer(res, config) yield () def mkMeter(using exporter: MetricExporter.Pull[IO]) = SdkMetrics diff --git a/modules/e2e/src/test/scala/CompatSuite.scala b/modules/e2e/src/test/scala/CompatSuite.scala index bf728b8..70d6638 100644 --- a/modules/e2e/src/test/scala/CompatSuite.scala +++ b/modules/e2e/src/test/scala/CompatSuite.scala @@ -8,6 +8,7 @@ import com.sksamuel.elastic4s.Indexable import lila.search.app.{ App, AppConfig, AppResources, ElasticConfig, HttpServerConfig } import lila.search.client.{ SearchClient, SearchError } import lila.search.spec.{ CountOutput, Query, SearchOutput } +import org.http4s.implicits.* import org.typelevel.log4cats.noop.{ NoOpFactory, NoOpLogger } import org.typelevel.log4cats.{ Logger, LoggerFactory } import org.typelevel.otel4s.metrics.Meter @@ -62,7 +63,7 @@ object CompatSuite extends weaver.IOSuite: def testAppConfig = AppConfig( server = HttpServerConfig(ip"0.0.0.0", port"9999", false, shutdownTimeout = 1, false), - elastic = ElasticConfig("http://0.0.0.0:9200") + elastic = ElasticConfig(uri"http://0.0.0.0:9200") ) def fakeClient: ESClient[IO] = new: diff --git a/modules/e2e/src/test/scala/ElasticSearchContainer.scala b/modules/e2e/src/test/scala/ElasticSearchContainer.scala index bd4975b..dee2165 100644 --- a/modules/e2e/src/test/scala/ElasticSearchContainer.scala +++ b/modules/e2e/src/test/scala/ElasticSearchContainer.scala @@ -28,7 +28,7 @@ object ElasticSearchContainer: Resource.make(start)(cont => IO(cont.stop())) def parseConfig(container: GenericContainer): ElasticConfig = - ElasticConfig(s"http://${container.host}:${container.mappedPort(PORT)}") + ElasticConfig(org.http4s.Uri.unsafeFromString(s"http://${container.host}:${container.mappedPort(PORT)}")) def start: Resource[IO, ElasticConfig] = container.map(parseConfig) diff --git a/modules/elastic/src/main/scala/ESClient.scala b/modules/elastic/src/main/scala/ESClient.scala index c634477..0af4e5c 100644 --- a/modules/elastic/src/main/scala/ESClient.scala +++ b/modules/elastic/src/main/scala/ESClient.scala @@ -5,12 +5,10 @@ import cats.effect.unsafe.IORuntime import cats.syntax.all.* import com.sksamuel.elastic4s.ElasticDsl.* import com.sksamuel.elastic4s.cats.effect.instances.* -import com.sksamuel.elastic4s.http.JavaClient import com.sksamuel.elastic4s.http4s.Http4sClient import com.sksamuel.elastic4s.{ ElasticClient, ElasticDsl, - ElasticProperties, Executor, Functor, Index as ESIndex, @@ -53,30 +51,14 @@ object ESClient: case Resource.ExitCase.Canceled => static.added(errorType, "canceled") - def apply(uri: String)(using meter: Meter[IO]): Resource[IO, ESClient[IO]] = - Resource - .make(IO(ElasticClient(JavaClient(ElasticProperties(uri)))))(client => IO(client.close())) - .evalMap: esClient => - meter - .histogram[Double]("db.client.operation.duration") - .withUnit("ms") - .create - .map( - apply( - esClient, - Attributes(Attribute("db.system", "elasticsearch"), Attribute("server.address", uri)) - ) - ) - def apply(client: Client[IO], uri: Uri)(using Meter[IO], IORuntime): IO[ESClient[IO]] = - val elasticClient = ElasticClient(Http4sClient.usingIO(client, uri)) Meter[IO] .histogram[Double]("db.client.operation.duration") .withUnit("ms") .create .map( apply( - elasticClient, + ElasticClient(Http4sClient.usingIO(client, uri)), Attributes(Attribute("db.system", "elasticsearch"), Attribute("server.address", uri.toString())) ) ) diff --git a/modules/ingestor/src/main/scala/app.config.scala b/modules/ingestor/src/main/scala/app.config.scala index bbef29b..27b7a2b 100644 --- a/modules/ingestor/src/main/scala/app.config.scala +++ b/modules/ingestor/src/main/scala/app.config.scala @@ -4,6 +4,8 @@ package ingestor import cats.effect.IO import cats.syntax.all.* import ciris.* +import ciris.http4s.* +import org.http4s.implicits.* import java.time.Instant import scala.concurrent.duration.* @@ -39,11 +41,12 @@ object MongoConfig: def config = (uri, name, studyUri, studyDatabase).parMapN(MongoConfig.apply) -case class ElasticConfig(uri: String) +case class ElasticConfig(uri: org.http4s.Uri) object ElasticConfig: - private def uri = env("ELASTIC_URI").or(prop("elastic.uri")).as[String].default("http://127.0.0.1:9200") - def config = uri.map(ElasticConfig.apply) + private def uri = + env("ELASTIC_URI").or(prop("elastic.uri")).as[org.http4s.Uri].default(uri"http://127.0.0.1:9200") + def config = uri.map(ElasticConfig.apply) case class IngestorConfig( forum: IngestorConfig.Forum, diff --git a/modules/ingestor/src/main/scala/app.resources.scala b/modules/ingestor/src/main/scala/app.resources.scala index 0596dcc..a11391b 100644 --- a/modules/ingestor/src/main/scala/app.resources.scala +++ b/modules/ingestor/src/main/scala/app.resources.scala @@ -1,11 +1,13 @@ package lila.search package ingestor +import cats.effect.unsafe.IORuntime import cats.effect.{ IO, Resource } import cats.syntax.all.* import com.mongodb.ReadPreference import mongo4cats.client.MongoClient import mongo4cats.database.MongoDatabase +import org.http4s.ember.client.EmberClientBuilder import org.typelevel.log4cats.Logger import org.typelevel.otel4s.metrics.Meter @@ -19,7 +21,7 @@ class AppResources( object AppResources: - def instance(conf: AppConfig)(using Logger[IO], Meter[IO]): Resource[IO, AppResources] = + def instance(conf: AppConfig)(using Logger[IO], Meter[IO], IORuntime): Resource[IO, AppResources] = ( makeMongoClient(conf.mongo), makeStudyMongoClient(conf.mongo), @@ -28,20 +30,23 @@ object AppResources: KVStore.apply().toResource ).parMapN(AppResources.apply) - def makeElasticClient(conf: ElasticConfig)(using Meter[IO]) = - ESClient(conf.uri) + private def makeElasticClient(conf: ElasticConfig)(using Meter[IO], IORuntime): Resource[IO, ESClient[IO]] = + EmberClientBuilder + .default[IO] + .build + .evalMap(ESClient(_, conf.uri)) - def makeMongoClient(conf: MongoConfig) = + private def makeMongoClient(conf: MongoConfig) = MongoClient .fromConnectionString[IO](conf.uri) .evalMap(_.getDatabase(conf.name).map(_.withReadPreference(ReadPreference.secondary()))) - def makeStudyMongoClient(conf: MongoConfig) = + private def makeStudyMongoClient(conf: MongoConfig) = MongoClient .fromConnectionString[IO](conf.studyUri) .evalMap(_.getDatabase(conf.studyName)) - def makeStudyOplogClient(conf: MongoConfig) = + private def makeStudyOplogClient(conf: MongoConfig) = MongoClient .fromConnectionString[IO](conf.studyUri) .evalMap(_.getDatabase("local")) diff --git a/modules/ingestor/src/main/scala/app.scala b/modules/ingestor/src/main/scala/app.scala index 333bb75..2b76657 100644 --- a/modules/ingestor/src/main/scala/app.scala +++ b/modules/ingestor/src/main/scala/app.scala @@ -2,6 +2,7 @@ package lila.search package ingestor import cats.effect.* +import cats.effect.unsafe.IORuntime import org.typelevel.log4cats.slf4j.Slf4jFactory import org.typelevel.log4cats.{ Logger, LoggerFactory } import org.typelevel.otel4s.experimental.metrics.* @@ -13,6 +14,7 @@ object App extends IOApp.Simple: given LoggerFactory[IO] = Slf4jFactory.create[IO] given Logger[IO] = LoggerFactory[IO].getLogger + given IORuntime = runtime override def run: IO[Unit] = app.useForever diff --git a/modules/ingestor/src/main/scala/cli.scala b/modules/ingestor/src/main/scala/cli.scala index 271857c..5a8f36a 100644 --- a/modules/ingestor/src/main/scala/cli.scala +++ b/modules/ingestor/src/main/scala/cli.scala @@ -3,6 +3,7 @@ package ingestor import cats.data.Validated import cats.effect.* +import cats.effect.unsafe.IORuntime import cats.syntax.all.* import com.monovore.decline.* import com.monovore.decline.effect.* @@ -23,6 +24,7 @@ object cli given LoggerFactory[IO] = Slf4jFactory.create[IO] given Logger[IO] = LoggerFactory[IO].getLogger given Meter[IO] = Meter.noop[IO] + given IORuntime = runtime override def main: Opts[IO[ExitCode]] = opts.parse.map: opts => diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 5c562a5..6b0ae06 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -49,7 +49,6 @@ object Dependencies { val playWS = "com.typesafe.play" %% "play-ahc-ws-standalone" % "2.2.10" - val elastic4sJavaClient = "nl.gn0s1s" %% "elastic4s-client-esjava" % V.elastic4s val elastic4sHttp4sClient = "nl.gn0s1s" %% "elastic4s-client-http4s" % V.elastic4s val elastic4sCatsEffect = "nl.gn0s1s" %% "elastic4s-effect-cats" % V.elastic4s From 02b5c7ebf195fb408798a08b9c0cd191c49d7c23 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Sat, 30 Nov 2024 20:03:07 +0100 Subject: [PATCH 5/5] Import http4s uri directly --- modules/app/src/main/scala/app.config.scala | 5 +++-- modules/ingestor/src/main/scala/app.config.scala | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/app/src/main/scala/app.config.scala b/modules/app/src/main/scala/app.config.scala index 01b0cc4..2047ff7 100644 --- a/modules/app/src/main/scala/app.config.scala +++ b/modules/app/src/main/scala/app.config.scala @@ -6,6 +6,7 @@ import cats.syntax.all.* import ciris.* import ciris.http4s.* import com.comcast.ip4s.* +import org.http4s.Uri import org.http4s.implicits.* object AppConfig: @@ -39,9 +40,9 @@ object HttpServerConfig: private def enableDocs = env("HTTP_ENABLE_DOCS").or(prop("http.enable.docs")).as[Boolean].default(false) def config = (host, port, logger, shutdownTimeout, enableDocs).parMapN(HttpServerConfig.apply) -case class ElasticConfig(uri: org.http4s.Uri) +case class ElasticConfig(uri: Uri) object ElasticConfig: private def uri = - env("ELASTIC_URI").or(prop("elastic.uri")).as[org.http4s.Uri].default(uri"http://127.0.0.1:9200") + env("ELASTIC_URI").or(prop("elastic.uri")).as[Uri].default(uri"http://127.0.0.1:9200") def config = uri.map(ElasticConfig.apply) diff --git a/modules/ingestor/src/main/scala/app.config.scala b/modules/ingestor/src/main/scala/app.config.scala index 27b7a2b..e50f851 100644 --- a/modules/ingestor/src/main/scala/app.config.scala +++ b/modules/ingestor/src/main/scala/app.config.scala @@ -5,6 +5,7 @@ import cats.effect.IO import cats.syntax.all.* import ciris.* import ciris.http4s.* +import org.http4s.Uri import org.http4s.implicits.* import java.time.Instant @@ -41,11 +42,11 @@ object MongoConfig: def config = (uri, name, studyUri, studyDatabase).parMapN(MongoConfig.apply) -case class ElasticConfig(uri: org.http4s.Uri) +case class ElasticConfig(uri: Uri) object ElasticConfig: private def uri = - env("ELASTIC_URI").or(prop("elastic.uri")).as[org.http4s.Uri].default(uri"http://127.0.0.1:9200") + env("ELASTIC_URI").or(prop("elastic.uri")).as[Uri].default(uri"http://127.0.0.1:9200") def config = uri.map(ElasticConfig.apply) case class IngestorConfig(