Skip to content

Commit

Permalink
Use prometheus build in server for ingestor
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Nov 1, 2024
1 parent 0c813ff commit 54a7bc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 48 deletions.
26 changes: 0 additions & 26 deletions modules/ingestor/src/main/scala/MetricExporterServer.scala

This file was deleted.

35 changes: 13 additions & 22 deletions modules/ingestor/src/main/scala/app.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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"))

0 comments on commit 54a7bc9

Please sign in to comment.