6
import LocalQueueServerRunner
7
import MetricsExtensions
10
import QueueServerConfiguration
13
public final class InitQueueServerConfigCommand: Command {
14
public let name = "initQueueServerConfig"
15
public let description = "Generates a sample queue server configuration file"
16
public let arguments: Arguments = [
17
ArgumentDescriptions.output.asRequired,
28
public func run(payload: CommandPayload) throws {
29
let logger = try di.get(ContextualLogger.self)
31
let outputPath: AbsolutePath = try payload.expectedSingleTypedValue(argumentName: ArgumentDescriptions.output.name)
33
let config = QueueServerConfiguration(
34
globalAnalyticsConfiguration: AnalyticsConfiguration(
35
graphiteConfiguration: MetricConfiguration(
36
socketAddress: SocketAddress(
37
host: "graphite.example.com — this is a host name which runs Graphite instance, and its port. Please also refer to https://github.com/avito-tech/Emcee/wiki/Graphite",
40
metricPrefix: "some.prefix.for.emcee"
42
statsdConfiguration: MetricConfiguration(
43
socketAddress: SocketAddress(
44
host: "statsd.example.com — this is a host name which runs Statsd instance, and its port. Please also refer to https://github.com/avito-tech/Emcee/wiki/Graphite",
47
metricPrefix: "some.prefix.for.emcee"
49
kibanaConfiguration: KibanaConfiguration(
51
URL(string: "http://kibana.example.com:12345/")!,
53
indexPattern: "E.g. 'emcee-index-16112021-' — please refer to https://github.com/avito-tech/Emcee/wiki/Analytics#kibana"
55
persistentMetricsJobId: "Usually you pass 'nil' here, because global analytics are not bound to any specific test jobs",
57
"WhatToPutHere": "Usually you'd put an empty dict here '{}', because these events are top level ones, but you can add any metadata as needed",
60
checkAgainTimeInterval: QueueServerConfigurationDefaultValues.checkAgainTimeInterval,
61
queueServerDeploymentDestinations: [
62
DeploymentDestination(
63
host: "emceequeue.example.com - host name where queue should be started, and SSH port",
65
username: "ssh username to use",
66
authentication: DeploymentDestinationAuthenticationType.password("ssh password. But you can auth by key too!"),
67
remoteDeploymentPath: AbsolutePath("Working directory for EmceeQueueServer process. It should be writable by the provided username. Emcee will upload itself into this folder and start queue in daemon mode by using launchd. It will create plist and use launchctl (without sudo) to spawn a new daemon. Emcee queue has built-in protection to avoid starting multiple similar queues on the same machine."),
71
queueServerTerminationPolicy: QueueServerConfigurationDefaultValues.queueServerTerminationPolicy,
72
workerDeploymentDestinations: [
73
DeploymentDestination(
74
host: "emceeWorker01.example.com - host name where WORKER should be started, and SSH port",
76
username: "ssh username to use on this worker. We recommend creating a separate standard user for this.",
77
authentication: DeploymentDestinationAuthenticationType.key(path: "/arbitrary/path/to/key.pub - you can pass any absolute path"),
78
remoteDeploymentPath: AbsolutePath("Working directory for EmceeWorker process on this host. It should be writable by the provided username. Emcee will upload itself into this folder and start worker in daemon mode by using launchd. It will create plist and use launchctl (without sudo) to spawn a new daemon. Worker will die right after queue dies."),
81
DeploymentDestination(
82
host: "emceeWorker02.example.com - host name where WORKER should be started, and SSH port",
85
authentication: DeploymentDestinationAuthenticationType.keyInDefaultSshLocation(filename: "key name inside ~/.ssh - most common location for SSH keys"),
86
remoteDeploymentPath: AbsolutePath("/Users/emcee/worker/"),
90
defaultWorkerSpecificConfiguration: WorkerSpecificConfigurationDefaultValues.defaultWorkerConfiguration,
91
workerStartMode: .queueStartsItsWorkersOverSshAndLaunchd,
92
useOnlyIPv4: QueueServerConfigurationDefaultValues.useOnlyIPv4,
93
portRange: QueueServerConfigurationDefaultValues.defaultQueuePortRange
96
let data = try JSONEncoder.pretty().encode(config)
97
try data.write(to: outputPath.fileUrl)
99
logger.info("Generated queue server configuration file stored at \(outputPath)")