From d223c816323f62f7e147a44823796d6bf5fc25f3 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sat, 18 Mar 2023 18:30:52 +0000 Subject: Print stats on shutdown --- cmd_collect.go | 10 ++++------ utils_housekeep.go | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd_collect.go b/cmd_collect.go index b33ceca..4d93271 100644 --- a/cmd_collect.go +++ b/cmd_collect.go @@ -45,12 +45,10 @@ func collect(opts options) error { // properly despite the parent context (including getRanges) // being done. The below is an ugly hack to avoid hanging. // - wait := time.Second * 5 // TODO: 15s - logger.Printf("INFO: about to exit, please wait %v...\n", wait) - select { - case <-time.After(wait): - os.Exit(0) - } + time.Sleep(time.Second) + logger.Printf("INFO: about to exit, please wait...") + time.Sleep(10 * time.Second) + os.Exit(1) }() metricsCh := make(chan metrics) diff --git a/utils_housekeep.go b/utils_housekeep.go index 7a60b27..eb39a7a 100644 --- a/utils_housekeep.go +++ b/utils_housekeep.go @@ -47,21 +47,28 @@ func handleMetrics(ctx context.Context, opts options, logs []metadata.Log, metri } } + output := func(desc string) { + str := "" + for _, log := range logs { + str += sum[*log.Description].String() + } + fmt.Fprintf(os.Stderr, "INFO: %s\n\n%s\n\n", desc, str) + } + defer output("status update before shutdown") + defer time.Sleep(500 * time.Millisecond) + ticker := time.NewTicker(opts.MetricsInterval) defer ticker.Stop() for { select { case <-ctx.Done(): + return case m := <-metricsCh: s := sum[m.Description] s.update(m) sum[m.Description] = s case <-ticker.C: - output := "" - for _, log := range logs { - output += sum[*log.Description].String() - } - fmt.Fprintf(os.Stderr, "INFO: periodic status update\n\n%s\n\n", output) + output("periodic status update") } } } -- cgit v1.2.3