Skip to content

Commit

Permalink
#355 NODATA state by TTL
Browse files Browse the repository at this point in the history
* Added attribute lastSuccessfulCheckForNoData in TriggerChecker
* Create instalation lastSuccessfulCheckForNoData in timestamp
  • Loading branch information
Nix O Live committed Sep 4, 2019
1 parent 8e0e101 commit a779d56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 13 additions & 7 deletions checker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func newCheckData(lastCheck *moira.CheckData, checkTimeStamp int64) moira.CheckD
newCheckData.Timestamp = checkTimeStamp
newCheckData.Message = ""
return newCheckData
}
}

func newMetricState(oldMetricState moira.MetricState, newState moira.State, newTimestamp int64, newValue *float64) *moira.MetricState {
newMetricState := oldMetricState
Expand Down Expand Up @@ -170,13 +170,13 @@ func (triggerChecker *TriggerChecker) handleCheckResult(checkData moira.CheckDat
case ErrTriggerHasNoMetrics, ErrTriggerHasOnlyWildcards:
triggerChecker.logger.Debugf("Trigger %s: %s", triggerChecker.triggerID, checkingError.Error())
triggerState := triggerChecker.ttlState.ToTriggerState()
checkData.State = triggerState
checkData.Message = checkingError.Error()
if triggerChecker.ttl == 0 {
checkData.State = triggerState
checkData.Message = checkingError.Error()
if triggerChecker.ttl == 0 {
// Do not alert when user don't wanna receive
// NODATA state alerts, but change trigger status
return checkData, nil
}
return checkData, nil
}
case ErrWrongTriggerTargets, ErrTriggerHasSameMetricNames:
checkData.State = moira.StateERROR
checkData.Message = checkingError.Error()
Expand Down Expand Up @@ -211,10 +211,16 @@ func (triggerChecker *TriggerChecker) checkForNoData(metricData *metricSource.Me
if triggerChecker.ttlState == moira.TTLStateDEL && metricLastState.EventTimestamp != 0 {
return true, nil
}
newTimestamp := lastCheckTimeStamp - triggerChecker.ttl
if triggerChecker.ttlState.ToMetricState() == moira.StateNODATA {
newTimestamp = triggerChecker.lastSuccessfulCheckForNoData
} else {
triggerChecker.lastSuccessfulCheckForNoData = newTimestamp
}
return false, newMetricState(
metricLastState,
triggerChecker.ttlState.ToMetricState(),
lastCheckTimeStamp-triggerChecker.ttl,
newTimestamp,
nil,
)
}
Expand Down
5 changes: 3 additions & 2 deletions checker/trigger_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type TriggerChecker struct {
trigger *moira.Trigger
lastCheck *moira.CheckData

ttl int64
ttlState moira.TTLState
ttl int64
ttlState moira.TTLState
lastSuccessfulCheckForNoData int64
}

// MakeTriggerChecker initialize new triggerChecker data
Expand Down

0 comments on commit a779d56

Please sign in to comment.