summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-10 14:02:12 +0300
committerPaul Buetow <paul@buetow.org>2021-10-10 14:15:26 +0300
commitf44792c9102488774c9993b080f35c65287a64b1 (patch)
tree94b0be371a2135f4fea63bca87e14ce057fc172e
parent97747ea0f3178f7f5890512d483fdccaa82846b0 (diff)
add another dmap test - reading 100 source files at once
fix a data race when reading multiple files on one server from the same session at once
-rw-r--r--TODO.md2
-rw-r--r--cmd/dcat/main.go2
-rw-r--r--cmd/dgrep/main.go2
-rw-r--r--cmd/dmap/main.go2
-rw-r--r--cmd/dtail/main.go2
-rw-r--r--cmd/dtailhealthcheck/main.go2
-rw-r--r--docker/Makefile2
-rw-r--r--integrationtests/dmap3.csv.expected204
-rw-r--r--integrationtests/dmap3.csv.query.expected1
-rw-r--r--internal/clients/maprclient.go2
-rw-r--r--internal/config/config.go2
-rw-r--r--internal/config/initializer.go4
-rw-r--r--internal/io/dlog/level.go5
-rw-r--r--internal/io/fs/permissions/permission.go2
-rw-r--r--internal/server/handlers/basehandler.go40
-rw-r--r--internal/server/handlers/healthhandler.go2
-rw-r--r--internal/server/handlers/serverhandler.go18
17 files changed, 260 insertions, 34 deletions
diff --git a/TODO.md b/TODO.md
index 72eb0f3..ba20053 100644
--- a/TODO.md
+++ b/TODO.md
@@ -15,5 +15,5 @@ This is a loose list of what to do. Maybe for the next releae or maybe for a lat
[ ] Manual test/adjust dtail colors
[ ] More integration test colors (via dcat?)
[ ] Integration test for dtail in serverless mode
-[ ] Go through the whole source and change indentation (try not to exceed 80char line lengths by too much)
+[ ] Integration test for dtail normal mode
[ ] Fix the sync.Pools (they aren't concurrent as it seems and can cause a panic)
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go
index 87ece9d..5851acc 100644
--- a/cmd/dcat/main.go
+++ b/cmd/dcat/main.go
@@ -41,7 +41,7 @@ func main() {
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
flag.StringVar(&args.LogDir, "logDir", "~/log", "Log dir")
flag.StringVar(&args.Logger, "logger", config.DefaultClientLogger, "Logger name")
- flag.StringVar(&args.LogLevel, "logLevel", "", "Log level")
+ flag.StringVar(&args.LogLevel, "logLevel", config.DefaultLogLevel, "Log level")
flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
flag.StringVar(&args.UserName, "user", userName, "Your system user name")
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 576e22b..da3f7a4 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -35,7 +35,7 @@ func main() {
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
flag.StringVar(&args.LogDir, "logDir", "~/log", "Log dir")
flag.StringVar(&args.Logger, "logger", config.DefaultClientLogger, "Logger name")
- flag.StringVar(&args.LogLevel, "logLevel", "", "Log level")
+ flag.StringVar(&args.LogLevel, "logLevel", config.DefaultLogLevel, "Log level")
flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression")
flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go
index 1f44076..89ca5d0 100644
--- a/cmd/dmap/main.go
+++ b/cmd/dmap/main.go
@@ -37,7 +37,7 @@ func main() {
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
flag.StringVar(&args.LogDir, "logDir", "~/log", "Log dir")
flag.StringVar(&args.Logger, "logger", config.DefaultClientLogger, "Logger name")
- flag.StringVar(&args.LogLevel, "logLevel", "", "Log level")
+ flag.StringVar(&args.LogLevel, "logLevel", config.DefaultLogLevel, "Log level")
flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
flag.StringVar(&args.QueryStr, "query", "", "Map reduce query")
flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index 2863370..4285476 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -54,7 +54,7 @@ func main() {
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
flag.StringVar(&args.LogDir, "logDir", "~/log", "Log dir")
flag.StringVar(&args.Logger, "logger", config.DefaultClientLogger, "Logger name")
- flag.StringVar(&args.LogLevel, "logLevel", "", "Log level")
+ flag.StringVar(&args.LogLevel, "logLevel", config.DefaultLogLevel, "Log level")
flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
flag.StringVar(&args.QueryStr, "query", "", "Map reduce query")
flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression")
diff --git a/cmd/dtailhealthcheck/main.go b/cmd/dtailhealthcheck/main.go
index b0ba4cd..7e54b1c 100644
--- a/cmd/dtailhealthcheck/main.go
+++ b/cmd/dtailhealthcheck/main.go
@@ -25,7 +25,7 @@ func main() {
flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
flag.StringVar(&args.Logger, "logger", config.DefaultHealthCheckLogger, "Logger name")
- flag.StringVar(&args.LogLevel, "logLevel", "", "Log level")
+ flag.StringVar(&args.LogLevel, "logLevel", "none", "Log level")
flag.StringVar(&args.ServersStr, "server", "", "Remote server to connect")
flag.Parse()
diff --git a/docker/Makefile b/docker/Makefile
index 4ffa423..fdd6c5b 100644
--- a/docker/Makefile
+++ b/docker/Makefile
@@ -12,7 +12,7 @@ spinup:
spindown:
./spindown.sh 10
spinup1:
- docker run -p 2222:2222 dserver:develop
+ docker run -p 2222:2222 dserver:develop
dtail:
../dtail --servers serverlist.txt --files '/var/log/dserver/*' --trustAllHosts --logLevel DEBUG
dtail2:
diff --git a/integrationtests/dmap3.csv.expected b/integrationtests/dmap3.csv.expected
new file mode 100644
index 0000000..88862d2
--- /dev/null
+++ b/integrationtests/dmap3.csv.expected
@@ -0,0 +1,204 @@
+count($time),$time,max($goroutines),avg($goroutines),min($goroutines)
+2300,20211002-071147,16.000000,14.391304,12.000000
+2000,20211002-071143,17.000000,15.000000,13.000000
+2000,20211002-071213,17.000000,14.100000,12.000000
+1100,20211002-071948,15.000000,14.272727,11.000000
+1000,20211002-071913,13.000000,13.000000,13.000000
+1000,20211002-071912,15.000000,15.000000,15.000000
+900,20211002-071921,15.000000,13.333333,12.000000
+700,20211002-071920,15.000000,15.000000,15.000000
+400,20211002-071922,13.000000,12.500000,12.000000
+300,20211002-071749,11.000000,11.000000,11.000000
+300,20211002-071157,11.000000,11.000000,11.000000
+300,20211002-071308,11.000000,11.000000,11.000000
+300,20211002-071406,11.000000,11.000000,11.000000
+300,20211002-071847,11.000000,11.000000,11.000000
+300,20211002-071859,11.000000,11.000000,11.000000
+300,20211002-071536,11.000000,11.000000,11.000000
+300,20211002-071729,11.000000,11.000000,11.000000
+300,20211002-071336,11.000000,11.000000,11.000000
+300,20211002-071146,11.000000,11.000000,11.000000
+300,20211002-071539,11.000000,11.000000,11.000000
+300,20211002-071719,11.000000,11.000000,11.000000
+300,20211002-071849,11.000000,11.000000,11.000000
+300,20211002-071927,11.000000,11.000000,11.000000
+300,20211002-071426,11.000000,11.000000,11.000000
+300,20211002-071757,11.000000,11.000000,11.000000
+300,20211002-071338,11.000000,11.000000,11.000000
+300,20211002-071817,11.000000,11.000000,11.000000
+300,20211002-071747,11.000000,11.000000,11.000000
+300,20211002-071306,11.000000,11.000000,11.000000
+300,20211002-071156,11.000000,11.000000,11.000000
+300,20211002-071316,11.000000,11.000000,11.000000
+300,20211002-071256,11.000000,11.000000,11.000000
+300,20211002-071328,11.000000,11.000000,11.000000
+300,20211002-071627,11.000000,11.000000,11.000000
+300,20211002-071917,11.000000,11.000000,11.000000
+300,20211002-071609,11.000000,11.000000,11.000000
+300,20211002-071516,11.000000,11.000000,11.000000
+300,20211002-071637,11.000000,11.000000,11.000000
+300,20211002-071929,11.000000,11.000000,11.000000
+300,20211002-071428,11.000000,11.000000,11.000000
+300,20211002-071717,11.000000,11.000000,11.000000
+300,20211002-071937,11.000000,11.000000,11.000000
+300,20211002-071837,11.000000,11.000000,11.000000
+300,20211002-071546,11.000000,11.000000,11.000000
+300,20211002-071739,11.000000,11.000000,11.000000
+300,20211002-071649,11.000000,11.000000,11.000000
+300,20211002-071809,11.000000,11.000000,11.000000
+300,20211002-071438,11.000000,11.000000,11.000000
+300,20211002-071529,11.000000,11.000000,11.000000
+300,20211002-071829,11.000000,11.000000,11.000000
+300,20211002-071606,11.000000,11.000000,11.000000
+300,20211002-071448,11.000000,11.000000,11.000000
+300,20211002-071416,11.000000,11.000000,11.000000
+300,20211002-071519,11.000000,11.000000,11.000000
+300,20211002-071356,11.000000,11.000000,11.000000
+300,20211002-071418,11.000000,11.000000,11.000000
+300,20211002-071807,11.000000,11.000000,11.000000
+300,20211002-071907,11.000000,11.000000,11.000000
+300,20211002-071206,11.000000,11.000000,11.000000
+300,20211002-071617,11.000000,11.000000,11.000000
+300,20211002-071727,11.000000,11.000000,11.000000
+300,20211002-071456,11.000000,11.000000,11.000000
+300,20211002-071947,11.000000,11.000000,11.000000
+300,20211002-071346,11.000000,11.000000,11.000000
+300,20211002-071208,11.000000,11.000000,11.000000
+300,20211002-071639,11.000000,11.000000,11.000000
+300,20211002-071629,11.000000,11.000000,11.000000
+300,20211002-071839,11.000000,11.000000,11.000000
+300,20211002-071939,11.000000,11.000000,11.000000
+300,20211002-071737,11.000000,11.000000,11.000000
+300,20211002-071258,11.000000,11.000000,11.000000
+300,20211002-071919,11.000000,11.000000,11.000000
+300,20211002-071246,11.000000,11.000000,11.000000
+300,20211002-071559,11.000000,11.000000,11.000000
+300,20211002-071506,11.000000,11.000000,11.000000
+300,20211002-071709,11.000000,11.000000,11.000000
+300,20211002-071619,11.000000,11.000000,11.000000
+300,20211002-071228,11.000000,11.000000,11.000000
+300,20211002-071759,11.000000,11.000000,11.000000
+300,20211002-071446,11.000000,11.000000,11.000000
+300,20211002-071657,11.000000,11.000000,11.000000
+300,20211002-071226,11.000000,11.000000,11.000000
+300,20211002-071549,11.000000,11.000000,11.000000
+300,20211002-071236,11.000000,11.000000,11.000000
+300,20211002-071508,11.000000,11.000000,11.000000
+300,20211002-071707,11.000000,11.000000,11.000000
+300,20211002-071238,11.000000,11.000000,11.000000
+300,20211002-071216,11.000000,11.000000,11.000000
+300,20211002-071326,11.000000,11.000000,11.000000
+300,20211002-071458,11.000000,11.000000,11.000000
+300,20211002-071857,11.000000,11.000000,11.000000
+300,20211002-071218,11.000000,11.000000,11.000000
+300,20211002-071909,11.000000,11.000000,11.000000
+300,20211002-071436,11.000000,11.000000,11.000000
+300,20211002-071358,11.000000,11.000000,11.000000
+300,20211002-071318,11.000000,11.000000,11.000000
+300,20211002-071647,11.000000,11.000000,11.000000
+300,20211002-071348,11.000000,11.000000,11.000000
+300,20211002-071819,11.000000,11.000000,11.000000
+300,20211002-071526,11.000000,11.000000,11.000000
+300,20211002-071659,11.000000,11.000000,11.000000
+300,20211002-071248,11.000000,11.000000,11.000000
+300,20211002-071556,11.000000,11.000000,11.000000
+300,20211002-071827,11.000000,11.000000,11.000000
+300,20211002-071408,11.000000,11.000000,11.000000
+200,20211002-071716,11.000000,11.000000,11.000000
+200,20211002-071527,11.000000,11.000000,11.000000
+200,20211002-071339,11.000000,11.000000,11.000000
+200,20211002-071858,11.000000,11.000000,11.000000
+200,20211002-071748,11.000000,11.000000,11.000000
+200,20211002-071557,11.000000,11.000000,11.000000
+200,20211002-071217,11.000000,11.000000,11.000000
+200,20211002-071337,11.000000,11.000000,11.000000
+200,20211002-071607,11.000000,11.000000,11.000000
+200,20211002-071928,11.000000,11.000000,11.000000
+200,20211002-071628,11.000000,11.000000,11.000000
+200,20211002-071706,11.000000,11.000000,11.000000
+200,20211002-071349,11.000000,11.000000,11.000000
+200,20211002-071407,11.000000,11.000000,11.000000
+200,20211002-071459,11.000000,11.000000,11.000000
+200,20211002-071826,11.000000,11.000000,11.000000
+200,20211002-071626,11.000000,11.000000,11.000000
+200,20211002-071926,11.000000,11.000000,11.000000
+200,20211002-071616,11.000000,11.000000,11.000000
+200,20211002-071537,11.000000,11.000000,11.000000
+200,20211002-071726,11.000000,11.000000,11.000000
+200,20211002-071718,11.000000,11.000000,11.000000
+200,20211002-071816,11.000000,11.000000,11.000000
+200,20211002-071916,11.000000,11.000000,11.000000
+200,20211002-071429,11.000000,11.000000,11.000000
+200,20211002-071327,11.000000,11.000000,11.000000
+200,20211002-071148,11.000000,11.000000,11.000000
+200,20211002-071158,11.000000,11.000000,11.000000
+200,20211002-071319,11.000000,11.000000,11.000000
+200,20211002-071309,11.000000,11.000000,11.000000
+200,20211002-071357,11.000000,11.000000,11.000000
+200,20211002-071219,11.000000,11.000000,11.000000
+200,20211002-071856,11.000000,11.000000,11.000000
+200,20211002-071509,11.000000,11.000000,11.000000
+200,20211002-071447,11.000000,11.000000,11.000000
+200,20211002-071439,11.000000,11.000000,11.000000
+200,20211002-071149,11.000000,11.000000,11.000000
+200,20211002-071457,11.000000,11.000000,11.000000
+200,20211002-071818,11.000000,11.000000,11.000000
+200,20211002-071517,11.000000,11.000000,11.000000
+200,20211002-071249,11.000000,11.000000,11.000000
+200,20211002-071648,11.000000,11.000000,11.000000
+200,20211002-071259,11.000000,11.000000,11.000000
+200,20211002-071828,11.000000,11.000000,11.000000
+200,20211002-071437,11.000000,11.000000,11.000000
+200,20211002-071207,11.000000,11.000000,11.000000
+200,20211002-071329,11.000000,11.000000,11.000000
+200,20211002-071918,11.000000,11.000000,11.000000
+200,20211002-071409,11.000000,11.000000,11.000000
+200,20211002-071359,11.000000,11.000000,11.000000
+200,20211002-071906,11.000000,11.000000,11.000000
+200,20211002-071646,11.000000,11.000000,11.000000
+200,20211002-071528,11.000000,11.000000,11.000000
+200,20211002-071736,11.000000,11.000000,11.000000
+200,20211002-071417,11.000000,11.000000,11.000000
+200,20211002-071608,11.000000,11.000000,11.000000
+200,20211002-071838,11.000000,11.000000,11.000000
+200,20211002-071518,11.000000,11.000000,11.000000
+200,20211002-071938,11.000000,11.000000,11.000000
+200,20211002-071227,11.000000,11.000000,11.000000
+200,20211002-071638,11.000000,11.000000,11.000000
+200,20211002-071449,11.000000,11.000000,11.000000
+200,20211002-071547,11.000000,11.000000,11.000000
+200,20211002-071908,11.000000,11.000000,11.000000
+200,20211002-071548,11.000000,11.000000,11.000000
+200,20211002-071846,11.000000,11.000000,11.000000
+200,20211002-071806,11.000000,11.000000,11.000000
+200,20211002-071307,11.000000,11.000000,11.000000
+200,20211002-071636,11.000000,11.000000,11.000000
+200,20211002-071738,11.000000,11.000000,11.000000
+200,20211002-071808,11.000000,11.000000,11.000000
+200,20211002-071239,11.000000,11.000000,11.000000
+200,20211002-071728,11.000000,11.000000,11.000000
+200,20211002-071946,11.000000,11.000000,11.000000
+200,20211002-071656,11.000000,11.000000,11.000000
+200,20211002-071347,11.000000,11.000000,11.000000
+200,20211002-071758,11.000000,11.000000,11.000000
+200,20211002-071247,11.000000,11.000000,11.000000
+200,20211002-071507,11.000000,11.000000,11.000000
+200,20211002-071848,11.000000,11.000000,11.000000
+200,20211002-071538,11.000000,11.000000,11.000000
+200,20211002-071756,11.000000,11.000000,11.000000
+200,20211002-071618,11.000000,11.000000,11.000000
+200,20211002-071746,11.000000,11.000000,11.000000
+200,20211002-071836,11.000000,11.000000,11.000000
+200,20211002-071229,11.000000,11.000000,11.000000
+200,20211002-071257,11.000000,11.000000,11.000000
+200,20211002-071419,11.000000,11.000000,11.000000
+200,20211002-071237,11.000000,11.000000,11.000000
+200,20211002-071936,11.000000,11.000000,11.000000
+200,20211002-071558,11.000000,11.000000,11.000000
+200,20211002-071427,11.000000,11.000000,11.000000
+200,20211002-071317,11.000000,11.000000,11.000000
+200,20211002-071658,11.000000,11.000000,11.000000
+200,20211002-071708,11.000000,11.000000,11.000000
+200,20211002-071209,11.000000,11.000000,11.000000
+200,20211002-071159,11.000000,11.000000,11.000000
+100,20211002-071949,15.000000,15.000000,15.000000
diff --git a/integrationtests/dmap3.csv.query.expected b/integrationtests/dmap3.csv.query.expected
new file mode 100644
index 0000000..c0031af
--- /dev/null
+++ b/integrationtests/dmap3.csv.query.expected
@@ -0,0 +1 @@
+from STATS select count($time),$time,max($goroutines),avg($goroutines),min($goroutines) group by $time order by count($time) outfile dmap3.csv.tmp \ No newline at end of file
diff --git a/internal/clients/maprclient.go b/internal/clients/maprclient.go
index 04f258d..074494c 100644
--- a/internal/clients/maprclient.go
+++ b/internal/clients/maprclient.go
@@ -108,7 +108,7 @@ func (c *MaprClient) Start(ctx context.Context, statsCh <-chan string) (status i
}
// NEXT: Make this a callback function rather trying to use polymorphism to call
-// this. This applies to all clients.
+// this. This applies to all clients. It will make the code easier to read.
func (c MaprClient) makeHandler(server string) handlers.Handler {
return handlers.NewMaprHandler(server, c.query, c.globalGroup)
}
diff --git a/internal/config/config.go b/internal/config/config.go
index b99b22b..ee23829 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -16,7 +16,7 @@ const (
// DefaultSSHPort is the default DServer port.
DefaultSSHPort int = 2222
// DefaultLogLevel specifies the default log level (obviously)
- DefaultLogLevel string = "INFO"
+ DefaultLogLevel string = "info"
// DefaultClientLogger specifies the default logger for the client commands.
DefaultClientLogger string = "fout"
// DefaultServerLogger specifies the default logger for dtail server.
diff --git a/internal/config/initializer.go b/internal/config/initializer.go
index 0a913db..0c6dfdf 100644
--- a/internal/config/initializer.go
+++ b/internal/config/initializer.go
@@ -147,7 +147,9 @@ func transformClient(in *initializer, args *Args, additionalArgs []string) error
strings.ToLower(args.ServersStr) == "serverless") {
// We are not connecting to any servers.
args.Serverless = true
- in.Common.LogLevel = "warn"
+ if args.LogLevel == DefaultLogLevel {
+ in.Common.LogLevel = "warn"
+ }
}
return nil
}
diff --git a/internal/io/dlog/level.go b/internal/io/dlog/level.go
index 0971094..05d9ed9 100644
--- a/internal/io/dlog/level.go
+++ b/internal/io/dlog/level.go
@@ -9,6 +9,7 @@ type level int
// Available log levels.
const (
+ None level = iota
Fatal level = iota
Error level = iota
Warn level = iota
@@ -26,6 +27,8 @@ var allLevels = []level{Fatal, Error, Warn, Info, Default, Verbose, Debug,
func newLevel(l string) level {
switch strings.ToLower(l) {
+ case "none":
+ return None
case "fatal":
return Fatal
case "error":
@@ -54,6 +57,8 @@ func newLevel(l string) level {
func (l level) String() string {
switch l {
+ case None:
+ return "NONE"
case Fatal:
return "FATAL"
case Error:
diff --git a/internal/io/fs/permissions/permission.go b/internal/io/fs/permissions/permission.go
index e80dbb2..d621c09 100644
--- a/internal/io/fs/permissions/permission.go
+++ b/internal/io/fs/permissions/permission.go
@@ -9,6 +9,6 @@ import (
// ToRead is to check whether user has read permissions to a given file.
func ToRead(user, filePath string) (bool, error) {
// Only implemented for Linux, always expect true
- dlog.Common.Warn(user, filePath, "Not performing ACL check as not compiled in")
+ dlog.Common.Debug(user, filePath, "Not performing ACL check as not compiled in")
return true, nil
}
diff --git a/internal/server/handlers/basehandler.go b/internal/server/handlers/basehandler.go
index 847e8f9..d814cc9 100644
--- a/internal/server/handlers/basehandler.go
+++ b/internal/server/handlers/basehandler.go
@@ -9,6 +9,7 @@ import (
"io"
"strconv"
"strings"
+ "sync"
"sync/atomic"
"time"
@@ -22,7 +23,7 @@ import (
user "github.com/mimecast/dtail/internal/user/server"
)
-type handleCommandCb func(context.Context, int, []string, string, map[string]string)
+type handleCommandCb func(context.Context, int, []string, string)
type baseHandler struct {
done *internal.Done
@@ -35,11 +36,15 @@ type baseHandler struct {
user *user.User
ackCloseReceived chan struct{}
activeCommands int32
- quiet bool
- spartan bool
- serverless int32
readBuf bytes.Buffer
writeBuf bytes.Buffer
+
+ // Some global options + sync primitives required.
+ once sync.Once
+ mutex sync.Mutex
+ quiet bool
+ spartan bool
+ serverless bool
}
// Shutdown the handler.
@@ -66,7 +71,7 @@ func (h *baseHandler) Read(p []byte) (n int, err error) {
return
}
- if h.serverless > 0 {
+ if h.serverless {
return
}
@@ -160,8 +165,9 @@ func (h *baseHandler) handleCommand(commandStr string) {
h.send(h.serverMessages, dlog.Server.Error(h.user, err))
return
}
+ h.setOptions(options)
- h.handleCommandCb(ctx, argc, args, commandName, options)
+ h.handleCommandCb(ctx, argc, args, commandName)
}
func (h *baseHandler) handleProtocolVersion(args []string) ([]string, int, string, error) {
@@ -232,6 +238,28 @@ func (h *baseHandler) handleAckCommand(argc int, args []string) {
}
}
+func (h *baseHandler) setOptions(options map[string]string) {
+ // We have to make sure that this block is executed only once.
+ h.mutex.Lock()
+ defer h.mutex.Unlock()
+ // We can read the options only once, will cause a data race otherwise if
+ // changed multiple times for multiple incoming commands.
+ h.once.Do(func() {
+ if quiet, _ := options["quiet"]; quiet == "true" {
+ dlog.Server.Debug(h.user, "Enabling quiet mode")
+ h.quiet = true
+ }
+ if spartan, _ := options["spartan"]; spartan == "true" {
+ dlog.Server.Debug(h.user, "Enabling spartan mode")
+ h.spartan = true
+ }
+ if serverless, _ := options["serverless"]; serverless == "true" {
+ dlog.Server.Debug(h.user, "Enabling serverless mode")
+ h.serverless = true
+ }
+ })
+}
+
func (h *baseHandler) send(ch chan<- string, message string) {
select {
case ch <- message:
diff --git a/internal/server/handlers/healthhandler.go b/internal/server/handlers/healthhandler.go
index 8d6c400..0425696 100644
--- a/internal/server/handlers/healthhandler.go
+++ b/internal/server/handlers/healthhandler.go
@@ -41,7 +41,7 @@ func NewHealthHandler(user *user.User) *HealthHandler {
}
func (h *HealthHandler) handleHealthCommand(ctx context.Context, argc int,
- args []string, commandName string, options map[string]string) {
+ args []string, commandName string) {
dlog.Server.Debug(h.user, "Handling health command", argc, args)
switch commandName {
diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go
index f12d590..52c4570 100644
--- a/internal/server/handlers/serverhandler.go
+++ b/internal/server/handlers/serverhandler.go
@@ -4,7 +4,6 @@ import (
"context"
"os"
"strings"
- "sync/atomic"
"github.com/mimecast/dtail/internal"
"github.com/mimecast/dtail/internal/io/dlog"
@@ -55,7 +54,7 @@ func NewServerHandler(user *user.User, catLimiter,
}
func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int,
- args []string, commandName string, options map[string]string) {
+ args []string, commandName string) {
dlog.Server.Debug(h.user, "Handling user command", argc, args)
h.incrementActiveCommands()
@@ -65,19 +64,6 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int,
}
}
- if quiet, _ := options["quiet"]; quiet == "true" {
- dlog.Server.Debug(h.user, "Enabling quiet mode")
- h.quiet = true
- }
- if spartan, _ := options["spartan"]; spartan == "true" {
- dlog.Server.Debug(h.user, "Enabling spartan mode")
- h.spartan = true
- }
- if serverless, _ := options["serverless"]; serverless == "true" {
- dlog.Server.Debug(h.user, "Enabling serverless mode")
- atomic.AddInt32(&h.serverless, 1)
- }
-
switch commandName {
case "grep", "cat":
command := newReadCommand(h, omode.CatClient)
@@ -109,7 +95,7 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int,
commandFinished()
default:
h.send(h.serverMessages, dlog.Server.Error(h.user,
- "Received unknown user command", commandName, argc, args, options))
+ "Received unknown user command", commandName, argc, args))
commandFinished()
}
}