Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
nightingale
提交
ae0b036a
N
nightingale
项目概览
DiDi
/
nightingale
9 个月 前同步成功
通知
45
Star
7053
Fork
1161
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
ae0b036a
编写于
8月 27, 2021
作者:
I
Istil
提交者:
GitHub
8月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support to mute by resource classpath_prefix (#785)
上级
351dee6a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
49 addition
and
34 deletion
+49
-34
alert/mute.go
alert/mute.go
+15
-5
cache/alert_mute.go
cache/alert_mute.go
+3
-2
http/router_mute.go
http/router_mute.go
+15
-13
models/mute.go
models/mute.go
+12
-12
sql/n9e.sql
sql/n9e.sql
+1
-0
timer/alert_mute.go
timer/alert_mute.go
+3
-2
未找到文件。
alert/mute.go
浏览文件 @
ae0b036a
package
alert
import
(
"strings"
"github.com/didi/nightingale/v5/cache"
"github.com/didi/nightingale/v5/models"
"github.com/toolkits/pkg/logger"
...
...
@@ -14,13 +16,13 @@ func isEventMute(event *models.AlertEvent) bool {
}
// 先去匹配一下metric为空的mute
if
matchMute
(
""
,
event
.
ResIdent
,
event
.
TagMap
)
{
if
matchMute
(
""
,
event
.
ResIdent
,
event
.
TagMap
,
event
.
ResClasspaths
)
{
return
true
}
// 如果是与条件,就会有多个metric,任一个匹配了屏蔽规则都算被屏蔽
for
i
:=
0
;
i
<
len
(
historyPoints
);
i
++
{
if
matchMute
(
historyPoints
[
i
]
.
Metric
,
event
.
ResIdent
,
event
.
TagMap
)
{
if
matchMute
(
historyPoints
[
i
]
.
Metric
,
event
.
ResIdent
,
event
.
TagMap
,
event
.
ResClasspaths
)
{
return
true
}
}
...
...
@@ -35,7 +37,7 @@ func isEventMute(event *models.AlertEvent) bool {
return
false
}
func
matchMute
(
metric
,
ident
string
,
tags
map
[
string
]
string
)
bool
{
func
matchMute
(
metric
,
ident
string
,
tags
map
[
string
]
string
,
classpaths
string
)
bool
{
filters
,
exists
:=
cache
.
AlertMute
.
GetByKey
(
metric
)
if
!
exists
{
// 没有屏蔽规则跟这个事件相关
...
...
@@ -44,7 +46,7 @@ func matchMute(metric, ident string, tags map[string]string) bool {
// 只要有一个屏蔽规则命中,那这个事件就是被屏蔽了
for
_
,
filter
:=
range
filters
{
if
matchMuteOnce
(
filter
,
ident
,
tags
)
{
if
matchMuteOnce
(
filter
,
ident
,
tags
,
classpaths
)
{
return
true
}
}
...
...
@@ -52,7 +54,15 @@ func matchMute(metric, ident string, tags map[string]string) bool {
return
false
}
func
matchMuteOnce
(
filter
cache
.
Filter
,
ident
string
,
tags
map
[
string
]
string
)
bool
{
func
matchMuteOnce
(
filter
cache
.
Filter
,
ident
string
,
tags
map
[
string
]
string
,
classpaths
string
)
bool
{
if
len
(
filter
.
ClasspathPrefix
)
!=
0
&&
!
strings
.
HasPrefix
(
classpaths
,
filter
.
ClasspathPrefix
)
&&
!
strings
.
Contains
(
classpaths
,
" "
+
filter
.
ClasspathPrefix
)
{
//没配置分组屏蔽就不做后续比较
//比如事件的资源calsspath为“n9e.mon n9e.rdb ccp.web”,配置屏蔽为n9e.rdb
//只要字符串前缀为n9e.rdb或者字符串包含“ n9e.rdb”即可判断所有alsspath中是否有前缀为n9e.rdb的
//只要有任一点不满足,那这个屏蔽规则也没有继续验证下去的必要
return
false
}
if
filter
.
ResReg
!=
nil
&&
!
filter
.
ResReg
.
MatchString
(
ident
)
{
// 比如屏蔽规则配置的是:c3-ceph.*
// 当前事件的资源标识是:c4-ceph01.bj
...
...
cache/alert_mute.go
浏览文件 @
ae0b036a
...
...
@@ -10,8 +10,9 @@ type AlertMuteMap struct {
Data
map
[
string
][]
Filter
}
type
Filter
struct
{
ResReg
*
regexp
.
Regexp
TagsMap
map
[
string
]
string
ClasspathPrefix
string
ResReg
*
regexp
.
Regexp
TagsMap
map
[
string
]
string
}
var
AlertMute
=
&
AlertMuteMap
{
Data
:
make
(
map
[
string
][]
Filter
)}
...
...
http/router_mute.go
浏览文件 @
ae0b036a
...
...
@@ -23,12 +23,13 @@ func muteGets(c *gin.Context) {
}
type
muteForm
struct
{
Metric
string
`json:"metric"`
ResFilters
string
`json:"res_filters"`
TagFilters
string
`json:"tags_filters"`
Cause
string
`json:"cause"`
Btime
int64
`json:"btime"`
Etime
int64
`json:"etime"`
ClasspathPrefix
string
`json:"classpath_prefix "`
Metric
string
`json:"metric"`
ResFilters
string
`json:"res_filters"`
TagFilters
string
`json:"tags_filters"`
Cause
string
`json:"cause"`
Btime
int64
`json:"btime"`
Etime
int64
`json:"etime"`
}
func
muteAdd
(
c
*
gin
.
Context
)
{
...
...
@@ -38,13 +39,14 @@ func muteAdd(c *gin.Context) {
me
:=
loginUser
(
c
)
.
MustPerm
(
"mute_create"
)
mt
:=
models
.
Mute
{
Metric
:
f
.
Metric
,
ResFilters
:
f
.
ResFilters
,
TagFilters
:
f
.
TagFilters
,
Cause
:
f
.
Cause
,
Btime
:
f
.
Btime
,
Etime
:
f
.
Etime
,
CreateBy
:
me
.
Username
,
ClasspathPrefix
:
f
.
ClasspathPrefix
,
Metric
:
f
.
Metric
,
ResFilters
:
f
.
ResFilters
,
TagFilters
:
f
.
TagFilters
,
Cause
:
f
.
Cause
,
Btime
:
f
.
Btime
,
Etime
:
f
.
Etime
,
CreateBy
:
me
.
Username
,
}
renderMessage
(
c
,
mt
.
Add
())
...
...
models/mute.go
浏览文件 @
ae0b036a
...
...
@@ -10,18 +10,18 @@ import (
)
type
Mute
struct
{
Id
int64
`json:"id"`
Metric
string
`json:"metric
"`
ResFilters
string
`json:"res_filters
"`
TagFilters
string
`json:"tag
s_filters"`
Cause
string
`json:"cause
"`
Btime
int64
`json:"btim
e"`
Etime
int64
`json:"e
time"`
CreateBy
string
`json:"create_by
"`
Create
At
int64
`json:"create_at
"`
ResRegexp
*
regexp
.
Regexp
`xorm:"-" json:"-"`
TagsMap
map
[
string
]
string
`xorm:"-" json:"-"`
Id
int64
`json:"id"`
ClasspathPrefix
string
`json:"classpath_prefix
"`
Metric
string
`json:"metric
"`
ResFilters
string
`json:"re
s_filters"`
TagFilters
string
`json:"tags_filters
"`
Cause
string
`json:"caus
e"`
Btime
int64
`json:"b
time"`
Etime
int64
`json:"etime
"`
Create
By
string
`json:"create_by
"`
CreateAt
int64
`json:"create_at"`
ResRegexp
*
regexp
.
Regexp
`xorm:"-" json:"-"`
TagsMap
map
[
string
]
string
`xorm:"-" json:"-"`
}
func
(
m
*
Mute
)
TableName
()
string
{
...
...
sql/n9e.sql
浏览文件 @
ae0b036a
...
...
@@ -160,6 +160,7 @@ CREATE TABLE `classpath_favorite` (
CREATE
TABLE
`mute`
(
`id`
bigint
unsigned
not
null
auto_increment
,
`classpath_prefix`
varchar
(
255
)
not
null
default
''
comment
'classpath prefix'
,
`metric`
varchar
(
255
)
not
null
comment
'required'
,
`res_filters`
varchar
(
4096
)
not
null
default
'resource filters'
,
`tag_filters`
varchar
(
8192
)
not
null
default
''
,
...
...
timer/alert_mute.go
浏览文件 @
ae0b036a
...
...
@@ -58,8 +58,9 @@ func syncAlertMutes() error {
}
filter
:=
cache
.
Filter
{
ResReg
:
mutes
[
i
]
.
ResRegexp
,
TagsMap
:
mutes
[
i
]
.
TagsMap
,
ResReg
:
mutes
[
i
]
.
ResRegexp
,
TagsMap
:
mutes
[
i
]
.
TagsMap
,
ClasspathPrefix
:
mutes
[
i
]
.
ClasspathPrefix
,
}
muteMap
[
mutes
[
i
]
.
Metric
]
=
append
(
muteMap
[
mutes
[
i
]
.
Metric
],
filter
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录