diff --git a/modules/ingestor/src/main/scala/MetricExporterServer.scala b/modules/ingestor/src/main/scala/MetricExporterServer.scala deleted file mode 100644 index 49a4d85..0000000 --- a/modules/ingestor/src/main/scala/MetricExporterServer.scala +++ /dev/null @@ -1,26 +0,0 @@ -package lila.search -package ingestor - -import cats.effect.IO -import cats.effect.kernel.Resource -import com.comcast.ip4s.* -import org.http4s.* -import org.http4s.ember.server.EmberServerBuilder -import org.http4s.server.{ Router, Server } -import org.typelevel.otel4s.sdk.exporter.prometheus.* -import org.typelevel.otel4s.sdk.metrics.exporter.MetricExporter - -import scala.concurrent.duration.* - -def metricExporterServer(using exporter: MetricExporter.Pull[IO]): Resource[IO, Server] = - val writerConfig = PrometheusWriter.Config.default - val prometheusRoutes = PrometheusHttpRoutes.routes[IO](exporter, writerConfig) - val routes = Router("/metrics" -> prometheusRoutes) - - EmberServerBuilder - .default[IO] - .withHost(ip"0.0.0.0") - .withPort(port"9465") - .withHttpApp(routes.orNotFound) - .withShutdownTimeout(1.seconds) - .build diff --git a/modules/ingestor/src/main/scala/app.scala b/modules/ingestor/src/main/scala/app.scala index 0426b2a..19a859e 100644 --- a/modules/ingestor/src/main/scala/app.scala +++ b/modules/ingestor/src/main/scala/app.scala @@ -2,14 +2,12 @@ package lila.search package ingestor import cats.effect.* -import cats.syntax.all.* import org.typelevel.log4cats.slf4j.{ Slf4jFactory, Slf4jLogger } import org.typelevel.log4cats.{ Logger, LoggerFactory } import org.typelevel.otel4s.experimental.metrics.* import org.typelevel.otel4s.metrics.Meter -import org.typelevel.otel4s.sdk.exporter.prometheus.PrometheusMetricExporter +import org.typelevel.otel4s.sdk.exporter.prometheus.autoconfigure.PrometheusMetricExporterAutoConfigure import org.typelevel.otel4s.sdk.metrics.SdkMetrics -import org.typelevel.otel4s.sdk.metrics.exporter.MetricExporter object App extends IOApp.Simple: @@ -20,28 +18,21 @@ object App extends IOApp.Simple: def app: Resource[IO, Unit] = for - given MetricExporter.Pull[IO] <- PrometheusMetricExporter.builder[IO].build.toResource - given Meter[IO] <- mkMeter - _ <- RuntimeMetrics.register[IO] - config <- AppConfig.load.toResource - _ <- Logger[IO].info(s"Starting lila-search ingestor with config: $config").toResource - res <- AppResources.instance(config) - _ <- IngestorApp(res, config).run() + given Meter[IO] <- mkMeter + _ <- RuntimeMetrics.register[IO] + config <- AppConfig.load.toResource + _ <- Logger[IO].info(s"Starting lila-search ingestor with config: $config").toResource + res <- AppResources.instance(config) + _ <- IngestorApp(res, config).run() yield () - def mkMeter(using exporter: MetricExporter.Pull[IO]) = SdkMetrics - .autoConfigured[IO](_.addMeterProviderCustomizer((b, _) => b.registerMetricReader(exporter.metricReader))) + def mkMeter = SdkMetrics + .autoConfigured[IO](_.addExporterConfigurer(PrometheusMetricExporterAutoConfigure[IO])) .evalMap(_.meterProvider.get("lila-search-ingestor")) -class IngestorApp(res: AppResources, config: AppConfig)(using - Logger[IO], - LoggerFactory[IO], - MetricExporter.Pull[IO] -): +class IngestorApp(res: AppResources, config: AppConfig)(using Logger[IO], LoggerFactory[IO]): def run(): Resource[IO, Unit] = - val ingestor: ResourceIO[Unit] = - Ingestor(res.lichess, res.study, res.studyLocal, res.elastic, res.store, config.ingestor) - .flatMap(_.run()) - .toResource - (ingestor, metricExporterServer).parTupled.void + Ingestor(res.lichess, res.study, res.studyLocal, res.elastic, res.store, config.ingestor) + .flatMap(_.run()) + .toResource .evalTap(_ => Logger[IO].info("Ingestor started"))