sandbox + kvutils: Add the "read" component back to the health checks. [KVL-475] [KVL-483] (#7486)

* participant-integration-api: Inject health checks into the API server.

CHANGELOG_BEGIN
- [Integration Kit] The ``StandaloneApiServer`` now takes a
  ``healthChecks`` parameter, which should identify the health checks to
  be exposed over the gRPC Health Checking Protocol. This will
  typically look something like::

    healthChecks = new HealthChecks("read" -> readService, "write" -> writeService)

  Integrators may also wish to expose the health of more components.
  All components wishing to report their health must implement the
  ``ReportsHealth`` trait.
 CHANGELOG_END

* sandbox + kvutils: Add the "read" component back to the health checks.
This commit is contained in:
Samir Talwar 2020-09-25 13:06:46 +02:00 committed by GitHub
parent b1872c10f7
commit 3f96b9b9db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 9 deletions

View File

@ -5,7 +5,7 @@ package com.daml.ledger.api.health
import com.daml.ledger.api.health.HealthChecks._
class HealthChecks(private val components: Components) {
class HealthChecks(components: Components) {
def this(components: Component*) = this(components.toMap)
def hasComponent(componentName: ComponentName): Boolean =
@ -16,6 +16,9 @@ class HealthChecks(private val components: Components) {
case None => components.forall(_._2.currentHealth() == Healthy)
case Some(name) => components(name).currentHealth() == Healthy
}
def +(component: Component) =
new HealthChecks(this.components + component)
}
object HealthChecks {

View File

@ -5,7 +5,7 @@ package com.daml.platform.apiserver
import java.io.File
import java.nio.file.Files
import java.time.Instant
import java.time.{Clock, Instant}
import akka.actor.ActorSystem
import akka.stream.Materializer
@ -47,6 +47,7 @@ final class StandaloneApiServer(
ledgerConfig: LedgerConfiguration,
optWriteService: Option[WriteService],
authService: AuthService,
healthChecks: HealthChecks,
metrics: Metrics,
timeServiceBackend: Option[TimeServiceBackend] = None,
otherServices: immutable.Seq[BindableService] = immutable.Seq.empty,
@ -77,12 +78,8 @@ final class StandaloneApiServer(
lfValueTranslationCache,
)
.map(index => new TimedIndexService(index, metrics))
authorizer = new Authorizer(
() => java.time.Clock.systemUTC.instant(),
ledgerId,
participantId)
healthChecks = new HealthChecks(
Seq("index" -> indexService) ++ optWriteService.toList.map("write" -> _): _*)
authorizer = new Authorizer(Clock.systemUTC.instant _, ledgerId, participantId)
healthChecksWithIndexService = healthChecks + ("index" -> indexService)
executionSequencerFactory <- new ExecutionSequencerFactoryOwner()
apiServicesOwner = new ApiServices.Owner(
participantId = participantId,
@ -99,7 +96,7 @@ final class StandaloneApiServer(
partyConfig = partyConfig,
optTimeServiceBackend = timeServiceBackend,
metrics = metrics,
healthChecks = healthChecks,
healthChecks = healthChecksWithIndexService,
seedService = SeedService(config.seeding),
)(materializer, executionSequencerFactory, loggingContext)
.map(_.withServices(otherServices))

View File

@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit
import akka.actor.ActorSystem
import akka.stream.Materializer
import com.daml.daml_lf_dev.DamlLf.Archive
import com.daml.ledger.api.health.HealthChecks
import com.daml.ledger.participant.state.v1.metrics.{TimedReadService, TimedWriteService}
import com.daml.ledger.participant.state.v1.{SubmissionId, WritePackagesService}
import com.daml.lf.archive.DarReader
@ -113,6 +114,10 @@ final class Runner[T <: ReadWriteService, Extra](
.acquire()
readService = new TimedReadService(ledger, metrics)
writeService = new TimedWriteService(ledger, metrics)
healthChecks = new HealthChecks(
"read" -> readService,
"write" -> writeService,
)
_ <- Resource.fromFuture(
Future.sequence(config.archiveFiles.map(uploadDar(_, writeService))))
_ <- new StandaloneIndexerServer(
@ -129,6 +134,7 @@ final class Runner[T <: ReadWriteService, Extra](
ledgerConfig = factory.ledgerConfig(config),
optWriteService = Some(writeService),
authService = factory.authService(config),
healthChecks = healthChecks,
metrics = metrics,
timeServiceBackend = factory.timeServiceBackend(config),
otherInterceptors = factory.interceptors(config),

View File

@ -16,6 +16,7 @@ import com.daml.caching
import com.daml.daml_lf_dev.DamlLf.Archive
import com.daml.ledger.api.auth.{AuthServiceWildcard, Authorizer}
import com.daml.ledger.api.domain
import com.daml.ledger.api.health.HealthChecks
import com.daml.ledger.on.sql.Database.InvalidDatabaseException
import com.daml.ledger.on.sql.SqlLedgerReaderWriter
import com.daml.ledger.participant.state.kvutils.api.KeyValueParticipantState
@ -148,6 +149,10 @@ class Runner(config: SandboxConfig) extends ResourceOwner[Port] {
ledger = new KeyValueParticipantState(readerWriter, readerWriter, metrics)
readService = new TimedReadService(ledger, metrics)
writeService = new TimedWriteService(ledger, metrics)
healthChecks = new HealthChecks(
"read" -> readService,
"write" -> writeService,
)
ledgerId <- ResourceOwner.forFuture(() =>
readService.getLedgerInitialConditions().runWith(Sink.head).map(_.ledgerId))
_ <- if (isReset) {
@ -213,6 +218,7 @@ class Runner(config: SandboxConfig) extends ResourceOwner[Port] {
ledgerConfig = config.ledgerConfig,
optWriteService = Some(writeService),
authService = authService,
healthChecks = healthChecks,
metrics = metrics,
timeServiceBackend = timeServiceBackend,
otherServices = List(resetService),