diff --git a/pkg/checks/base.go b/pkg/checks/base.go index 8f98da6a..bde19e55 100644 --- a/pkg/checks/base.go +++ b/pkg/checks/base.go @@ -69,8 +69,6 @@ type Base struct { Mutex sync.Mutex // Done channel is used to notify about shutdown of a check. Done chan struct{} - // Update is a channel used to notify about configuration updates. - Update chan struct{} // closed is a flag indicating if the check has been shut down. closed bool } @@ -80,7 +78,6 @@ func NewBase() Base { return Base{ Mutex: sync.Mutex{}, Done: make(chan struct{}, 1), - Update: make(chan struct{}, 3), closed: false, } } diff --git a/pkg/checks/base_test.go b/pkg/checks/base_test.go index 47e10493..8721fa65 100644 --- a/pkg/checks/base_test.go +++ b/pkg/checks/base_test.go @@ -12,35 +12,30 @@ func TestBase_Shutdown(t *testing.T) { tests := []struct { name string - b *Base + base *Base }{ { name: "shutdown", - b: &Base{ - Done: make(chan struct{}, 1), - }, + base: &Base{Done: make(chan struct{}, 1)}, }, { name: "already shutdown", - b: &Base{ - Done: make(chan struct{}, 1), - closed: true, - }, + base: &Base{Done: make(chan struct{}, 1), closed: true}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if tt.b.closed { - close(tt.b.Done) + if tt.base.closed { + close(tt.base.Done) } - tt.b.Shutdown() + tt.base.Shutdown() - if !tt.b.closed { + if !tt.base.closed { t.Error("Base.Shutdown() should close Base.Done") } assert.Panics(t, func() { - tt.b.Done <- struct{}{} + tt.base.Done <- struct{}{} }, "Base.Done should be closed") }) } diff --git a/pkg/checks/dns/dns.go b/pkg/checks/dns/dns.go index 2728d1b0..00a2fe62 100644 --- a/pkg/checks/dns/dns.go +++ b/pkg/checks/dns/dns.go @@ -93,11 +93,6 @@ func (ch *check) Run(ctx context.Context, cResult chan checks.ResultDTO) error { return ctx.Err() case <-ch.Done: return nil - case <-ch.Update: - ch.Mutex.Lock() - timer.Reset(ch.config.Interval) - log.DebugContext(ctx, "Interval of dns check updated", "interval", ch.config.Interval.String()) - ch.Mutex.Unlock() case <-timer.C: res := ch.check(ctx) cResult <- checks.ResultDTO{ @@ -119,7 +114,7 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { if c, ok := cfg.(*Config); ok { ch.Mutex.Lock() defer ch.Mutex.Unlock() - if reflect.DeepEqual(ch.config, *c) { + if c == nil || reflect.DeepEqual(&ch.config, c) { return nil } @@ -133,7 +128,6 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { } ch.config = *c - ch.Update <- struct{}{} return nil } diff --git a/pkg/checks/health/health.go b/pkg/checks/health/health.go index 7689df87..5a31e1fb 100644 --- a/pkg/checks/health/health.go +++ b/pkg/checks/health/health.go @@ -80,11 +80,6 @@ func (ch *check) Run(ctx context.Context, cResult chan checks.ResultDTO) error { return ctx.Err() case <-ch.Done: return nil - case <-ch.Update: - ch.Mutex.Lock() - timer.Reset(ch.config.Interval) - log.DebugContext(ctx, "Interval of health check updated", "interval", ch.config.Interval.String()) - ch.Mutex.Unlock() case <-timer.C: res := ch.check(ctx) cResult <- checks.ResultDTO{ @@ -107,7 +102,7 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { if c, ok := cfg.(*Config); ok { ch.Mutex.Lock() defer ch.Mutex.Unlock() - if reflect.DeepEqual(ch.config, *c) { + if c == nil || reflect.DeepEqual(&ch.config, c) { return nil } @@ -121,7 +116,6 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { } ch.config = *c - ch.Update <- struct{}{} return nil } diff --git a/pkg/checks/latency/latency.go b/pkg/checks/latency/latency.go index f187eb1d..d78b318f 100644 --- a/pkg/checks/latency/latency.go +++ b/pkg/checks/latency/latency.go @@ -82,11 +82,6 @@ func (ch *check) Run(ctx context.Context, cResult chan checks.ResultDTO) error { return ctx.Err() case <-ch.Done: return nil - case <-ch.Update: - ch.Mutex.Lock() - timer.Reset(ch.config.Interval) - log.DebugContext(ctx, "Interval of latency check updated", "interval", ch.config.Interval.String()) - ch.Mutex.Unlock() case <-timer.C: res := ch.check(ctx) cResult <- checks.ResultDTO{ @@ -109,7 +104,7 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { if c, ok := cfg.(*Config); ok { ch.Mutex.Lock() defer ch.Mutex.Unlock() - if reflect.DeepEqual(ch.config, *c) { + if c == nil || reflect.DeepEqual(&ch.config, c) { return nil } @@ -123,7 +118,6 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { } ch.config = *c - ch.Update <- struct{}{} return nil } diff --git a/pkg/checks/traceroute/check.go b/pkg/checks/traceroute/check.go index 873e9e3e..2ad5daed 100644 --- a/pkg/checks/traceroute/check.go +++ b/pkg/checks/traceroute/check.go @@ -65,7 +65,7 @@ type check struct { func NewCheck() checks.Check { c := &check{ Base: checks.NewBase(), - config: Config{}, + config: Config{Retry: checks.DefaultRetry}, traceroute: TraceRoute, metrics: newMetrics(), } @@ -105,11 +105,6 @@ func (ch *check) Run(ctx context.Context, cResult chan checks.ResultDTO) error { return ctx.Err() case <-ch.Done: return nil - case <-ch.Update: - ch.Mutex.Lock() - timer.Reset(ch.config.Interval) - log.DebugContext(ctx, "Interval of traceroute check updated", "interval", ch.config.Interval.String()) - ch.Mutex.Unlock() case <-timer.C: res := ch.check(ctx) ch.metrics.MinHops(res) @@ -229,7 +224,7 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { if c, ok := cfg.(*Config); ok { ch.Mutex.Lock() defer ch.Mutex.Unlock() - if reflect.DeepEqual(ch.config, *c) { + if c == nil || reflect.DeepEqual(&ch.config, c) { return nil } @@ -243,7 +238,6 @@ func (ch *check) UpdateConfig(cfg checks.Runtime) error { } ch.config = *c - ch.Update <- struct{}{} return nil }