Rule manager: remove blocking channel in mail (#7631)

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-07-22 00:13:24 +02:00 committed by GitHub
parent 52cdcc2a3b
commit b83cbacbdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View file

@ -660,18 +660,14 @@ func main() {
}
{
// Rule manager.
// TODO(krasi) refactor ruleManager.Run() to be blocking to avoid using an extra blocking channel.
cancel := make(chan struct{})
g.Add(
func() error {
<-reloadReady.C
ruleManager.Run()
<-cancel
return nil
},
func(err error) {
ruleManager.Stop()
close(cancel)
},
)
}

View file

@ -875,8 +875,13 @@ func NewManager(o *ManagerOptions) *Manager {
return m
}
// Run starts processing of the rule manager.
// Run starts processing of the rule manager. It is blocking.
func (m *Manager) Run() {
m.start()
<-m.done
}
func (m *Manager) start() {
close(m.block)
}

View file

@ -716,7 +716,7 @@ func TestUpdate(t *testing.T) {
Context: context.Background(),
Logger: log.NewNopLogger(),
})
ruleManager.Run()
ruleManager.start()
defer ruleManager.Stop()
err := ruleManager.Update(10*time.Second, files, nil)
@ -906,8 +906,8 @@ func TestMetricsUpdate(t *testing.T) {
}
storage := teststorage.New(t)
registry := prometheus.NewRegistry()
defer storage.Close()
registry := prometheus.NewRegistry()
opts := promql.EngineOpts{
Logger: nil,
Reg: nil,
@ -923,7 +923,7 @@ func TestMetricsUpdate(t *testing.T) {
Logger: log.NewNopLogger(),
Registerer: registry,
})
ruleManager.Run()
ruleManager.start()
defer ruleManager.Stop()
countMetrics := func() int {
@ -997,7 +997,7 @@ func TestGroupStalenessOnRemoval(t *testing.T) {
Logger: log.NewNopLogger(),
})
var stopped bool
ruleManager.Run()
ruleManager.start()
defer func() {
if !stopped {
ruleManager.Stop()
@ -1074,7 +1074,7 @@ func TestMetricsStalenessOnManagerShutdown(t *testing.T) {
Logger: log.NewNopLogger(),
})
var stopped bool
ruleManager.Run()
ruleManager.start()
defer func() {
if !stopped {
ruleManager.Stop()