Emcee

Форк
0
/
InitQueueServerConfigCommand.swift 
101 строка · 5.6 Кб
1
import ArgLib
2
import Deployer
3
import EmceeLogging
4
import Foundation
5
import EmceeDI
6
import LocalQueueServerRunner
7
import MetricsExtensions
8
import PathLib
9
import QueueModels
10
import QueueServerConfiguration
11
import SocketModels
12

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,
18
    ]
19
    
20
    private let di: DI
21
    
22
    public init(
23
        di: DI
24
    ) throws {
25
        self.di = di
26
    }
27
    
28
    public func run(payload: CommandPayload) throws {
29
        let logger = try di.get(ContextualLogger.self)
30
        
31
        let outputPath: AbsolutePath = try payload.expectedSingleTypedValue(argumentName: ArgumentDescriptions.output.name)
32

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",
38
                        port: 42
39
                    ),
40
                    metricPrefix: "some.prefix.for.emcee"
41
                ),
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",
45
                        port: 1234
46
                    ),
47
                    metricPrefix: "some.prefix.for.emcee"
48
                ),
49
                kibanaConfiguration: KibanaConfiguration(
50
                    endpoints: [
51
                        URL(string: "http://kibana.example.com:12345/")!,
52
                    ],
53
                    indexPattern: "E.g. 'emcee-index-16112021-' — please refer to https://github.com/avito-tech/Emcee/wiki/Analytics#kibana"
54
                ),
55
                persistentMetricsJobId: "Usually you pass 'nil' here, because global analytics are not bound to any specific test jobs",
56
                metadata: [
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",
58
                ]
59
            ),
60
            checkAgainTimeInterval: QueueServerConfigurationDefaultValues.checkAgainTimeInterval,
61
            queueServerDeploymentDestinations: [
62
                DeploymentDestination(
63
                    host: "emceequeue.example.com - host name where queue should be started, and SSH port",
64
                    port: 22,
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."),
68
                    configuration: nil
69
                )
70
            ],
71
            queueServerTerminationPolicy: QueueServerConfigurationDefaultValues.queueServerTerminationPolicy,
72
            workerDeploymentDestinations: [
73
                DeploymentDestination(
74
                    host: "emceeWorker01.example.com - host name where WORKER should be started, and SSH port",
75
                    port: 22,
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."),
79
                    configuration: nil
80
                ),
81
                DeploymentDestination(
82
                    host: "emceeWorker02.example.com - host name where WORKER should be started, and SSH port",
83
                    port: 22,
84
                    username: "emcee",
85
                    authentication: DeploymentDestinationAuthenticationType.keyInDefaultSshLocation(filename: "key name inside ~/.ssh - most common location for SSH keys"),
86
                    remoteDeploymentPath: AbsolutePath("/Users/emcee/worker/"),
87
                    configuration: nil
88
                )
89
            ],
90
            defaultWorkerSpecificConfiguration: WorkerSpecificConfigurationDefaultValues.defaultWorkerConfiguration,
91
            workerStartMode: .queueStartsItsWorkersOverSshAndLaunchd,
92
            useOnlyIPv4: QueueServerConfigurationDefaultValues.useOnlyIPv4,
93
            portRange: QueueServerConfigurationDefaultValues.defaultQueuePortRange
94
        )
95
        
96
        let data = try JSONEncoder.pretty().encode(config)
97
        try data.write(to: outputPath.fileUrl)
98
        
99
        logger.info("Generated queue server configuration file stored at \(outputPath)")
100
    }
101
}
102

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.