summaryrefslogtreecommitdiff
path: root/internal/config/config.go
blob: 48a825c0145574efe06f6de569207d8ae9b30ea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package config

import "github.com/mimecast/dtail/internal/source"

const (
	// HealthUser is used for the health check
	HealthUser string = "DTAIL-HEALTH"
	// ScheduleUser is used for non-interactive scheduled mapreduce queries.
	ScheduleUser string = "DTAIL-SCHEDULE"
	// ContinuousUser is used for non-interactive continuous mapreduce queries.
	ContinuousUser string = "DTAIL-CONTINUOUS"
	// InterruptTimeoutS specifies the Ctrl+C log pause interval.
	InterruptTimeoutS int = 3
	// DefaultConnectionsPerCPU controls how many connections are established concurrently.
	DefaultConnectionsPerCPU int = 10
	// DefaultSSHPort is the default DServer port.
	DefaultSSHPort int = 2222
	// DefaultLogLevel specifies the default log level (obviously)
	DefaultLogLevel string = "info"
	// DefaultClientLogger specifies the default logger for the client commands.
	DefaultClientLogger string = "fout"
	// DefaultServerLogger specifies the default logger for dtail server.
	DefaultServerLogger string = "file"
	// DefaultHealthCheckLogger specifies the default logger used for health checks.
	DefaultHealthCheckLogger string = "none"
)

// Client holds DTail client configuration.
var Client *ClientConfig

// Server holds DTail server configuration.
var Server *ServerConfig

// Common holds configuration common to both client and server.
var Common *CommonConfig

// Setup the DTail configuration.
func Setup(sourceProcess source.Source, args *Args, additionalArgs []string) {
	initializer := initializer{
		Common: newDefaultCommonConfig(),
		Server: newDefaultServerConfig(),
		Client: newDefaultClientConfig(),
	}
	if err := initializer.parseConfig(args); err != nil {
		panic(err)
	}
	if err := initializer.transformConfig(sourceProcess, args, additionalArgs); err != nil {
		panic(err)
	}

	// Make config accessible globally
	Server = initializer.Server
	Client = initializer.Client
	Common = initializer.Common
}