Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
a3d44252
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a3d44252
编写于
3月 09, 2021
作者:
J
junotx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix alerts unretriggered when updating rule
Signed-off-by:
N
junotx
<
junotx@126.com
>
上级
6f719e0a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
77 addition
and
13 deletion
+77
-13
pkg/models/alerting/rules/ruler.go
pkg/models/alerting/rules/ruler.go
+77
-13
未找到文件。
pkg/models/alerting/rules/ruler.go
浏览文件 @
a3d44252
...
...
@@ -102,36 +102,100 @@ func (r *ruleResource) deleteAlertingRules(rules ...*RuleWithGroup) (bool, error
// If there are rules to be updated, return true to indicate the resource should be updated.
func
(
r
*
ruleResource
)
updateAlertingRules
(
rules
...*
RuleWithGroup
)
(
bool
,
error
)
{
var
(
commit
bool
spec
=
r
.
Spec
.
DeepCopy
()
ruleMap
=
make
(
map
[
string
]
*
RuleWithGroup
)
commit
bool
spec
=
r
.
Spec
.
DeepCopy
()
ruleMap
=
make
(
map
[
string
]
*
RuleWithGroup
)
ruleGroups
=
make
(
map
[
string
]
map
[
string
]
struct
{})
// mapping of name to group
)
if
spec
==
nil
{
return
false
,
nil
}
spec
.
Groups
=
nil
for
i
,
rule
:=
range
rules
{
if
rule
!=
nil
{
ruleMap
[
rule
.
Alert
]
=
rules
[
i
]
ruleGroups
[
rule
.
Alert
]
=
make
(
map
[
string
]
struct
{})
}
}
// Firstly delete the old rules
for
_
,
g
:=
range
r
.
Spec
.
Groups
{
var
rules
[]
promresourcesv1
.
Rule
for
_
,
r
:=
range
g
.
Rules
{
if
r
.
Alert
!=
""
{
if
_
,
ok
:=
ruleMap
[
r
.
Alert
];
ok
{
ruleGroups
[
r
.
Alert
][
g
.
Name
]
=
struct
{}{}
commit
=
true
continue
}
}
rules
=
append
(
rules
,
r
)
}
if
len
(
rules
)
>
0
{
spec
.
Groups
=
append
(
spec
.
Groups
,
promresourcesv1
.
RuleGroup
{
Name
:
g
.
Name
,
Interval
:
g
.
Interval
,
PartialResponseStrategy
:
g
.
PartialResponseStrategy
,
Rules
:
rules
,
})
}
}
addRules
:=
func
(
g
*
promresourcesv1
.
RuleGroup
)
bool
{
var
add
bool
var
num
=
customRuleGroupSize
-
len
(
g
.
Rules
)
if
num
>
0
{
for
name
,
rule
:=
range
ruleMap
{
if
num
<=
0
{
break
}
if
gNames
,
ok
:=
ruleGroups
[
name
];
ok
{
// Add a rule to a different group than the group where it resided, to clear its alerts, etc.
// Because Prometheus may migrate information such as alerts from the old rule into the new rule
// when updating a rule within a group.
if
_
,
ok
:=
gNames
[
g
.
Name
];
!
ok
{
g
.
Rules
=
append
(
g
.
Rules
,
rule
.
Rule
)
num
--
delete
(
ruleMap
,
name
)
add
=
true
}
}
}
}
return
add
}
// Then add the new rules
var
groupMax
=
-
1
for
i
,
g
:=
range
spec
.
Groups
{
for
j
,
r
:=
range
g
.
Rules
{
if
r
.
Alert
==
""
{
if
len
(
ruleMap
)
==
0
{
break
}
if
strings
.
HasPrefix
(
g
.
Name
,
customRuleGroupDefaultPrefix
)
{
suf
,
err
:=
strconv
.
Atoi
(
strings
.
TrimPrefix
(
g
.
Name
,
customRuleGroupDefaultPrefix
))
if
err
!=
nil
{
continue
}
if
b
,
ok
:=
ruleMap
[
r
.
Alert
];
ok
{
if
b
==
nil
{
spec
.
Groups
[
i
]
.
Rules
=
append
(
g
.
Rules
[
:
j
],
g
.
Rules
[
j
+
1
:
]
...
)
}
else
{
spec
.
Groups
[
i
]
.
Rules
[
j
]
=
b
.
Rule
ruleMap
[
r
.
Alert
]
=
nil
// clear to mark it updated
}
commit
=
true
if
suf
>
groupMax
{
groupMax
=
suf
}
}
if
addRules
(
&
spec
.
Groups
[
i
])
{
commit
=
true
}
}
for
groupMax
++
;
len
(
ruleMap
)
>
0
;
groupMax
++
{
g
:=
promresourcesv1
.
RuleGroup
{
Name
:
fmt
.
Sprintf
(
"%s%d"
,
customRuleGroupDefaultPrefix
,
groupMax
)}
if
addRules
(
&
g
)
{
spec
.
Groups
=
append
(
spec
.
Groups
,
g
)
commit
=
true
}
}
if
commit
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录