-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prism-agent): add http metrics (#585)
* First working version of unified metrics from different sources * Fix test compilations * Reractor ZHttp4sBlazeServer to catch all errors * format
- Loading branch information
Showing
8 changed files
with
131 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...x/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/HttpURIDereferencerImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...nt/service/server/src/main/scala/io/iohk/atala/agent/server/http/ZHttp4sBlazeServer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.iohk.atala.agent.server.http | ||
|
||
import io.iohk.atala.api.http.ErrorResponse | ||
import io.iohk.atala.system.controller.SystemEndpoints | ||
import io.micrometer.prometheus.PrometheusMeterRegistry | ||
import org.http4s.* | ||
import org.http4s.blaze.server.BlazeServerBuilder | ||
import org.http4s.server.Router | ||
import sttp.tapir.* | ||
import sttp.tapir.server.http4s.Http4sServerOptions | ||
import sttp.tapir.server.http4s.ztapir.ZHttp4sServerInterpreter | ||
import sttp.tapir.server.metrics.prometheus.PrometheusMetrics | ||
import sttp.tapir.ztapir.ZServerEndpoint | ||
import zio.* | ||
import zio.interop.catz.* | ||
|
||
class ZHttp4sBlazeServer(micrometerRegistry: PrometheusMeterRegistry) { | ||
|
||
private val tapirPrometheusMetricsZIO: Task[PrometheusMetrics[Task]] = ZIO.attempt { | ||
PrometheusMetrics.default[Task](registry = micrometerRegistry.getPrometheusRegistry) | ||
} | ||
|
||
private val serverOptionsZIO: ZIO[PrometheusMetrics[Task], Throwable, Http4sServerOptions[Task]] = for { | ||
srv <- ZIO.service[PrometheusMetrics[Task]] | ||
options <- ZIO.attempt { | ||
Http4sServerOptions | ||
.customiseInterceptors[Task] | ||
.defaultHandlers(ErrorResponse.failureResponseHandler) | ||
.metricsInterceptor( | ||
srv.metricsInterceptor( | ||
ignoreEndpoints = Seq(SystemEndpoints.metrics) | ||
) | ||
) | ||
.options | ||
} | ||
} yield options | ||
|
||
def start( | ||
endpoints: List[ZServerEndpoint[Any, Any]], | ||
port: Int | ||
): Task[ExitCode] = { | ||
|
||
val serve = for { | ||
metrics <- tapirPrometheusMetricsZIO | ||
options <- serverOptionsZIO.provide(ZLayer.succeed(metrics)) | ||
serve <- ZIO.attempt { | ||
val http4sEndpoints: HttpRoutes[Task] = | ||
ZHttp4sServerInterpreter(options) | ||
.from(endpoints) | ||
.toRoutes | ||
|
||
ZIO.executor.flatMap(executor => | ||
BlazeServerBuilder[Task] | ||
.withExecutionContext(executor.asExecutionContext) | ||
.bindHttp(port, "0.0.0.0") | ||
.withHttpApp(Router("/" -> http4sEndpoints).orNotFound) | ||
.serve | ||
.compile | ||
.drain | ||
) | ||
} | ||
} yield serve | ||
|
||
serve.flatten.exitCode | ||
} | ||
} | ||
|
||
object ZHttp4sBlazeServer { | ||
def make: URIO[PrometheusMeterRegistry, ZHttp4sBlazeServer] = { | ||
for { | ||
micrometerRegistry <- ZIO.service[PrometheusMeterRegistry] | ||
zHttp4sBlazeServer = ZHttp4sBlazeServer(micrometerRegistry) | ||
} yield zHttp4sBlazeServer | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/http/ZHttpServer.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.