summaryrefslogtreecommitdiff
path: root/cmd/dmap
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-05 08:50:33 +0200
committerPaul Buetow <paul@buetow.org>2026-03-05 08:50:33 +0200
commit5d1b9f1062d38c301c0995ec6da980bdf5e48332 (patch)
tree81e1a8963ea66cf06164e89beb6cd2da0ee325f7 /cmd/dmap
parentbb46cfbccea301721fb93485ea7169f5841feda3 (diff)
Improve lint/vet reliability and refactor client runtime/bootstrap
Diffstat (limited to 'cmd/dmap')
-rw-r--r--cmd/dmap/main.go50
1 files changed, 11 insertions, 39 deletions
diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go
index 498a09e..ca3981f 100644
--- a/cmd/dmap/main.go
+++ b/cmd/dmap/main.go
@@ -1,15 +1,10 @@
package main
import (
- "context"
"flag"
"os"
- "sync"
-
- "net/http"
- _ "net/http"
- _ "net/http/pprof"
+ "github.com/mimecast/dtail/internal/cli"
"github.com/mimecast/dtail/internal/clients"
"github.com/mimecast/dtail/internal/config"
"github.com/mimecast/dtail/internal/io/dlog"
@@ -67,44 +62,21 @@ func main() {
version.PrintAndExit()
}
- ctx, cancel := context.WithCancel(context.Background())
- var wg sync.WaitGroup
- wg.Add(1)
- dlog.Start(ctx, &wg, source.Client)
-
- // Set up profiling
- profiler := profiling.NewProfiler(profileFlags.ToConfig("dmap"))
- defer profiler.Stop()
-
- if pprof != "" {
- dlog.Client.Info("Starting PProf", pprof)
- go func() {
- panic(http.ListenAndServe(pprof, nil))
- }()
- }
-
- // Log initial metrics if profiling is enabled
- if profileFlags.Enabled() {
- profiler.LogMetrics("startup")
- }
+ runtime := cli.NewClientRuntime(nil, profileFlags, "dmap")
+ runtime.StartPProf(pprof)
+ runtime.LogStartupMetrics()
client, err := clients.NewMaprClient(args, clients.DefaultMode)
if err != nil {
+ runtime.Stop()
dlog.Client.FatalPanic(err)
}
- status := client.Start(ctx, signal.InterruptChWithCancel(ctx, cancel))
-
- // Log final metrics if profiling is enabled
- if profileFlags.Enabled() {
- profiler.LogMetrics("shutdown")
- }
-
- // Stop profiler before exit
- profiler.Stop()
-
- cancel()
-
- wg.Wait()
+ status := client.Start(
+ runtime.Context(),
+ signal.InterruptChWithCancel(runtime.Context(), runtime.Cancel),
+ )
+ runtime.LogShutdownMetrics()
+ runtime.Stop()
os.Exit(status)
}