From 627224d49331de6b8b58033cfa5e47d3d3b432c2 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Tue, 19 Oct 2021 16:35:27 +0300 Subject: [PATCH] vmalert: properly init SIGHUP listener before starting group manager (#1725) Regression was introduced during code refactoring. It potentially could lead to situation when SIGHUP signals were ignored while vmalert was still busy with initing group manager. Signed-off-by: hagen1778 --- app/vmalert/main.go | 14 +++++++------- app/vmalert/main_test.go | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/vmalert/main.go b/app/vmalert/main.go index 7e9c109f3b..775f756b2e 100644 --- a/app/vmalert/main.go +++ b/app/vmalert/main.go @@ -127,11 +127,16 @@ func main() { logger.Fatalf("cannot parse configuration file: %s", err) } + // Register SIGHUP handler for config re-read just before manager.start call. + // This guarantees that the config will be re-read if the signal arrives during manager.start call. + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1240 + sighupCh := procutil.NewSighupChan() + if err := manager.start(ctx, groupsCfg); err != nil { logger.Fatalf("failed to start: %s", err) } - go configReload(ctx, manager, groupsCfg) + go configReload(ctx, manager, groupsCfg, sighupCh) rh := &requestHandler{m: manager} go httpserver.Serve(*httpListenAddr, rh.handler) @@ -245,12 +250,7 @@ See the docs at https://docs.victoriametrics.com/vmalert.html . flagutil.Usage(s) } -func configReload(ctx context.Context, m *manager, groupsCfg []config.Group) { - // Register SIGHUP handler for config re-read just before manager.start call. - // This guarantees that the config will be re-read if the signal arrives during manager.start call. - // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1240 - sighupCh := procutil.NewSighupChan() - +func configReload(ctx context.Context, m *manager, groupsCfg []config.Group, sighupCh <-chan os.Signal) { var configCheckCh <-chan time.Time if *rulesCheckInterval > 0 { ticker := time.NewTicker(*rulesCheckInterval) diff --git a/app/vmalert/main_test.go b/app/vmalert/main_test.go index 8a4174ce3b..7b927805a5 100644 --- a/app/vmalert/main_test.go +++ b/app/vmalert/main_test.go @@ -102,8 +102,9 @@ groups: } syncCh := make(chan struct{}) + sighupCh := procutil.NewSighupChan() go func() { - configReload(ctx, m, nil) + configReload(ctx, m, nil, sighupCh) close(syncCh) }()