summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2021-10-15 12:38:39 +0300
committerPaul Buetow <pbuetow@mimecast.com>2021-10-15 12:38:39 +0300
commit1edc1469024d3cb74473bd99959d5d1068229c39 (patch)
tree72618e384626d9fc368994e3f24be9e9892d0610 /internal/config/config.go
parent4e1b7f6ff7e3f10bda852da90f7b62d5dbccd455 (diff)
parentc0332e8fa13f4939de17c856b2e71fd093847253 (diff)
merge from github.com/snonux/dtail
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go71
1 files changed, 36 insertions, 35 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 276ddcf..ee23829 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -1,23 +1,30 @@
package config
-import (
- "encoding/json"
- "io/ioutil"
- "os"
+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"
)
-// ControlUser is used for various DTail specific operations.
-const ControlUser string = "DTAIL-CONTROL"
-
-// ScheduleUser is used for non-interactive scheduled mapreduce queries.
-const ScheduleUser string = "DTAIL-SCHEDULE"
-
-// ContinuousUser is used for non-interactive continuous mapreduce queries.
-const ContinuousUser string = "DTAIL-CONTINUOUS"
-
-// InterruptTimeoutS is used to terminate DTail when Ctrl+C was pressed twice within a given interval.
-const InterruptTimeoutS int = 3
-
// Client holds a DTail client configuration.
var Client *ClientConfig
@@ -27,28 +34,22 @@ var Server *ServerConfig
// Common holds common configs of both both, client and server.
var Common *CommonConfig
-// Used to initialize the configuration.
-type configInitializer struct {
- Common *CommonConfig
- Server *ServerConfig
- Client *ClientConfig
-}
-
-// Parse and read a given config file in JSON format.
-func (c *configInitializer) parseConfig(configFile string) {
- fd, err := os.Open(configFile)
- if err != nil {
- panic(err)
+// Setup the DTail configuration.
+func Setup(sourceProcess source.Source, args *Args, additionalArgs []string) {
+ initializer := initializer{
+ Common: newDefaultCommonConfig(),
+ Server: newDefaultServerConfig(),
+ Client: newDefaultClientConfig(),
}
- defer fd.Close()
-
- cfgBytes, err := ioutil.ReadAll(fd)
- if err != nil {
+ if err := initializer.parseConfig(args); err != nil {
panic(err)
}
-
- err = json.Unmarshal([]byte(cfgBytes), c)
- if err != nil {
+ if err := initializer.transformConfig(sourceProcess, args, additionalArgs); err != nil {
panic(err)
}
+
+ // Make config accessible globally
+ Server = initializer.Server
+ Client = initializer.Client
+ Common = initializer.Common
}