[DPP-1327] Put SoX's default config under version control (#15671)

This commit is contained in:
pbatko-da 2022-11-25 13:48:34 +01:00 committed by GitHub
parent 9952e6011c
commit d3ed3c8118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 264 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import com.daml.ports.Port
import io.netty.handler.ssl.ClientAuth
import scopt.OParser
import java.io.File
import java.nio.file.Paths
import java.time.Duration
import java.util.UUID
import com.daml.metrics.api.reporters.MetricsReporter
@ -133,6 +134,7 @@ object CliConfig {
commandDumpIndexMetadata,
commandRunHocon(name),
commandConvertConfig(getEnvVar, extraOptions),
commandPrintDefaultConfig(),
builder.checkConfig(checkNoEmptyParticipant),
)
@ -213,6 +215,26 @@ object CliConfig {
.action((_, config) => config.copy(mode = Mode.ConvertConfig))
.children(legacyCommand(getEnvVar, extraOptions))
private def commandPrintDefaultConfig[Extra](): OParser[_, CliConfig[Extra]] = {
val builder = OParser.builder[CliConfig[Extra]]
builder
.cmd("print-default-config")
.text(
"Prints default config to stdout or to a file"
)
.action((_, config) => config.copy(mode = Mode.PrintDefaultConfig(None)))
.children(
builder
.arg[String]("<output-file-path>")
.minOccurs(0)
.text("An optional output file")
.action((outputFilePath, config) =>
config.copy(mode = Mode.PrintDefaultConfig(Some(Paths.get(outputFilePath))))
),
configKeyValueOption,
)
}
def legacyCommand[Extra](
getEnvVar: String => Option[String],
extraOptions: OParser[_, CliConfig[Extra]],

View File

@ -3,6 +3,8 @@
package com.daml.ledger.runner.common
import java.nio.file.Path
sealed abstract class Mode
object Mode {
@ -16,6 +18,8 @@ object Mode {
/** Accepts legacy Cli parameters, but just prints configuration */
case object ConvertConfig extends Mode
final case class PrintDefaultConfig(outputFilePath: Option[Path]) extends Mode
/** Dump index metadata and exit */
final case class DumpIndexMetadata(jdbcUrls: Vector[String]) extends Mode

View File

@ -10,6 +10,7 @@ load(
load("//ledger/ledger-api-tests:conformance.bzl", "conformance_test", "generate_conf", "server_conformance_test")
load("@oracle//:index.bzl", "oracle_tags")
load("@os_info//:os_info.bzl", "is_windows")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
da_scala_library(
name = "sandbox-on-x",
@ -132,7 +133,7 @@ da_scala_test_suite(
name = "sandbox-on-x-unit-tests",
size = "small",
srcs = glob(["src/test/suite/**/*.scala"]),
resources = glob(["src/test/resources/**/*"]),
resources = glob(["src/test/resources/**/*"]) + glob(["resources/*"]),
scala_deps = [
"@maven//:org_mockito_mockito_scala",
],
@ -155,6 +156,7 @@ da_scala_test_suite(
"//ledger/participant-state-index",
"//libs-scala/contextualized-logging",
"//libs-scala/logging-entries",
"@maven//:commons_io_commons_io",
"@maven//:io_dropwizard_metrics_metrics_core",
"@maven//:org_mockito_mockito_core",
],
@ -339,6 +341,38 @@ da_scala_binary(
],
)
# A rule that writes the default config to a file
genrule(
name = "generate-default.conf",
srcs = [],
outs = ["generated-default.conf"],
cmd = "$(location //ledger/sandbox-on-x:app) print-default-config $(location generated-default.conf) -C ledger.participants.default.services-thread-pool-size=1337",
tools = ["//ledger/sandbox-on-x:app"],
visibility = ["//visibility:public"],
)
# A rule that writes a script file for copying the generated default config file into the source tree
write_file(
name = "write-update-generated-sources-script",
out = "update-generated-sources.sh",
content = [
"#!/usr/bin/env bash",
"cd $BUILD_WORKSPACE_DIRECTORY",
"mkdir -p ledger/sandbox-on-x/resources",
"cp -fv bazel-bin/ledger/sandbox-on-x/generated-default.conf ledger/sandbox-on-x/resources/generated-default.conf",
"",
],
) if not is_windows else None
# A rule that copies the generated default config file into the source tree
sh_binary(
name = "update-generated-sources",
srcs = ["update-generated-sources.sh"],
data = [
"generate-default.conf",
],
) if not is_windows else None
alias(
name = "conformance-test-postgres-bin",
actual = "//ledger/sandbox-on-x:sandbox-on-x-ephemeral-postgresql",

View File

@ -0,0 +1,135 @@
bridge {
conflict-checking-enabled=true
max-deduplication-duration="1800 seconds"
stage-buffer-size=128
submission-buffer-size=500
}
ledger {
data-source {
default="<REDACTED>"
}
engine {
allowed-language-versions=early-access
contract-key-uniqueness=strict
forbid-v-0-contract-id=true
limits {
choice-controllers=2147483647
choice-observers=2147483647
contract-observers=2147483647
contract-signatories=2147483647
transaction-input-contracts=2147483647
}
package-validation=true
require-suffixed-global-contract-id=false
stack-trace-mode=false
}
ledger-id=default-ledger-id
metrics {
enabled=false
registry-type=jvm-shared
reporter=console
reporting-interval="10s"
}
participants {
default {
api-server {
api-stream-shutdown-timeout="5s"
command {
input-buffer-size=512
max-commands-in-flight=256
tracker-retention-period="300 seconds"
}
configuration-load-timeout="10s"
initial-ledger-configuration {
avg-transaction-latency="0 days"
delay-before-submitting="0 days"
enabled=true
max-deduplication-duration="1800 seconds"
max-skew="30 seconds"
min-skew="30 seconds"
}
management-service-timeout="2m"
max-inbound-message-size=67108864
port=6865
rate-limit {
enabled=true
max-api-services-index-db-queue-size=1000
max-api-services-queue-size=10000
max-streams=1000
max-used-heap-space-percentage=100
min-free-heap-space-bytes=0
}
seeding=strong
time-provider-type=wall-clock
user-management {
cache-expiry-after-write-in-seconds=5
enabled=false
max-cache-size=100
max-users-page-size=1000
}
}
authentication {
type=wildcard
}
data-source-properties {
connection-pool {
connection-pool-size=16
connection-timeout="250ms"
}
postgres {}
}
index-service {
acs-contract-fetching-parallelism=2
acs-global-parallelism=10
acs-id-fetching-parallelism=2
acs-id-page-buffer-size=1
acs-id-page-size=20000
acs-id-page-working-memory-bytes=104857600
api-stream-shutdown-timeout="5s"
buffered-streams-page-size=100
events-page-size=1000
events-processing-parallelism=8
in-memory-fan-out-thread-pool-size=16
in-memory-state-updater-parallelism=2
max-contract-key-state-cache-size=100000
max-contract-state-cache-size=100000
max-transactions-in-memory-fan-out-buffer-size=10000
prepare-package-metadata-time-out-warning="1s"
}
indexer {
batching-parallelism=4
enable-compression=false
high-availability {
indexer-lock-id=105305792
indexer-worker-lock-id=105305793
main-lock-acquire-retry-millis=500
main-lock-checker-jdbc-network-timeout-millis=10000
main-lock-checker-period-millis=1000
worker-lock-acquire-max-retry=1000
worker-lock-acquire-retry-millis=500
}
ingestion-parallelism=16
input-mapping-parallelism=16
max-input-buffer-size=50
max-output-batched-buffer-size=16
max-tailer-batch-size=10
package-metadata-view {
init-load-parallelism=16
init-process-parallelism=16
init-takes-too-long-initial-delay="1m"
init-takes-too-long-interval="10s"
}
restart-delay="10s"
startup-mode {
allow-existing-schema=false
type=migrate-and-start
}
submission-batch-size=50
}
jwt-timestamp-leeway {
enabled=false
}
services-thread-pool-size=1337
}
}
}

View File

@ -3,6 +3,9 @@
package com.daml.ledger.sandbox
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, StandardOpenOption}
import com.daml.ledger.resources.{ResourceContext, ResourceOwner}
import com.daml.ledger.runner.common._
import com.daml.logging.ContextualizedLogger
@ -40,13 +43,13 @@ object CliSandboxOnXRunner {
}
private def runProgram(
config: CliConfig[BridgeConfig],
cliConfig: CliConfig[BridgeConfig],
explicitDisclosureUnsafeEnabled: Boolean,
): Unit =
config.mode match {
cliConfig.mode match {
case Mode.Run =>
SandboxOnXConfig
.loadFromConfig(config.configFiles, config.configMap)
.loadFromConfig(cliConfig.configFiles, cliConfig.configMap)
.fold(
System.err.println,
{ sandboxOnXConfig =>
@ -59,14 +62,35 @@ object CliSandboxOnXRunner {
program(DumpIndexMetadata(jdbcUrls))
case Mode.ConvertConfig =>
Console.out.println(
ConfigRenderer.render(SandboxOnXConfig.fromLegacy(new BridgeConfigAdaptor, config))
ConfigRenderer.render(SandboxOnXConfig.fromLegacy(new BridgeConfigAdaptor, cliConfig))
)
case Mode.RunLegacyCliConfig =>
val configAdaptor: BridgeConfigAdaptor = new BridgeConfigAdaptor
val sandboxOnXConfig: SandboxOnXConfig = SandboxOnXConfig.fromLegacy(configAdaptor, config)
val sandboxOnXConfig: SandboxOnXConfig =
SandboxOnXConfig.fromLegacy(configAdaptor, cliConfig)
program(sox(configAdaptor, sandboxOnXConfig, explicitDisclosureUnsafeEnabled))
case Mode.PrintDefaultConfig(outputFilePathO) =>
val text = genDefaultConfigText(cliConfig.configMap)
outputFilePathO match {
case Some(outputFilePath) =>
val _ = Files.write(
outputFilePath,
text.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE_NEW,
)
case None => println(text)
}
}
def genDefaultConfigText(overrides: Map[String, String] = Map()): String = {
val soxConfig = SandboxOnXConfig.loadFromConfig(configMap = overrides) match {
case Left(msg) => sys.error(msg)
case Right(soxConfig) => soxConfig
}
val text = ConfigRenderer.render(soxConfig)
text
}
private def sox(
configAdaptor: BridgeConfigAdaptor,
sandboxOnXConfig: SandboxOnXConfig,

View File

@ -0,0 +1,39 @@
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.daml.ledger.sandbox
import java.nio.charset.StandardCharsets
import org.apache.commons.io.IOUtils
import org.scalatest.{AppendedClues, OptionValues}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
class TestGeneratedDefaultConfigIsUpToDate
extends AnyFlatSpec
with Matchers
with OptionValues
with AppendedClues {
private val clue =
"Generated default config is not up-to-date. \nPlease run: bazel run //ledger/sandbox-on-x:update-generated-sources"
it should "generated default config should be up-to-date" in {
val actual =
readFromResource("generated-default.conf").map(_.replaceAll("\\r", "").replaceAll("\\e", ""))
val expected = CliSandboxOnXRunner
.genDefaultConfigText(overrides =
Map("ledger.participants.default.services-thread-pool-size" -> "1337")
)
.replaceAll("\\r", "")
.replaceAll("\\e", "")
actual.value shouldBe expected withClue (clue)
}
private def readFromResource(resourceName: String): Option[String] = {
val streamO = Option(getClass.getClassLoader.getResourceAsStream(resourceName))
streamO.map(stream => IOUtils.toString(stream, StandardCharsets.UTF_8))
}
}