diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-05 08:50:33 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-05 08:50:33 +0200 |
| commit | 5d1b9f1062d38c301c0995ec6da980bdf5e48332 (patch) | |
| tree | 81e1a8963ea66cf06164e89beb6cd2da0ee325f7 /cmd/dgrep | |
| parent | bb46cfbccea301721fb93485ea7169f5841feda3 (diff) | |
Improve lint/vet reliability and refactor client runtime/bootstrap
Diffstat (limited to 'cmd/dgrep')
| -rw-r--r-- | cmd/dgrep/main.go | 47 |
1 files changed, 8 insertions, 39 deletions
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go index 0002c89..0e4eb29 100644 --- a/cmd/dgrep/main.go +++ b/cmd/dgrep/main.go @@ -1,18 +1,12 @@ 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" "github.com/mimecast/dtail/internal/io/signal" "github.com/mimecast/dtail/internal/profiling" "github.com/mimecast/dtail/internal/source" @@ -67,48 +61,23 @@ 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("dgrep")) - defer profiler.Stop() + runtime := cli.NewClientRuntime(nil, profileFlags, "dgrep") if grep != "" { args.RegexStr = grep } - 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.StartPProf(pprof) + runtime.LogStartupMetrics() client, err := clients.NewGrepClient(args) if err != nil { + runtime.Stop() panic(err) } - status := client.Start(ctx, signal.InterruptCh(ctx)) - - // 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.InterruptCh(runtime.Context())) + runtime.LogShutdownMetrics() + runtime.Stop() os.Exit(status) } |
