Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Nightingale
提交
616d56d5
N
Nightingale
项目概览
jobily
/
Nightingale
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Nightingale
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
616d56d5
编写于
9月 01, 2023
作者:
T
Tripitakav
提交者:
GitHub
9月 01, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support loki datasources (#1700)
上级
10a0b509
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
52 addition
and
15 deletion
+52
-15
alert/eval/alert_rule.go
alert/eval/alert_rule.go
+12
-0
alert/eval/eval.go
alert/eval/eval.go
+3
-1
center/cconf/plugin.go
center/cconf/plugin.go
+6
-0
center/router/router_datasource.go
center/router/router_datasource.go
+12
-0
center/router/router_mute.go
center/router/router_mute.go
+4
-4
center/router/router_notify_config.go
center/router/router_notify_config.go
+1
-1
front/statik/statik.go
front/statik/statik.go
+2
-4
models/alert_rule.go
models/alert_rule.go
+5
-2
pkg/poster/post.go
pkg/poster/post.go
+2
-2
prom/reader.go
prom/reader.go
+4
-0
pushgw/router/router_opentsdb_easyjson.go
pushgw/router/router_opentsdb_easyjson.go
+1
-1
未找到文件。
alert/eval/alert_rule.go
浏览文件 @
616d56d5
...
...
@@ -107,6 +107,18 @@ func (s *Scheduler) syncAlertRules() {
alertRule
:=
NewAlertRuleWorker
(
rule
,
dsId
,
processor
,
s
.
promClients
,
s
.
ctx
)
alertRuleWorkers
[
alertRule
.
Hash
()]
=
alertRule
}
}
else
if
rule
.
IsLokiRule
()
{
datasourceIds
:=
s
.
promClients
.
Hit
(
rule
.
DatasourceIdsJson
)
for
_
,
dsId
:=
range
datasourceIds
{
if
!
naming
.
DatasourceHashRing
.
IsHit
(
dsId
,
fmt
.
Sprintf
(
"%d"
,
rule
.
Id
),
s
.
aconf
.
Heartbeat
.
Endpoint
)
{
continue
}
processor
:=
process
.
NewProcessor
(
rule
,
dsId
,
s
.
alertRuleCache
,
s
.
targetCache
,
s
.
busiGroupCache
,
s
.
alertMuteCache
,
s
.
datasourceCache
,
s
.
promClients
,
s
.
ctx
,
s
.
stats
)
alertRuleWorker
:=
NewAlertRuleWorker
(
rule
,
dsId
,
processor
,
s
.
promClients
,
s
.
ctx
)
alertRuleWorkers
[
alertRuleWorker
.
Hash
()]
=
alertRuleWorker
}
}
else
if
rule
.
IsHostRule
()
&&
s
.
ctx
.
IsCenter
{
// all host rule will be processed by center instance
if
!
naming
.
DatasourceHashRing
.
IsHit
(
naming
.
HostDatasource
,
fmt
.
Sprintf
(
"%d"
,
rule
.
Id
),
s
.
aconf
.
Heartbeat
.
Endpoint
)
{
...
...
alert/eval/eval.go
浏览文件 @
616d56d5
...
...
@@ -87,7 +87,7 @@ func (arw *AlertRuleWorker) Start() {
func
(
arw
*
AlertRuleWorker
)
Eval
()
{
cachedRule
:=
arw
.
rule
if
cachedRule
==
nil
{
//logger.Errorf("rule_eval:%s rule not found", arw.Key())
//
logger.Errorf("rule_eval:%s rule not found", arw.Key())
return
}
...
...
@@ -98,6 +98,8 @@ func (arw *AlertRuleWorker) Eval() {
lst
=
arw
.
GetPromAnomalyPoint
(
cachedRule
.
RuleConfig
)
case
models
.
HOST
:
lst
=
arw
.
GetHostAnomalyPoint
(
cachedRule
.
RuleConfig
)
case
models
.
LOKI
:
lst
=
arw
.
GetPromAnomalyPoint
(
cachedRule
.
RuleConfig
)
default
:
return
}
...
...
center/cconf/plugin.go
浏览文件 @
616d56d5
...
...
@@ -13,4 +13,10 @@ var Plugins = []Plugin{
Type
:
"elasticsearch"
,
TypeName
:
"Elasticsearch"
,
},
{
Id
:
2
,
Category
:
"loki"
,
Type
:
"loki"
,
TypeName
:
"Loki"
,
},
}
center/router/router_datasource.go
浏览文件 @
616d56d5
...
...
@@ -151,6 +151,18 @@ func DatasourceCheck(ds models.Datasource) error {
}
}
if
ds
.
PluginType
==
models
.
LOKI
{
subPath
:=
"/api/v1/labels"
fullURL
=
fmt
.
Sprintf
(
"%s%s"
,
ds
.
HTTPJson
.
Url
,
subPath
)
req
,
err
=
http
.
NewRequest
(
"GET"
,
fullURL
,
nil
)
if
err
!=
nil
{
logger
.
Errorf
(
"Error creating request: %v"
,
err
)
return
fmt
.
Errorf
(
"request url:%s failed"
,
fullURL
)
}
}
if
ds
.
AuthJson
.
BasicAuthUser
!=
""
{
req
.
SetBasicAuth
(
ds
.
AuthJson
.
BasicAuthUser
,
ds
.
AuthJson
.
BasicAuthPassword
)
}
...
...
center/router/router_mute.go
浏览文件 @
616d56d5
...
...
@@ -40,10 +40,10 @@ func (rt *Router) alertMuteAdd(c *gin.Context) {
ginx
.
NewRender
(
c
)
.
Message
(
f
.
Add
(
rt
.
Ctx
))
}
//Preview events (alert_cur_event) that match the mute strategy based on the following criteria:
//business group ID (group_id, group_id), product (prod, rule_prod),
//alert event severity (severities, severity), and event tags (tags, tags).
//For products of type not 'host', also consider the category (cate, cate) and datasource ID (datasource_ids, datasource_id).
//
Preview events (alert_cur_event) that match the mute strategy based on the following criteria:
//
business group ID (group_id, group_id), product (prod, rule_prod),
//
alert event severity (severities, severity), and event tags (tags, tags).
//
For products of type not 'host', also consider the category (cate, cate) and datasource ID (datasource_ids, datasource_id).
func
(
rt
*
Router
)
alertMutePreview
(
c
*
gin
.
Context
)
{
//Generally the match of events would be less.
...
...
center/router/router_notify_config.go
浏览文件 @
616d56d5
...
...
@@ -203,7 +203,7 @@ type form struct {
Email
string
`json:"email"`
}
//After configuring the aconf.SMTPConfig, users can choose to perform a test. In this test, the function attempts to send an email
//
After configuring the aconf.SMTPConfig, users can choose to perform a test. In this test, the function attempts to send an email
func
(
rt
*
Router
)
attemptSendEmail
(
c
*
gin
.
Context
)
{
var
f
form
ginx
.
BindJSON
(
c
,
&
f
)
...
...
front/statik/statik.go
浏览文件 @
616d56d5
...
...
@@ -6,9 +6,7 @@ import (
"github.com/rakyll/statik/fs"
)
func
init
()
{
data
:=
"PK
\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
"
fs
.
Register
(
data
)
}
\ No newline at end of file
fs
.
Register
(
data
)
}
models/alert_rule.go
浏览文件 @
616d56d5
...
...
@@ -18,6 +18,7 @@ import (
const
(
METRIC
=
"metric"
HOST
=
"host"
LOKI
=
"loki"
PROMETHEUS
=
"prometheus"
)
...
...
@@ -420,7 +421,7 @@ func (ar *AlertRule) FillDatasourceIds() error {
func
(
ar
*
AlertRule
)
FillSeverities
()
error
{
if
ar
.
RuleConfig
!=
""
{
if
ar
.
Cate
==
PROMETHEUS
{
if
ar
.
Cate
==
PROMETHEUS
||
ar
.
Cate
==
LOKI
{
var
rule
PromRuleConfig
if
err
:=
json
.
Unmarshal
([]
byte
(
ar
.
RuleConfig
),
&
rule
);
err
!=
nil
{
return
err
...
...
@@ -787,7 +788,9 @@ func AlertRuleStatistics(ctx *ctx.Context) (*Statistics, error) {
func
(
ar
*
AlertRule
)
IsPrometheusRule
()
bool
{
return
ar
.
Prod
==
METRIC
&&
ar
.
Cate
==
PROMETHEUS
}
func
(
ar
*
AlertRule
)
IsLokiRule
()
bool
{
return
ar
.
Prod
==
LOKI
}
func
(
ar
*
AlertRule
)
IsHostRule
()
bool
{
return
ar
.
Prod
==
HOST
}
...
...
pkg/poster/post.go
浏览文件 @
616d56d5
...
...
@@ -52,11 +52,11 @@ func GetByUrl[T any](url string, cfg conf.CenterApi) (T, error) {
if
len
(
cfg
.
BasicAuthUser
)
>
0
{
req
.
SetBasicAuth
(
cfg
.
BasicAuthUser
,
cfg
.
BasicAuthPass
)
}
if
cfg
.
Timeout
<
1
{
cfg
.
Timeout
=
5000
}
client
:=
&
http
.
Client
{
Timeout
:
time
.
Duration
(
cfg
.
Timeout
)
*
time
.
Millisecond
,
}
...
...
prom/reader.go
浏览文件 @
616d56d5
...
...
@@ -43,6 +43,8 @@ func (pc *PromClientMap) loadFromDatabase() {
var
err
error
if
!
pc
.
ctx
.
IsCenter
{
datasources
,
err
=
poster
.
GetByUrls
[[]
*
models
.
Datasource
](
pc
.
ctx
,
"/v1/n9e/datasources?typ="
+
models
.
PROMETHEUS
)
lokiDatasource
,
err
:=
poster
.
GetByUrls
[[]
*
models
.
Datasource
](
pc
.
ctx
,
"/v1/n9e/datasources?typ="
+
models
.
LOKI
)
datasources
=
append
(
datasources
,
lokiDatasource
...
)
if
err
!=
nil
{
logger
.
Errorf
(
"failed to get datasources, error: %v"
,
err
)
return
...
...
@@ -52,6 +54,8 @@ func (pc *PromClientMap) loadFromDatabase() {
}
}
else
{
datasources
,
err
=
models
.
GetDatasourcesGetsBy
(
pc
.
ctx
,
models
.
PROMETHEUS
,
""
,
""
,
""
)
lokiDatasource
,
err
:=
models
.
GetDatasourcesGetsBy
(
pc
.
ctx
,
models
.
LOKI
,
""
,
""
,
""
)
datasources
=
append
(
datasources
,
lokiDatasource
...
)
if
err
!=
nil
{
logger
.
Errorf
(
"failed to get datasources, error: %v"
,
err
)
return
...
...
pushgw/router/router_opentsdb_easyjson.go
浏览文件 @
616d56d5
...
...
@@ -211,4 +211,4 @@ func (v *HTTPMetric) UnmarshalJSON(data []byte) error {
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func
(
v
*
HTTPMetric
)
UnmarshalEasyJSON
(
l
*
jlexer
.
Lexer
)
{
easyjson30864de9DecodeGithubComDidiNightingaleV5SrcServerRouter1
(
l
,
v
)
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录