Rule manager: remove blocking channel in mail (#7631)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
52cdcc2a3b
commit
b83cbacbdd
|
@ -660,18 +660,14 @@ func main() {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// Rule manager.
|
// Rule manager.
|
||||||
// TODO(krasi) refactor ruleManager.Run() to be blocking to avoid using an extra blocking channel.
|
|
||||||
cancel := make(chan struct{})
|
|
||||||
g.Add(
|
g.Add(
|
||||||
func() error {
|
func() error {
|
||||||
<-reloadReady.C
|
<-reloadReady.C
|
||||||
ruleManager.Run()
|
ruleManager.Run()
|
||||||
<-cancel
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(err error) {
|
func(err error) {
|
||||||
ruleManager.Stop()
|
ruleManager.Stop()
|
||||||
close(cancel)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -875,8 +875,13 @@ func NewManager(o *ManagerOptions) *Manager {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts processing of the rule manager.
|
// Run starts processing of the rule manager. It is blocking.
|
||||||
func (m *Manager) Run() {
|
func (m *Manager) Run() {
|
||||||
|
m.start()
|
||||||
|
<-m.done
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) start() {
|
||||||
close(m.block)
|
close(m.block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -716,7 +716,7 @@ func TestUpdate(t *testing.T) {
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
Logger: log.NewNopLogger(),
|
Logger: log.NewNopLogger(),
|
||||||
})
|
})
|
||||||
ruleManager.Run()
|
ruleManager.start()
|
||||||
defer ruleManager.Stop()
|
defer ruleManager.Stop()
|
||||||
|
|
||||||
err := ruleManager.Update(10*time.Second, files, nil)
|
err := ruleManager.Update(10*time.Second, files, nil)
|
||||||
|
@ -906,8 +906,8 @@ func TestMetricsUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
storage := teststorage.New(t)
|
storage := teststorage.New(t)
|
||||||
registry := prometheus.NewRegistry()
|
|
||||||
defer storage.Close()
|
defer storage.Close()
|
||||||
|
registry := prometheus.NewRegistry()
|
||||||
opts := promql.EngineOpts{
|
opts := promql.EngineOpts{
|
||||||
Logger: nil,
|
Logger: nil,
|
||||||
Reg: nil,
|
Reg: nil,
|
||||||
|
@ -923,7 +923,7 @@ func TestMetricsUpdate(t *testing.T) {
|
||||||
Logger: log.NewNopLogger(),
|
Logger: log.NewNopLogger(),
|
||||||
Registerer: registry,
|
Registerer: registry,
|
||||||
})
|
})
|
||||||
ruleManager.Run()
|
ruleManager.start()
|
||||||
defer ruleManager.Stop()
|
defer ruleManager.Stop()
|
||||||
|
|
||||||
countMetrics := func() int {
|
countMetrics := func() int {
|
||||||
|
@ -997,7 +997,7 @@ func TestGroupStalenessOnRemoval(t *testing.T) {
|
||||||
Logger: log.NewNopLogger(),
|
Logger: log.NewNopLogger(),
|
||||||
})
|
})
|
||||||
var stopped bool
|
var stopped bool
|
||||||
ruleManager.Run()
|
ruleManager.start()
|
||||||
defer func() {
|
defer func() {
|
||||||
if !stopped {
|
if !stopped {
|
||||||
ruleManager.Stop()
|
ruleManager.Stop()
|
||||||
|
@ -1074,7 +1074,7 @@ func TestMetricsStalenessOnManagerShutdown(t *testing.T) {
|
||||||
Logger: log.NewNopLogger(),
|
Logger: log.NewNopLogger(),
|
||||||
})
|
})
|
||||||
var stopped bool
|
var stopped bool
|
||||||
ruleManager.Run()
|
ruleManager.start()
|
||||||
defer func() {
|
defer func() {
|
||||||
if !stopped {
|
if !stopped {
|
||||||
ruleManager.Stop()
|
ruleManager.Stop()
|
||||||
|
|
Loading…
Reference in New Issue