Skip to content

Commit

Permalink
fix : Fix continuous trigger threshold not effective (#329)
Browse files Browse the repository at this point in the history
* fix : Fix continuous trigger threshold not effective

* fix : Optimize indicator alarm rule card display
  • Loading branch information
wzh425 authored Jul 27, 2023
1 parent 0737fbb commit 98908e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
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

0 comments on commit 98908e3

Please sign in to comment.