-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ledger-api-bench-tool - command submission and stream reading complet…
…e workflow [DPP-668] (#11544) * Created a top level WorkflowDescriptor * Stream descriptor in yaml * Do not pass global config to Benchmark * Fixed parsing template ids * Moved descriptor to the top level * Complete workflow * Print descriptor * Simplifiying * Simplifiying * Simplifiying * Defining submission+benchmark workflow in a yaml file. CHANGELOG_BEGIN - [Integration Kit] - ledger-api-bench-tool can run a workflow consisting of the command submission phase and stream benchmark phase. CHANGELOG_END * Log submission elapsed time * Change submission progress logging interval to 10000 * Changed misleading error type * unique_parties switch * Allow to skip submission phase
- Loading branch information
Showing
11 changed files
with
394 additions
and
237 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
53 changes: 53 additions & 0 deletions
53
...ger-api-bench-tool/src/main/scala/com/daml/ledger/api/benchtool/DescriptorConverter.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,53 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.api.benchtool | ||
|
||
import com.daml.ledger.api.benchtool.Config.StreamConfig | ||
import com.daml.ledger.api.benchtool.submission.CommandSubmitter | ||
import com.daml.ledger.test.model.Foo.{Foo1, Foo2, Foo3} | ||
import com.daml.ledger.client.binding.Primitive | ||
|
||
object DescriptorConverter { | ||
|
||
def streamDescriptorToConfig( | ||
descriptor: StreamDescriptor, | ||
submissionSummary: Option[CommandSubmitter.SubmissionSummary], | ||
): StreamConfig = { | ||
import scalaz.syntax.tag._ | ||
def templateStringToId(template: String) = template match { | ||
case "Foo1" => Foo1.id.unwrap | ||
case "Foo2" => Foo2.id.unwrap | ||
case "Foo3" => Foo3.id.unwrap | ||
case invalid => throw new RuntimeException(s"Invalid template: $invalid") | ||
} | ||
|
||
def convertedParty(party: String): String = { | ||
submissionSummary match { | ||
case None => party | ||
case Some(summary) => partyFromObservers(party, summary.observers) | ||
} | ||
} | ||
|
||
def partyFromObservers(party: String, observers: List[Primitive.Party]): String = | ||
observers | ||
.map(_.unwrap) | ||
.find(_.contains(party)) | ||
.getOrElse(throw new RuntimeException(s"Observer not found: $party")) | ||
|
||
val filters = descriptor.filters.map { filter => | ||
convertedParty(filter.party) -> Some(filter.templates.map(templateStringToId)) | ||
}.toMap | ||
|
||
descriptor.streamType match { | ||
case StreamDescriptor.StreamType.ActiveContracts => | ||
Config.StreamConfig.ActiveContractsStreamConfig( | ||
name = descriptor.name, | ||
filters = filters, | ||
) | ||
case invalid => | ||
throw new RuntimeException(s"Invalid stream type: $invalid") | ||
} | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
...dger-api-bench-tool/src/main/scala/com/daml/ledger/api/benchtool/WorkflowDescriptor.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,42 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.api.benchtool | ||
|
||
final case class WorkflowDescriptor( | ||
submission: Option[SubmissionDescriptor], | ||
streams: List[StreamDescriptor] = List.empty, | ||
) | ||
|
||
final case class SubmissionDescriptor( | ||
numberOfInstances: Int, | ||
numberOfObservers: Int, | ||
uniqueParties: Boolean, | ||
instanceDistribution: List[SubmissionDescriptor.ContractDescription], | ||
) | ||
|
||
object SubmissionDescriptor { | ||
final case class ContractDescription( | ||
template: String, | ||
weight: Int, | ||
payloadSizeBytes: Int, | ||
archiveChance: Double, | ||
) | ||
} | ||
|
||
final case class StreamDescriptor( | ||
streamType: StreamDescriptor.StreamType, | ||
name: String, | ||
filters: List[StreamDescriptor.PartyFilter], | ||
) | ||
|
||
object StreamDescriptor { | ||
sealed trait StreamType | ||
object StreamType { | ||
case object Transactions extends StreamType | ||
case object TransactionTrees extends StreamType | ||
case object ActiveContracts extends StreamType | ||
} | ||
|
||
final case class PartyFilter(party: String, templates: List[String]) | ||
} |
67 changes: 67 additions & 0 deletions
67
...r/ledger-api-bench-tool/src/main/scala/com/daml/ledger/api/benchtool/WorkflowParser.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,67 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.api.benchtool | ||
|
||
import io.circe.Decoder | ||
import io.circe.yaml.parser | ||
|
||
import java.io.Reader | ||
|
||
object WorkflowParser { | ||
import Decoders._ | ||
|
||
def parse(reader: Reader): Either[ParserError, WorkflowDescriptor] = | ||
parser | ||
.parse(reader) | ||
.flatMap(_.as[WorkflowDescriptor]) | ||
.left | ||
.map(error => ParserError(error.getLocalizedMessage)) | ||
|
||
case class ParserError(details: String) | ||
|
||
object Decoders { | ||
implicit val contractDescriptionDecoder: Decoder[SubmissionDescriptor.ContractDescription] = | ||
Decoder.forProduct4( | ||
"template", | ||
"weight", | ||
"payload_size_bytes", | ||
"archive_probability", | ||
)(SubmissionDescriptor.ContractDescription.apply) | ||
|
||
implicit val submissionDescriptorDecoder: Decoder[SubmissionDescriptor] = | ||
Decoder.forProduct4( | ||
"num_instances", | ||
"num_observers", | ||
"unique_parties", | ||
"instance_distribution", | ||
)(SubmissionDescriptor.apply) | ||
|
||
implicit val streamTypeDecoder: Decoder[StreamDescriptor.StreamType] = Decoder[String].emap { | ||
case "active-contracts" => Right(StreamDescriptor.StreamType.ActiveContracts) | ||
case "transactions" => Right(StreamDescriptor.StreamType.Transactions) | ||
case "transaction-trees" => Right(StreamDescriptor.StreamType.TransactionTrees) | ||
case invalid => Left(s"Invalid stream type: $invalid") | ||
} | ||
|
||
implicit val filtersDecoder: Decoder[StreamDescriptor.PartyFilter] = | ||
Decoder.forProduct2( | ||
"party", | ||
"templates", | ||
)(StreamDescriptor.PartyFilter.apply) | ||
|
||
implicit val streamDescriptorDecoder: Decoder[StreamDescriptor] = | ||
Decoder.forProduct3( | ||
"type", | ||
"name", | ||
"filters", | ||
)(StreamDescriptor.apply) | ||
|
||
implicit val workflowDescriptorDecoder: Decoder[WorkflowDescriptor] = | ||
Decoder.forProduct2( | ||
"submission", | ||
"streams", | ||
)(WorkflowDescriptor.apply) | ||
} | ||
|
||
} |
Oops, something went wrong.