-
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: restore JVM metrics endpoint capability (#527)
* feat: restore JVM metrics endpoint capability * feat: move system controller to Tapir, simplify APISIX routing
- Loading branch information
davidpoltorak-io
committed
May 19, 2023
1 parent
3b9437c
commit 7d603f0
Showing
14 changed files
with
436 additions
and
117 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
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
28 changes: 0 additions & 28 deletions
28
prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/SystemInfoApp.scala
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/health/HealthInfo.scala
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
...gent/service/server/src/main/scala/io/iohk/atala/system/controller/SystemController.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,13 @@ | ||
package io.iohk.atala.system.controller | ||
|
||
import zio.{IO, ZIO} | ||
import io.iohk.atala.api.http.{ErrorResponse, RequestContext} | ||
import io.iohk.atala.system.controller.http.HealthInfo | ||
|
||
trait SystemController { | ||
|
||
def health()(implicit rc: RequestContext): IO[ErrorResponse, HealthInfo] | ||
|
||
def metrics()(implicit rc: RequestContext): IO[ErrorResponse, String] | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../service/server/src/main/scala/io/iohk/atala/system/controller/SystemControllerImpl.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,28 @@ | ||
package io.iohk.atala.system.controller | ||
|
||
import io.iohk.atala.agent.server.buildinfo.BuildInfo | ||
import io.iohk.atala.api.http.{ErrorResponse, RequestContext} | ||
import io.iohk.atala.system.controller.http.HealthInfo | ||
import zio.http.Response | ||
import zio.metrics.connectors.prometheus | ||
import zio.metrics.connectors.prometheus.PrometheusPublisher | ||
import zio.{IO, URLayer, ZIO, ZLayer} | ||
|
||
class SystemControllerImpl( | ||
prometheus: PrometheusPublisher | ||
) extends SystemController { | ||
|
||
override def health()(implicit rc: RequestContext): IO[ErrorResponse, HealthInfo] = { | ||
ZIO.succeed(HealthInfo(version = BuildInfo.version)) | ||
} | ||
|
||
override def metrics()(implicit rc: RequestContext): IO[ErrorResponse, String] = { | ||
prometheus.get | ||
} | ||
|
||
} | ||
|
||
object SystemControllerImpl { | ||
val layer: URLayer[PrometheusPublisher, SystemController] = | ||
ZLayer.fromFunction(SystemControllerImpl(_)) | ||
} |
65 changes: 65 additions & 0 deletions
65
...agent/service/server/src/main/scala/io/iohk/atala/system/controller/SystemEndpoints.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,65 @@ | ||
package io.iohk.atala.system.controller | ||
|
||
import io.iohk.atala.api.http.EndpointOutputs.* | ||
import io.iohk.atala.api.http.model.PaginationInput | ||
import io.iohk.atala.api.http.{ErrorResponse, RequestContext} | ||
import io.iohk.atala.connect.controller.http.{Connection, CreateConnectionRequest} | ||
import io.iohk.atala.issue.controller.http.* | ||
import io.iohk.atala.system.controller.http.HealthInfo | ||
import sttp.model.StatusCode | ||
import sttp.tapir.ztapir.stringBody | ||
import sttp.tapir.json.zio.jsonBody | ||
import sttp.tapir.{ | ||
Endpoint, | ||
EndpointInfo, | ||
EndpointInput, | ||
PublicEndpoint, | ||
endpoint, | ||
extractFromRequest, | ||
oneOf, | ||
oneOfDefaultVariant, | ||
oneOfVariant, | ||
path, | ||
query, | ||
statusCode, | ||
stringToPath | ||
} | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder} | ||
|
||
import java.util.UUID | ||
|
||
object SystemEndpoints { | ||
|
||
val health: PublicEndpoint[ | ||
(RequestContext), | ||
ErrorResponse, | ||
HealthInfo, | ||
Any | ||
] = | ||
endpoint.get | ||
.in(extractFromRequest[RequestContext](RequestContext.apply)) | ||
.in("_system" / "health") | ||
.out(jsonBody[HealthInfo].description("The health info object.")) | ||
.errorOut(basicFailures) | ||
.tag("System") | ||
.summary("As a system user, check the health status of the running service") | ||
.description("Returns the health info object of the running service") | ||
.name("systemHealth") | ||
|
||
val metrics: PublicEndpoint[ | ||
(RequestContext), | ||
ErrorResponse, | ||
String, | ||
Any | ||
] = | ||
endpoint.get | ||
.in(extractFromRequest[RequestContext](RequestContext.apply)) | ||
.in("_system" / "metrics") | ||
.out(stringBody.description("The metrics as pain strings.")) | ||
.errorOut(basicFailures) | ||
.tag("System") | ||
.summary("As a system user, check the health status of the running service") | ||
.description("Returns the health info object of the running service") | ||
.name("systemMetrics") | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...service/server/src/main/scala/io/iohk/atala/system/controller/SystemServerEndpoints.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,34 @@ | ||
package io.iohk.atala.system.controller | ||
|
||
import io.iohk.atala.api.http.RequestContext | ||
import io.iohk.atala.system.controller.SystemEndpoints.* | ||
import sttp.tapir.ztapir.* | ||
import zio.{URIO, ZIO} | ||
|
||
class SystemServerEndpoints(systemController: SystemController) { | ||
|
||
val healthEndpoint: ZServerEndpoint[Any, Any] = | ||
health.zServerLogic { case (ctx: RequestContext) => | ||
systemController.health()(ctx) | ||
} | ||
|
||
val metricsEndpoint: ZServerEndpoint[Any, Any] = | ||
metrics.zServerLogic { case (ctx: RequestContext) => | ||
systemController.metrics()(ctx) | ||
} | ||
|
||
val all: List[ZServerEndpoint[Any, Any]] = List( | ||
healthEndpoint, | ||
metricsEndpoint | ||
) | ||
|
||
} | ||
|
||
object SystemServerEndpoints { | ||
def all: URIO[SystemController, List[ZServerEndpoint[Any, Any]]] = { | ||
for { | ||
systemController <- ZIO.service[SystemController] | ||
systemServerEndpoints = new SystemServerEndpoints(systemController) | ||
} yield systemServerEndpoints.all | ||
} | ||
} |
Oops, something went wrong.