Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trigger check lock in handleTriggerInLock #992

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion checker/worker/metric_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ func (manager *WorkerManager) handleMetricEvent(pattern string) error {
start := time.Now()
defer manager.Metrics.MetricEventsHandleTime.UpdateSince(start)

manager.lastData = time.Now().UTC().Unix()
now := time.Now().UTC().Unix()
manager.lastData = now

triggerIds, err := manager.Database.GetPatternTriggerIDs(pattern)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion checker/worker/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (ch *scheduler) triggerScheduler(stop <-chan struct{}) error {
func (ch *scheduler) scheduleTriggersToCheck() error {
err := ch.validateSource()
if err != nil {
ch.manager.Logger.Info().
ch.manager.Logger.Warning().
Error(err).
String("cluster_key", ch.clusterKey.String()).
Msg("Source is invalid. Stop scheduling trigger checks")
Expand Down
3 changes: 2 additions & 1 deletion checker/worker/trigger_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (manager *WorkerManager) handleTrigger(triggerID string, metrics *metrics.C

func (manager *WorkerManager) handleTriggerInLock(triggerID string, metrics *metrics.CheckMetrics) error {
acquired, err := manager.Database.SetTriggerCheckLock(triggerID)
defer manager.Database.DeleteTriggerCheckLock(triggerID) //nolint

if err != nil {
return err
Expand All @@ -57,6 +56,8 @@ func (manager *WorkerManager) handleTriggerInLock(triggerID string, metrics *met
return nil
}

defer manager.Database.DeleteTriggerCheckLock(triggerID) //nolint

startedAt := time.Now()
defer metrics.TriggersCheckTime.UpdateSince(startedAt)

Expand Down
4 changes: 2 additions & 2 deletions checker/worker/worker_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ func (manager *WorkerManager) makeSourceValidator(clusterKey moira.ClusterKey) (
func (manager *WorkerManager) validateGraphiteLocal() error {
now := time.Now().UTC().Unix()

if manager.lastData+manager.Config.StopCheckingIntervalSeconds < now {
if manager.lastData+manager.Config.StopCheckingIntervalSeconds > now {
return nil
}

return fmt.Errorf("graphite local source invalid: no metrics for %d second", manager.Config.StopCheckingIntervalSeconds)
return fmt.Errorf("graphite local source invalid: no metrics for %d second", now-manager.lastData)
}

func (manager *WorkerManager) startCheckerWorker(w *scheduler) error {
Expand Down
Loading