Skip to content

Commit

Permalink
Merge pull request #27 from Cairry/master
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
Cairry authored Apr 24, 2024
2 parents 63d572d + 8c31ca6 commit 93eeed9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 72 deletions.
61 changes: 0 additions & 61 deletions .idea/workspace.xml

This file was deleted.

10 changes: 5 additions & 5 deletions alert/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (rq *RuleQuery) Query(rule models.AlertRule) {

}

func (rq *RuleQuery) alertRecover(rule models.AlertRule, dsId string, curKeys []string) {
func (rq *RuleQuery) alertRecover(rule models.AlertRule, curKeys []string) {
firingKeys := rule.GetFiringAlertCacheKeys()
// 获取已恢复告警的keys
recoverKeys := getSliceDifference(firingKeys, curKeys)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (rq *RuleQuery) prometheus(datasourceId string, rule models.AlertRule) {
var curFiringKeys, curPendingKeys []string
defer func() {
go gcPendingCache(rule, datasourceId, curPendingKeys)
rq.alertRecover(rule, datasourceId, curFiringKeys)
rq.alertRecover(rule, curFiringKeys)
go gcRecoverWaitCache(rule, curFiringKeys)
}()

Expand Down Expand Up @@ -106,7 +106,7 @@ func (rq *RuleQuery) prometheus(datasourceId string, rule models.AlertRule) {
func (rq *RuleQuery) aliCloudSLS(datasourceId string, rule models.AlertRule) {
var curKeys []string
defer func() {
rq.alertRecover(rule, datasourceId, curKeys)
rq.alertRecover(rule, curKeys)
go gcRecoverWaitCache(rule, curKeys)
}()

Expand Down Expand Up @@ -168,7 +168,7 @@ func (rq *RuleQuery) aliCloudSLS(datasourceId string, rule models.AlertRule) {
func (rq *RuleQuery) loki(datasourceId string, rule models.AlertRule) {
var curKeys []string
defer func() {
rq.alertRecover(rule, datasourceId, curKeys)
rq.alertRecover(rule, curKeys)
go gcRecoverWaitCache(rule, curKeys)
}()

Expand Down Expand Up @@ -223,7 +223,7 @@ func (rq *RuleQuery) loki(datasourceId string, rule models.AlertRule) {
func (rq *RuleQuery) jaeger(datasourceId string, rule models.AlertRule) {
var curKeys []string
defer func() {
rq.alertRecover(rule, datasourceId, curKeys)
rq.alertRecover(rule, curKeys)
go gcRecoverWaitCache(rule, curKeys)
}()

Expand Down
22 changes: 16 additions & 6 deletions models/alert_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,26 @@ func (a *AlertRule) ParserRuleToGorm() *AlertRule {

// GetFiringAlertCacheKeys 获取当前规则组中所有的 Firing 告警数据
func (a *AlertRule) GetFiringAlertCacheKeys() []string {
keyPrefix := a.TenantId + ":" + FiringAlertCachePrefix + alertCacheTailKeys(a.RuleId, a.DatasourceId)
keys, _ := globals.RedisCli.Keys(keyPrefix).Result()
return keys
var keyList []string
for _, v := range a.DatasourceIdList {
keyPrefix := a.TenantId + ":" + FiringAlertCachePrefix + alertCacheTailKeys(a.RuleId, v)
keys, _ := globals.RedisCli.Keys(keyPrefix).Result()
keyList = append(keyList, keys...)
}

return keyList
}

// GetPendingAlertCacheKeys 获取当前规则组中所有的 Pending 告警数据
func (a *AlertRule) GetPendingAlertCacheKeys() []string {
keyPrefix := a.TenantId + ":" + PendingAlertCachePrefix + alertCacheTailKeys(a.RuleId, a.DatasourceId)
keys, _ := globals.RedisCli.Keys(keyPrefix).Result()
return keys
var keyList []string
for _, v := range a.DatasourceIdList {
keyPrefix := a.TenantId + ":" + PendingAlertCachePrefix + alertCacheTailKeys(a.RuleId, v)
keys, _ := globals.RedisCli.Keys(keyPrefix).Result()
keyList = append(keyList, keys...)
}

return keyList
}

func alertCacheTailKeys(ruleId, dsId string) string {
Expand Down

0 comments on commit 93eeed9

Please sign in to comment.