Skip to content

Commit 38ea726

Browse files
[ci] Add Http client metrics. (#3415)
--------- Signed-off-by: Raymond Roestenburg <raymond.roestenburg@digitalasset.com> Co-authored-by: Nicu Reut <nicu.reut@digitalasset.com>
1 parent 51db589 commit 38ea726

File tree

38 files changed

+1124
-740
lines changed

38 files changed

+1124
-740
lines changed

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/ConsoleHttpCommandRunner.scala

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package org.lfdecentralizedtrust.splice.console
55

6-
import com.digitalasset.canton.config.{ConsoleCommandTimeout, NonNegativeDuration}
6+
import com.digitalasset.canton.config.ConsoleCommandTimeout
77
import com.digitalasset.canton.console.{
88
CommandErrors,
99
ConsoleCommandResult,
@@ -17,7 +17,6 @@ import org.apache.pekko.http.scaladsl.model.HttpHeader
1717
import org.lfdecentralizedtrust.splice.admin.api.client.HttpCtlRunner
1818
import org.lfdecentralizedtrust.splice.admin.api.client.commands.{HttpCommand, HttpCommandException}
1919
import org.lfdecentralizedtrust.splice.config.NetworkAppClientConfig
20-
import org.lfdecentralizedtrust.splice.environment.SpliceEnvironment
2120
import org.lfdecentralizedtrust.splice.http.HttpClient
2221
import org.lfdecentralizedtrust.splice.util.TemplateJsonDecoder
2322

@@ -26,25 +25,23 @@ import scala.concurrent.{ExecutionContextExecutor, TimeoutException}
2625
/** HTTP version of Canton’s GrpcAdminCommandRunner
2726
*/
2827
class ConsoleHttpCommandRunner(
29-
environment: SpliceEnvironment,
3028
commandTimeouts: ConsoleCommandTimeout,
31-
requestTimeout: NonNegativeDuration,
32-
)(implicit tracer: Tracer, templateDecoder: TemplateJsonDecoder)
33-
extends NamedLogging
29+
override val loggerFactory: NamedLoggerFactory,
30+
)(implicit
31+
tracer: Tracer,
32+
templateDecoder: TemplateJsonDecoder,
33+
httpClient: HttpClient,
34+
ec: ExecutionContextExecutor,
35+
as: ActorSystem,
36+
) extends NamedLogging
3437
with Spanning {
35-
36-
private implicit val executionContext: ExecutionContextExecutor =
37-
environment.executionContext
38-
private implicit val actorSystem: ActorSystem = environment.actorSystem
39-
override val loggerFactory: NamedLoggerFactory = environment.loggerFactory
40-
4138
private val httpRunner = new HttpCtlRunner(
4239
loggerFactory
4340
)
4441

4542
def runCommand[Result](
4643
instanceName: String,
47-
command: HttpCommand[?, Result],
44+
command: HttpCommand[?, Result, ?],
4845
headers: List[HttpHeader],
4946
clientConfig: NetworkAppClientConfig,
5047
): ConsoleCommandResult[Result] =
@@ -57,9 +54,6 @@ class ConsoleHttpCommandRunner(
5754
)
5855
val commandTimeout = commandTimeouts.bounded
5956

60-
implicit val httpClient: HttpClient =
61-
HttpClient(HttpClient.HttpRequestParameters(requestTimeout), logger)
62-
6357
val url = clientConfig.url
6458
try {
6559
val start = System.currentTimeMillis()

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/HttpCommandRunner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ trait HttpCommandRunner {
1111
/** Run an HTTP command and return its result.
1212
* HTTP variant of Canton’s AdminCommandRunner.
1313
*/
14-
protected[console] def httpCommand[Result](
15-
httpCommand: HttpCommand[?, Result],
14+
protected[console] def httpCommand[Res, Result, Client](
15+
httpCommand: HttpCommand[Res, Result, Client],
1616
basePath: Option[String] = None,
1717
): ConsoleCommandResult[Result]
1818
}

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/ScanAppReference.scala

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
package org.lfdecentralizedtrust.splice.console
55

6-
import org.apache.pekko.actor.ActorSystem
76
import org.lfdecentralizedtrust.splice.codegen.java.splice
87
import org.lfdecentralizedtrust.splice.codegen.java.splice.types.Round
98
import org.lfdecentralizedtrust.splice.codegen.java.splice.amulet.FeaturedAppRight
@@ -724,8 +723,7 @@ abstract class ScanAppReference(
724723
final class ScanAppBackendReference(
725724
override val spliceConsoleEnvironment: SpliceConsoleEnvironment,
726725
name: String,
727-
)(implicit actorSystem: ActorSystem)
728-
extends ScanAppReference(spliceConsoleEnvironment, name)
726+
) extends ScanAppReference(spliceConsoleEnvironment, name)
729727
with AppBackendReference
730728
with BaseInspection[ScanApp] {
731729

@@ -747,14 +745,6 @@ final class ScanAppBackendReference(
747745
override def config: ScanAppBackendConfig =
748746
spliceConsoleEnvironment.environment.config.scansByString(name)
749747

750-
/** Remote participant this scan app is configured to interact with. */
751-
lazy val participantClient =
752-
new ParticipantClientReference(
753-
spliceConsoleEnvironment,
754-
s"remote participant for `$name``",
755-
config.participantClient.getParticipantClientConfig(),
756-
)
757-
758748
/** Remote participant this scan app is configured to interact with. Uses admin tokens to bypass auth. */
759749
lazy val participantClientWithAdminToken =
760750
new ParticipantClientReference(

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/SpliceInstanceReference.scala

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import org.apache.pekko.http.scaladsl.model.headers.{Authorization, OAuth2Bearer
88
import com.digitalasset.daml.lf.archive.DarParser
99
import org.lfdecentralizedtrust.splice.admin.api.client.HttpAdminAppClient
1010
import org.lfdecentralizedtrust.splice.admin.api.client.commands.HttpCommand
11-
import org.lfdecentralizedtrust.splice.config.{NetworkAppClientConfig, SpliceBackendConfig}
11+
import org.lfdecentralizedtrust.splice.config.{
12+
BaseParticipantClientConfig,
13+
NetworkAppClientConfig,
14+
SpliceBackendConfig,
15+
}
1216
import org.lfdecentralizedtrust.splice.environment.{
1317
NodeBase,
1418
SpliceConsoleEnvironment,
@@ -45,7 +49,7 @@ import com.digitalasset.canton.topology.admin.grpc.TopologyStoreId
4549
import com.digitalasset.canton.topology.transaction.VettedPackage
4650

4751
import java.io.File
48-
import scala.concurrent.ExecutionContext
52+
import scala.concurrent.{Await, ExecutionContext}
4953
import scala.concurrent.duration.*
5054
import scala.reflect.ClassTag
5155
import scala.util.Try
@@ -123,8 +127,8 @@ trait HttpAppReference extends AppReference with HttpCommandRunner {
123127

124128
def httpClientConfig: NetworkAppClientConfig
125129

126-
override protected[splice] def httpCommand[Result](
127-
httpCommand: HttpCommand[?, Result],
130+
override protected[splice] def httpCommand[Res, Result, Client](
131+
httpCommand: HttpCommand[Res, Result, Client],
128132
basePath: Option[String] = None,
129133
): ConsoleCommandResult[Result] =
130134
spliceConsoleEnvironment.httpCommandRunner.runCommand(
@@ -237,6 +241,39 @@ trait AppBackendReference extends AppReference with LocalInstanceReference {
237241
x => x,
238242
)
239243
}
244+
245+
protected def getParticipantClient()(implicit
246+
ec: ExecutionContext
247+
): ParticipantClientReference = {
248+
val remoteParticipantClientConfig = getRemoteParticipantConfigWithToken(
249+
config.participantClient
250+
)
251+
new ParticipantClientReference(
252+
spliceConsoleEnvironment,
253+
s"remote participant for `$name``",
254+
remoteParticipantClientConfig,
255+
)
256+
}
257+
258+
private def getRemoteParticipantConfigWithToken(
259+
participantClientConfig: BaseParticipantClientConfig
260+
)(implicit ec: ExecutionContext): RemoteParticipantConfig = {
261+
val tokenStrO = Await.result(
262+
spliceConsoleEnvironment.httpClient
263+
.getToken(participantClientConfig.ledgerApi.authConfig)
264+
.map(_.map(_.accessToken)),
265+
30.seconds,
266+
)
267+
RemoteParticipantConfig(
268+
participantClientConfig.adminApi,
269+
participantClientConfig.ledgerApi.clientConfig,
270+
tokenStrO,
271+
)
272+
}
273+
implicit val ec: ExecutionContext = executionContext
274+
275+
/** Remote participant this splitwell app is configured to interact with. */
276+
lazy val participantClient = getParticipantClient()
240277
}
241278

242279
/** Subclass of participantClient that takes the config as an argument

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/SplitwellReference.scala

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
package org.lfdecentralizedtrust.splice.console
55

6-
import org.apache.pekko.actor.ActorSystem
76
import com.daml.ledger.api.v2.CommandsOuterClass
87
import com.daml.ledger.javaapi.data.codegen.Update
98
import org.lfdecentralizedtrust.splice.codegen.java.splice.splitwell as splitwellCodegen
@@ -29,8 +28,10 @@ import com.digitalasset.canton.console.{
2928
LedgerApiCommandRunner,
3029
}
3130
import com.digitalasset.canton.console.commands.BaseLedgerApiAdministration
32-
import com.digitalasset.canton.topology.{SynchronizerId, PartyId}
31+
import com.digitalasset.canton.topology.{PartyId, SynchronizerId}
3332

33+
import scala.concurrent.{Await, ExecutionContext}
34+
import scala.concurrent.duration.DurationInt
3435
import scala.jdk.CollectionConverters.*
3536

3637
/** Splitwell app reference. Defines the console commands that can be run against either a client or backend splitwell reference.
@@ -78,22 +79,26 @@ final class SplitwellAppClientReference(
7879
override val spliceConsoleEnvironment: SpliceConsoleEnvironment,
7980
name: String,
8081
val config: SplitwellAppClientConfig, // adding this explicitly for easier overriding
81-
)(implicit actorSystem: ActorSystem)
82-
extends SplitwellAppReference(spliceConsoleEnvironment, name) {
82+
) extends SplitwellAppReference(spliceConsoleEnvironment, name) {
8383
private val acceptDuration = new RelTime(
8484
60_000_000
8585
)
86-
8786
override protected val instanceType = "Splitwell Client"
8887

8988
override def httpClientConfig = config.adminApi
9089

90+
implicit val ec: ExecutionContext = executionContext
9191
override lazy val ledgerApi: com.digitalasset.canton.console.ExternalLedgerApiClient =
9292
new ExternalLedgerApiClient(
9393
config.participantClient.ledgerApi.clientConfig.address,
9494
config.participantClient.ledgerApi.clientConfig.port,
9595
config.participantClient.ledgerApi.clientConfig.tls,
96-
config.participantClient.ledgerApi.getToken().map(_.accessToken),
96+
Await.result(
97+
spliceConsoleEnvironment.httpClient
98+
.getToken(config.participantClient.ledgerApi.authConfig)
99+
.map(_.map(_.accessToken)),
100+
30.seconds,
101+
),
97102
)(consoleEnvironment)
98103

99104
val userId: String = config.ledgerApiUser
@@ -469,8 +474,7 @@ final class SplitwellAppClientReference(
469474
final class SplitwellAppBackendReference(
470475
override val consoleEnvironment: SpliceConsoleEnvironment,
471476
name: String,
472-
)(implicit actorSystem: ActorSystem)
473-
extends SplitwellAppReference(consoleEnvironment, name)
477+
) extends SplitwellAppReference(consoleEnvironment, name)
474478
with AppBackendReference
475479
with BaseInspection[SplitwellApp] {
476480

@@ -508,14 +512,6 @@ final class SplitwellAppBackendReference(
508512

509513
override val scanClientConfig = config.scanClient
510514

511-
/** Remote participant this splitwell app is configured to interact with. */
512-
lazy val participantClient =
513-
new ParticipantClientReference(
514-
consoleEnvironment,
515-
s"remote participant for `$name``",
516-
config.participantClient.getParticipantClientConfig(),
517-
)
518-
519515
/** Remote participant this splitwell app is configured to interact with. Uses admin tokens to bypass auth. */
520516
lazy val participantClientWithAdminToken =
521517
new ParticipantClientReference(

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/SvAppReference.scala

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import com.digitalasset.canton.admin.api.client.data.NodeStatus
3838
import com.digitalasset.canton.console.{BaseInspection, Help}
3939
import com.digitalasset.canton.topology.{ParticipantId, PartyId}
4040
import com.digitalasset.canton.tracing.TraceContext
41-
import org.apache.pekko.actor.ActorSystem
4241

4342
import scala.jdk.OptionConverters.*
4443
import java.time.Instant
@@ -283,8 +282,7 @@ final case class SvAppClientReference(
283282
class SvAppBackendReference(
284283
override val consoleEnvironment: SpliceConsoleEnvironment,
285284
name: String,
286-
)(implicit actorSystem: ActorSystem)
287-
extends SvAppReference(consoleEnvironment, name)
285+
) extends SvAppReference(consoleEnvironment, name)
288286
with AppBackendReference
289287
with BaseInspection[SvApp] {
290288

@@ -403,14 +401,6 @@ class SvAppBackendReference(
403401
httpCommand(HttpSvOperatorAppClient.GetMediatorNodeStatus())
404402
}
405403

406-
/** Remote participant this sv app is configured to interact with. */
407-
lazy val participantClient =
408-
new ParticipantClientReference(
409-
consoleEnvironment,
410-
s"remote participant for `$name``",
411-
config.participantClient.getParticipantClientConfig(),
412-
)
413-
414404
/** Remote participant this sv app is configured to interact with. Uses admin tokens to bypass auth. */
415405
lazy val participantClientWithAdminToken =
416406
new ParticipantClientReference(

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/console/ValidatorAppReference.scala

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ import org.lfdecentralizedtrust.tokenstandard.{metadata, transferinstruction}
3434
import com.digitalasset.canton.console.{BaseInspection, Help}
3535
import com.digitalasset.canton.data.CantonTimestamp
3636
import com.digitalasset.canton.topology.PartyId
37-
import org.apache.pekko.actor.ActorSystem
3837
import org.lfdecentralizedtrust.splice.codegen.java.splice.amuletrules.TransferPreapproval
3938
import org.lfdecentralizedtrust.splice.codegen.java.splice.api.token.{
40-
allocationv1,
4139
allocationinstructionv1,
40+
allocationv1,
4241
transferinstructionv1,
4342
}
4443
import org.lfdecentralizedtrust.splice.codegen.java.splice.externalpartyamuletrules.TransferCommandCounter
@@ -505,8 +504,7 @@ abstract class ValidatorAppReference(
505504
final class ValidatorAppBackendReference(
506505
override val consoleEnvironment: SpliceConsoleEnvironment,
507506
name: String,
508-
)(implicit actorSystem: ActorSystem)
509-
extends ValidatorAppReference(consoleEnvironment, name)
507+
) extends ValidatorAppReference(consoleEnvironment, name)
510508
with AppBackendReference
511509
with BaseInspection[ValidatorApp] {
512510

@@ -565,14 +563,6 @@ final class ValidatorAppBackendReference(
565563
override def config: ValidatorAppBackendConfig =
566564
consoleEnvironment.environment.config.validatorsByString(name)
567565

568-
/** Remote participant this validator app is configured to interact with. */
569-
lazy val participantClient =
570-
new ParticipantClientReference(
571-
consoleEnvironment,
572-
s"remote participant for `$name`",
573-
config.participantClient.getParticipantClientConfig(),
574-
)
575-
576566
/** Remote participant this validator app is configured to interact with. Uses admin tokens to bypass auth. */
577567
val participantClientWithAdminToken =
578568
new ParticipantClientReference(

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/environment/SpliceConsoleEnvironment.scala

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package org.lfdecentralizedtrust.splice.environment
55

6+
import com.daml.metrics.api.MetricHandle.LabeledMetricsFactory
7+
import com.daml.metrics.api.MetricsContext
68
import com.digitalasset.canton.config.CantonRequireTypes.InstanceName
79
import com.digitalasset.canton.console.{
810
ConsoleEnvironment,
@@ -16,6 +18,7 @@ import com.digitalasset.daml.lf.typesig.PackageSignature
1618
import org.apache.pekko.actor.ActorSystem
1719
import org.lfdecentralizedtrust.splice.config.SpliceConfig
1820
import org.lfdecentralizedtrust.splice.console.*
21+
import org.lfdecentralizedtrust.splice.http.{HttpClient, HttpClientMetrics}
1922
import org.lfdecentralizedtrust.splice.scan.config.ScanAppClientConfig
2023
import org.lfdecentralizedtrust.splice.sv.SvAppClientConfig
2124
import org.lfdecentralizedtrust.splice.util.ResourceTemplateDecoder
@@ -25,6 +28,8 @@ import org.lfdecentralizedtrust.splice.validator.config.{
2528
}
2629
import org.lfdecentralizedtrust.splice.wallet.config.WalletAppClientConfig
2730

31+
import scala.concurrent.ExecutionContext
32+
2833
class SpliceConsoleEnvironment(
2934
override val environment: SpliceEnvironment,
3035
val consoleOutput: ConsoleOutput = StandardConsoleOutput,
@@ -33,17 +38,29 @@ class SpliceConsoleEnvironment(
3338

3439
override type Config = SpliceConfig
3540

36-
implicit val actorSystem: ActorSystem = environment.actorSystem
41+
private implicit lazy val actorSystem: ActorSystem = environment.actorSystem
42+
private implicit lazy val ec: ExecutionContext = environment.executionContext
3743
private lazy val templateDecoder = new ResourceTemplateDecoder(
3844
SpliceConsoleEnvironment.packageSignatures,
3945
environment.loggerFactory,
4046
)
4147

48+
private val metricsContext = MetricsContext("component" -> "splice-console-environment")
49+
50+
lazy val metricsFactory: LabeledMetricsFactory =
51+
environment.metrics.metricsFactoryProvider.generateMetricsFactory(
52+
metricsContext
53+
)
54+
lazy val httpClient: HttpClient = HttpClient(
55+
HttpClient.HttpRequestParameters(environment.config.parameters.timeouts.requestTimeout),
56+
HttpClientMetrics(metricsFactory),
57+
logger,
58+
)
59+
4260
lazy val httpCommandRunner: ConsoleHttpCommandRunner = new ConsoleHttpCommandRunner(
43-
environment,
4461
environment.config.parameters.timeouts.console,
45-
environment.config.parameters.timeouts.requestTimeout,
46-
)(this.tracer, templateDecoder)
62+
environment.loggerFactory,
63+
)(this.tracer, templateDecoder, httpClient, environment.executionContext, actorSystem)
4764

4865
def mergeLocalSpliceInstances(
4966
locals: Seq[AppBackendReference]*

apps/app/src/main/scala/org/lfdecentralizedtrust/splice/environment/SpliceEnvironment.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SpliceEnvironment(
3939
// dump config (without sensitive data) to ease debugging
4040
logger.info(s"SpliceEnvironment with config = {\n${config.dumpString}\n}")
4141

42-
private lazy val metrics = SpliceMetricsFactory(
42+
lazy val metrics = SpliceMetricsFactory(
4343
metricsRegistry,
4444
dbStorageHistograms,
4545
loggerFactory,

0 commit comments

Comments
 (0)