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 : Fix continuous trigger threshold not effective #329

Merged
merged 2 commits into from
Jul 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ public class TriggerAlarmEventHandler
{
private readonly IAlarmHistoryRepository _repository;
private readonly IAlarmRuleRepository _alarmRulerepository;
private readonly IEventBus _eventBus;

public TriggerAlarmEventHandler(IAlarmHistoryRepository repository
, IAlarmRuleRepository alarmRulerepository
, IEventBus eventBus)
, IAlarmRuleRepository alarmRulerepository)
{
_repository = repository;
_alarmRulerepository = alarmRulerepository;
_eventBus = eventBus;
}

[EventHandler]
Expand All @@ -31,7 +28,7 @@ public async Task HandleEventAsync(TriggerAlarmEvent eto)
if (alarm == null || alarm.RecoveryTime.HasValue)
{
alarm = new AlarmHistory(eto.AlarmRuleId, eto.AlertSeverity, isNotification, eto.TriggerRuleItems);
alarm.AddAlarmRuleRecord(eto.ExcuteTime, eto.AggregateResult, true, 1, eto.TriggerRuleItems);
alarm.AddAlarmRuleRecord(eto.ExcuteTime, eto.AggregateResult, true, eto.ConsecutiveCount, eto.TriggerRuleItems);
alarm.SetIsNotification(isNotification, isSilence);
await _repository.AddAsync(alarm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,9 @@ public void RecoveryAlarm(DateTimeOffset excuteTime, ConcurrentDictionary<string
AddDomainEvent(new RecoveryAlarmEvent(Id, excuteTime, aggregateResult, ruleResult));
}

public bool IsTrigger(List<RuleResultItem> ruleResult, int consecutiveCount)
public bool IsRuleValid(List<RuleResultItem> ruleResult)
{
var isValid = ruleResult.Any(x => x.IsValid);
return isValid && consecutiveCount > ContinuousTriggerThreshold;
return ruleResult.Any(x => x.IsValid);
}

public void SkipCheck(DateTimeOffset excuteTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public async Task CheckRuleAsync(DateTimeOffset excuteTime, AlarmRule alarmRule,
var cacheKey = $"{AlarmCacheKeys.ALARM_CONSECUTIVE_COUNT}_{alarmRule.Id}";
var consecutiveCount = Convert.ToInt32(await _cacheClient.HashIncrementAsync(cacheKey));

var isTrigger = alarmRule.IsTrigger(ruleResult, consecutiveCount);
var isRuleValid = alarmRule.IsRuleValid(ruleResult);
var isTrigger = isRuleValid && consecutiveCount >= alarmRule.ContinuousTriggerThreshold;

if (isTrigger)
{
Expand All @@ -61,8 +62,13 @@ public async Task CheckRuleAsync(DateTimeOffset excuteTime, AlarmRule alarmRule,
}
else
{
alarmRule.AddAggregateResult(excuteTime, aggregateResult, false, 0, ruleResult);
await _cacheClient.RemoveAsync<long>(cacheKey);
if (!isRuleValid)
{
consecutiveCount = 0;
await _cacheClient.RemoveAsync<long>(cacheKey);
}

alarmRule.AddAggregateResult(excuteTime, aggregateResult, false, consecutiveCount, ruleResult);
}

await _repository.UpdateAsync(alarmRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
{
foreach (var item in _metricMonitorItems)
{
<MChip Class="rounded-3 body2 default-tag mr-3 mt-3" Color="emphasis2" Outlined Style="max-width: 98px;">
@item.Aggregation.Name
<MChip Class="rounded-3 body2 default-tag mr-3 mt-3" Color="emphasis2" Outlined>
<EllipsisText>@item.Aggregation.Name</EllipsisText>
</MChip>
}
}
Expand Down