summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-10-09 21:10:29 +0300
committerPaul Buetow <paul@buetow.org>2021-10-10 13:36:41 +0300
commit97747ea0f3178f7f5890512d483fdccaa82846b0 (patch)
tree9ff1335ca26afc90e55fd6de416457e252d75a35
parent7a7169791a64190e1002e38bc9c04ad0d5c1ce1f (diff)
vetting and linting and some code restyling
-rw-r--r--Makefile4
-rw-r--r--TODO.md4
-rw-r--r--cmd/dcat/main.go3
-rw-r--r--cmd/dgrep/main.go4
-rw-r--r--cmd/dmap/main.go5
-rw-r--r--cmd/dserver/main.go3
-rw-r--r--cmd/dtail/main.go6
-rw-r--r--cmd/dtailhealthcheck/main.go1
-rw-r--r--integrationtests/commons.go15
-rw-r--r--integrationtests/dcat_test.go4
-rw-r--r--integrationtests/dgrep_test.go8
-rw-r--r--integrationtests/dmap_test.go50
-rw-r--r--integrationtests/dtail_test.go4
-rw-r--r--integrationtests/dtailhealthcheck_test.go10
-rw-r--r--internal/clients/baseclient.go7
-rw-r--r--internal/clients/catclient.go2
-rw-r--r--internal/clients/connectors/serverconnection.go48
-rw-r--r--internal/clients/connectors/serverless.go16
-rw-r--r--internal/clients/grepclient.go5
-rw-r--r--internal/clients/handlers/healthhandler.go3
-rw-r--r--internal/clients/handlers/maprhandler.go13
-rw-r--r--internal/clients/healthclient.go17
-rw-r--r--internal/clients/maprclient.go13
-rw-r--r--internal/clients/stats.go11
-rw-r--r--internal/clients/tailclient.go3
-rw-r--r--internal/color/brush/brush.go8
-rw-r--r--internal/color/color.go11
-rw-r--r--internal/color/paint.go19
-rw-r--r--internal/color/table.go19
-rw-r--r--internal/config/args.go6
-rw-r--r--internal/config/client.go12
-rw-r--r--internal/config/config.go6
-rw-r--r--internal/config/initializer.go59
-rw-r--r--internal/config/server.go7
-rw-r--r--internal/discovery/discovery.go13
-rw-r--r--internal/done.go1
-rw-r--r--internal/io/dlog/dlog.go22
-rw-r--r--internal/io/dlog/level.go5
-rw-r--r--internal/io/dlog/loggers/factory.go6
-rw-r--r--internal/io/dlog/loggers/file.go17
-rw-r--r--internal/io/dlog/loggers/logger.go1
-rw-r--r--internal/io/dlog/loggers/strategy.go11
-rw-r--r--internal/io/fs/catfile.go4
-rw-r--r--internal/io/fs/filereader.go3
-rw-r--r--internal/io/fs/permissions/permission_linuxacl.go2
-rw-r--r--internal/io/fs/readfile.go29
-rw-r--r--internal/io/fs/tailfile.go4
-rw-r--r--internal/io/pool/builder.go3
-rw-r--r--internal/io/pool/bytesbuffer.go3
-rw-r--r--internal/io/prompt/prompt.go7
-rw-r--r--internal/io/signal/signal.go3
-rw-r--r--internal/mapr/aggregateset.go4
-rw-r--r--internal/mapr/client/aggregate.go9
-rw-r--r--internal/mapr/funcs/function.go7
-rw-r--r--internal/mapr/funcs/function_test.go21
-rw-r--r--internal/mapr/funcs/maskdigits.go2
-rw-r--r--internal/mapr/globalgroupset.go8
-rw-r--r--internal/mapr/groupset.go9
-rw-r--r--internal/mapr/logformat/default.go5
-rw-r--r--internal/mapr/logformat/default_test.go24
-rw-r--r--internal/mapr/logformat/generickv.go2
-rw-r--r--internal/mapr/logformat/parser.go12
-rw-r--r--internal/mapr/query.go17
-rw-r--r--internal/mapr/query_test.go125
-rw-r--r--internal/mapr/selectcondition.go12
-rw-r--r--internal/mapr/server/aggregate.go30
-rw-r--r--internal/mapr/setclause.go2
-rw-r--r--internal/mapr/setcondition.go15
-rw-r--r--internal/mapr/token.go11
-rw-r--r--internal/mapr/whereclause.go10
-rw-r--r--internal/mapr/wherecondition.go24
-rw-r--r--internal/protocol/protocol.go1
-rw-r--r--internal/regex/regex.go9
-rw-r--r--internal/regex/regex_test.go17
-rw-r--r--internal/server/continuous.go9
-rw-r--r--internal/server/handlers/basehandler.go30
-rw-r--r--internal/server/handlers/healthhandler.go11
-rw-r--r--internal/server/handlers/mapcommand.go7
-rw-r--r--internal/server/handlers/readcommand.go41
-rw-r--r--internal/server/handlers/serverhandler.go20
-rw-r--r--internal/server/scheduler.go9
-rw-r--r--internal/server/server.go47
-rw-r--r--internal/server/stats.go11
-rw-r--r--internal/source/source.go14
-rw-r--r--internal/ssh/client/authmethods.go41
-rw-r--r--internal/ssh/client/customkeycallback.go3
-rw-r--r--internal/ssh/client/knownhostscallback.go19
-rw-r--r--internal/ssh/server/hostkey.go3
-rw-r--r--internal/ssh/server/publickeycallback.go27
-rw-r--r--internal/ssh/ssh.go4
-rw-r--r--internal/user/name.go3
-rw-r--r--internal/user/server/user.go30
-rw-r--r--internal/version/version.go6
93 files changed, 670 insertions, 581 deletions
diff --git a/Makefile b/Makefile
index 6a0f828..543b29e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
GO ?= go
-all: build test
+all: build
build: dserver dcat dgrep dmap dtail dtailhealthcheck
dserver:
ifndef USE_ACL
@@ -43,7 +43,7 @@ lint:
find . -type d | while read dir; do \
echo golint $$dir; \
golint $$dir; \
- done
+ done | grep -F .go:
test:
${GO} clean -testcache
ifndef USE_ACL
diff --git a/TODO.md b/TODO.md
index 45ed4e3..72eb0f3 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
-[ ] Integration test for health check serverless mode
-[ ] Rewrite + test health client (copy catclient)
+[ ] Go through the whole source and change indentation (try not to exceed 80char line lengths by too much)
+[ ] 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 662a50d..87ece9d 100644
--- a/cmd/dcat/main.go
+++ b/cmd/dcat/main.go
@@ -33,7 +33,8 @@ func main() {
flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Trust all unknown host keys")
flag.BoolVar(&displayVersion, "version", false, "Display version")
- flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU,
+ "How many connections established per CPU core concurrently")
flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port")
flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path")
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 529331d..576e22b 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -20,7 +20,6 @@ func main() {
var args config.Args
var displayVersion bool
var grep string
-
userName := user.Name()
flag.BoolVar(&args.NoColor, "noColor", false, "Disable ANSII terminal colors")
@@ -29,7 +28,8 @@ func main() {
flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Trust all unknown host keys")
flag.BoolVar(&displayVersion, "version", false, "Display version")
- flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU,
+ "How many connections established per CPU core concurrently")
flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port")
flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path")
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go
index acc1dc6..1f44076 100644
--- a/cmd/dmap/main.go
+++ b/cmd/dmap/main.go
@@ -19,11 +19,9 @@ import (
// The evil begins here.
func main() {
var displayVersion bool
-
args := config.Args{
Mode: omode.MapClient,
}
-
userName := user.Name()
flag.BoolVar(&args.NoColor, "noColor", false, "Disable ANSII terminal colors")
@@ -31,7 +29,8 @@ func main() {
flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Trust all unknown host keys")
flag.BoolVar(&displayVersion, "version", false, "Display version")
- flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU,
+ "How many connections established per CPU core concurrently")
flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port")
flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path")
diff --git a/cmd/dserver/main.go b/cmd/dserver/main.go
index b4fc873..cf726cf 100644
--- a/cmd/dserver/main.go
+++ b/cmd/dserver/main.go
@@ -32,7 +32,8 @@ func main() {
user.NoRootCheck()
flag.BoolVar(&color, "color", false, "Enable ANSII terminal colors")
- flag.BoolVar(&config.ServerRelaxedAuthEnable, "relaxedAuth", false, "Enable relaxced SSH auth mode (don't use in production!)")
+ flag.BoolVar(&config.ServerRelaxedAuthEnable, "relaxedAuth", false,
+ "Enable relaxced SSH auth mode (don't use in production!)")
flag.BoolVar(&displayVersion, "version", false, "Display version")
flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port")
flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index adfeaa5..2863370 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -44,7 +44,8 @@ func main() {
flag.BoolVar(&displayColorTable, "colorTable", false, "Show color table")
flag.BoolVar(&displayWideColorTable, "wideColorTable", false, "Show a large color table")
flag.BoolVar(&displayVersion, "version", false, "Display version")
- flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU, "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU,
+ "How many connections established per CPU core concurrently")
flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port")
flag.IntVar(&args.Timeout, "timeout", 0, "Max time dtail server will collect data until disconnection")
flag.IntVar(&pprof, "pprof", -1, "Start PProf server this port")
@@ -93,7 +94,8 @@ func main() {
dlog.Start(ctx, &wg, source.Client)
if checkHealth {
- fmt.Println("WARN: DTail health check has moved to separate binary dtailhealtcheck - please adjust the monitoring scripts!")
+ fmt.Println("WARN: DTail health check has moved to separate binary dtailhealtcheck" +
+ " - please adjust the monitoring scripts!")
cancel()
os.Exit(1)
}
diff --git a/cmd/dtailhealthcheck/main.go b/cmd/dtailhealthcheck/main.go
index 0f37f8a..b0ba4cd 100644
--- a/cmd/dtailhealthcheck/main.go
+++ b/cmd/dtailhealthcheck/main.go
@@ -35,7 +35,6 @@ func main() {
defer cancel()
var wg sync.WaitGroup
wg.Add(1)
-
dlog.Start(ctx, &wg, source.HealthCheck)
if pprof > -1 {
diff --git a/integrationtests/commons.go b/integrationtests/commons.go
index f96b532..2fdbfc3 100644
--- a/integrationtests/commons.go
+++ b/integrationtests/commons.go
@@ -15,10 +15,12 @@ import (
)
func runCommand(t *testing.T, cmd string, args []string, stdoutFile string) (int, error) {
- return runCommandContext(t, context.TODO(), cmd, args, stdoutFile)
+ return runCommandContext(context.TODO(), t, cmd, args, stdoutFile)
}
-func runCommandContext(t *testing.T, ctx context.Context, cmd string, args []string, stdoutFile string) (int, error) {
+func runCommandContext(ctx context.Context, t *testing.T, cmd string, args []string,
+ stdoutFile string) (int, error) {
+
if _, err := os.Stat(cmd); err != nil {
return -1, fmt.Errorf("No such binary %s, please compile first (%v)", cmd, err)
}
@@ -76,7 +78,8 @@ func compareFilesContents(t *testing.T, fileA, fileB string) error {
return fmt.Errorf("Files differ, line '%s' is missing in one of them", line)
}
if countA != countB {
- return fmt.Errorf("Files differ, count of line '%s' is %d in one but %d in another", line, countA, countB)
+ return fmt.Errorf("Files differ, count of line '%s' is %d in one but %d in another",
+ line, countA, countB)
}
}
return nil
@@ -92,11 +95,13 @@ func compareFilesContents(t *testing.T, fileA, fileB string) error {
}
// The mapreduce result can be in a different order each time (Golang maps are not sorted).
- t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)", fileA, fileB))
+ t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)",
+ fileA, fileB))
if err := compareMaps(a, b); err != nil {
return err
}
- t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)", fileB, fileA))
+ t.Log(fmt.Sprintf("Checking whether %s has same lines as file %s (ignoring line order)",
+ fileB, fileA))
if err := compareMaps(b, a); err != nil {
return err
}
diff --git a/integrationtests/dcat_test.go b/integrationtests/dcat_test.go
index a164960..342ebd0 100644
--- a/integrationtests/dcat_test.go
+++ b/integrationtests/dcat_test.go
@@ -8,12 +8,12 @@ import (
func TestDCat(t *testing.T) {
testdataFile := "dcat.txt.expected"
stdoutFile := "dcat.out"
+ args := []string{"-spartan", testdataFile}
- if _, err := runCommand(t, "../dcat", []string{"-spartan", testdataFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dcat", args, stdoutFile); err != nil {
t.Error(err)
return
}
-
if err := compareFiles(t, stdoutFile, testdataFile); err != nil {
t.Error(err)
return
diff --git a/integrationtests/dgrep_test.go b/integrationtests/dgrep_test.go
index 6a15ebd..4d54a2d 100644
--- a/integrationtests/dgrep_test.go
+++ b/integrationtests/dgrep_test.go
@@ -9,12 +9,12 @@ func TestDGrep(t *testing.T) {
inFile := "mapr_testdata.log"
stdoutFile := "dgrep.stdout.tmp"
expectedStdoutFile := "dgrep.txt.expected"
+ args := []string{"-spartan", "--grep", "20211002-071947", inFile}
- if _, err := runCommand(t, "../dgrep", []string{"-spartan", "--grep", "20211002-071947", inFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dgrep", args, stdoutFile); err != nil {
t.Error(err)
return
}
-
if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil {
t.Error(err)
return
@@ -26,12 +26,12 @@ func TestDGrep2(t *testing.T) {
inFile := "mapr_testdata.log"
stdoutFile := "dgrep2.stdout.tmp"
expectedStdoutFile := "dgrep2.txt.expected"
+ args := []string{"-spartan", "--grep", "20211002-071947", "--invert", inFile}
- if _, err := runCommand(t, "../dgrep", []string{"-spartan", "--grep", "20211002-071947", "--invert", inFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dgrep", args, stdoutFile); err != nil {
t.Error(err)
return
}
-
if err := compareFiles(t, stdoutFile, expectedStdoutFile); err != nil {
t.Error(err)
return
diff --git a/integrationtests/dmap_test.go b/integrationtests/dmap_test.go
index b512985..f5c78e0 100644
--- a/integrationtests/dmap_test.go
+++ b/integrationtests/dmap_test.go
@@ -14,9 +14,12 @@ func TestDMap(t *testing.T) {
queryFile := fmt.Sprintf("%s.query", csvFile)
expectedQueryFile := "dmap.csv.query.expected"
- query := fmt.Sprintf("from STATS select count($line),last($time),avg($goroutines),min(concurrentConnections),max(lifetimeConnections) group by $hostname outfile %s", csvFile)
+ query := fmt.Sprintf("from STATS select count($line),last($time),"+
+ "avg($goroutines),min(concurrentConnections),max(lifetimeConnections) "+
+ "group by $hostname outfile %s", csvFile)
+ args := []string{"-query", query, inFile}
- if _, err := runCommand(t, "../dmap", []string{"-query", query, inFile}, stdoutFile); err != nil {
+ if _, err := runCommand(t, "../dmap", args, stdoutFile); err != nil {
t.Error(err)
return
}
@@ -42,9 +45,48 @@ func TestDMap2(t *testing.T) {
queryFile := fmt.Sprintf("%s.query", csvFile)
expectedQueryFile := "dmap2.csv.query.expected"
- query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),avg($goroutines),min($goroutines) group by $time order by count($time) outfile %s", csvFile)
+ query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
+ "avg($goroutines),min($goroutines) group by $time order by count($time) "+
+ "outfile %s", csvFile)
- if _, err := runCommand(t, "../dmap", []string{"-query", query, inFile}, stdoutFile); err != nil {
+ args := []string{"-query", query, inFile}
+ if _, err := runCommand(t, "../dmap", args, stdoutFile); err != nil {
+ t.Error(err)
+ return
+ }
+ if err := compareFilesContents(t, csvFile, expectedCsvFile); err != nil {
+ t.Error(err)
+ return
+ }
+ if err := compareFiles(t, queryFile, expectedQueryFile); err != nil {
+ t.Error(err)
+ return
+ }
+
+ os.Remove(stdoutFile)
+ os.Remove(csvFile)
+ os.Remove(queryFile)
+}
+
+func TestDMap3(t *testing.T) {
+ inFile := "mapr_testdata.log"
+ stdoutFile := "dmap3.stdout.tmp"
+ csvFile := "dmap3.csv.tmp"
+ expectedCsvFile := "dmap3.csv.expected"
+ queryFile := fmt.Sprintf("%s.query", csvFile)
+ expectedQueryFile := "dmap3.csv.query.expected"
+
+ query := fmt.Sprintf("from STATS select count($time),$time,max($goroutines),"+
+ "avg($goroutines),min($goroutines) group by $time order by count($time) "+
+ "outfile %s", csvFile)
+
+ // Read many input files at once.
+ args := []string{"-query", query}
+ for i := 0; i < 100; i++ {
+ args = append(arg