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 <roman@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2021-10-19 16:35:27 +03:00 committed by Aliaksandr Valialkin
parent 0a1982b294
commit 627224d493
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 9 additions and 8 deletions

View file

@ -127,11 +127,16 @@ func main() {
logger.Fatalf("cannot parse configuration file: %s", err) 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 { if err := manager.start(ctx, groupsCfg); err != nil {
logger.Fatalf("failed to start: %s", err) logger.Fatalf("failed to start: %s", err)
} }
go configReload(ctx, manager, groupsCfg) go configReload(ctx, manager, groupsCfg, sighupCh)
rh := &requestHandler{m: manager} rh := &requestHandler{m: manager}
go httpserver.Serve(*httpListenAddr, rh.handler) go httpserver.Serve(*httpListenAddr, rh.handler)
@ -245,12 +250,7 @@ See the docs at https://docs.victoriametrics.com/vmalert.html .
flagutil.Usage(s) flagutil.Usage(s)
} }
func configReload(ctx context.Context, m *manager, groupsCfg []config.Group) { func configReload(ctx context.Context, m *manager, groupsCfg []config.Group, sighupCh <-chan os.Signal) {
// 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()
var configCheckCh <-chan time.Time var configCheckCh <-chan time.Time
if *rulesCheckInterval > 0 { if *rulesCheckInterval > 0 {
ticker := time.NewTicker(*rulesCheckInterval) ticker := time.NewTicker(*rulesCheckInterval)

View file

@ -102,8 +102,9 @@ groups:
} }
syncCh := make(chan struct{}) syncCh := make(chan struct{})
sighupCh := procutil.NewSighupChan()
go func() { go func() {
configReload(ctx, m, nil) configReload(ctx, m, nil, sighupCh)
close(syncCh) close(syncCh)
}() }()