|
@@ -16,17 +16,18 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
type EventHandler struct {
|
|
type EventHandler struct {
|
|
- RP *omodels.OtRulesPolicy `json:"result_policy"`
|
|
|
|
- AC *omodels.AlertCondition `json:"alert_condition"`
|
|
|
|
- JR *omodels.JudgeResult `json:"judge_result"`
|
|
|
|
- Emo *omodels.Events
|
|
|
|
- promMap *sync.Map
|
|
|
|
- Errs map[string]error `json:"_"`
|
|
|
|
|
|
+ RP *omodels.OtRulesPolicy `json:"result_policy"`
|
|
|
|
+ AC *omodels.AlertCondition `json:"alert_condition"`
|
|
|
|
+ JR *omodels.JudgeResult `json:"judge_result"`
|
|
|
|
+ Emo *omodels.Events
|
|
|
|
+ promMap *sync.Map
|
|
|
|
+ CheckStartTime time.Time `json:"check_starttime"`
|
|
|
|
+ Errs map[string]error `json:"_"`
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
- row: 单个数值,出现不代表异常,需要与point比较,复合则立即写入异常事件,单不一定告警,需要结合频率、周期进行判断
|
|
|
|
- rows: list值,出现代表有异常,立即写入异常事件监控,但不一定告警,需要结合频率,周期进行判断
|
|
|
|
|
|
+ row: 单个数值,出现不代表异常,需要与point比较,符合则立即写入异常事件,单不一定告警,需要结合频率、周期进行判断
|
|
|
|
+ --{取消该条检测} rows: list值,出现代表有异常,立即写入异常事件监控,但不一定告警,需要结合频率,周期进行判断
|
|
*/
|
|
*/
|
|
|
|
|
|
func InitEventHandler(pMap *sync.Map) *EventHandler {
|
|
func InitEventHandler(pMap *sync.Map) *EventHandler {
|
|
@@ -38,6 +39,7 @@ func InitEventHandler(pMap *sync.Map) *EventHandler {
|
|
//eg:@@UNSET_apdex::health:5m_{"condition":"<","point":0.7,"point_type":"float","tigger_hz":3,"interval":5}
|
|
//eg:@@UNSET_apdex::health:5m_{"condition":"<","point":0.7,"point_type":"float","tigger_hz":3,"interval":5}
|
|
e.Errs = make(map[string]error)
|
|
e.Errs = make(map[string]error)
|
|
e.promMap = pMap
|
|
e.promMap = pMap
|
|
|
|
+ e.CheckStartTime = time.Now()
|
|
return e
|
|
return e
|
|
}
|
|
}
|
|
|
|
|
|
@@ -57,8 +59,9 @@ func (e *EventHandler) JudgeRow() *EventHandler {
|
|
case "row":
|
|
case "row":
|
|
e.JR.CompareV = e.JR.RowResult
|
|
e.JR.CompareV = e.JR.RowResult
|
|
default:
|
|
default:
|
|
- e.JR.CompareV = e.JR.RowResult
|
|
|
|
|
|
+ e.JR.CompareV = e.JR.RowGaugeResult
|
|
}
|
|
}
|
|
|
|
+ logger.Debug("compareV is: ", e.JR.CompareV)
|
|
return e
|
|
return e
|
|
}
|
|
}
|
|
|
|
|
|
@@ -114,7 +117,8 @@ func (e *EventHandler) JudgeInterval(chdb *gorm.DB) *EventHandler {
|
|
return e
|
|
return e
|
|
}
|
|
}
|
|
switch e.RP.RuleValueType {
|
|
switch e.RP.RuleValueType {
|
|
- case "row":
|
|
|
|
|
|
+ // case "row":
|
|
|
|
+ default:
|
|
if !e.JR.IsException {
|
|
if !e.JR.IsException {
|
|
return e
|
|
return e
|
|
}
|
|
}
|
|
@@ -127,11 +131,18 @@ func (e *EventHandler) JudgeInterval(chdb *gorm.DB) *EventHandler {
|
|
err = chdb.Table(emo.TableName()).
|
|
err = chdb.Table(emo.TableName()).
|
|
Raw(`SELECT COUNT(*)
|
|
Raw(`SELECT COUNT(*)
|
|
FROM otel_events
|
|
FROM otel_events
|
|
- WHERE AlertStatus = ? AND UID = ?`, FIRING, e.JR.UID).
|
|
|
|
|
|
+ WHERE AlertStatus = ? AND UID = ? AND Timestamp >= ?`, FIRING, e.JR.UID, ft).
|
|
Row().Scan(&count)
|
|
Row().Scan(&count)
|
|
- if count == 0 {
|
|
|
|
- ft = timer
|
|
|
|
- } else {
|
|
|
|
|
|
+ if err != nil {
|
|
|
|
+ logger.Error("select fire count err: ", err)
|
|
|
|
+ e.Errs["select fire count err"] = err
|
|
|
|
+ return e
|
|
|
|
+ }
|
|
|
|
+ // if count == 0 {
|
|
|
|
+ // // ft = timer
|
|
|
|
+ // timer = ft
|
|
|
|
+ // } else
|
|
|
|
+ if count != 0 {
|
|
err = chdb.Table(emo.TableName()).
|
|
err = chdb.Table(emo.TableName()).
|
|
Raw(`SELECT AppendTime
|
|
Raw(`SELECT AppendTime
|
|
FROM otel_events
|
|
FROM otel_events
|
|
@@ -144,11 +155,11 @@ func (e *EventHandler) JudgeInterval(chdb *gorm.DB) *EventHandler {
|
|
e.Errs["alert status 4 row"] = err
|
|
e.Errs["alert status 4 row"] = err
|
|
return e
|
|
return e
|
|
}
|
|
}
|
|
|
|
+ if timer.After(ft) || timer.Equal(ft) {
|
|
|
|
+ ft = timer
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if timer.After(ft) || timer.Equal(ft) {
|
|
|
|
- ft = timer
|
|
|
|
- }
|
|
|
|
rows, err := chdb.Table(emo.TableName()).
|
|
rows, err := chdb.Table(emo.TableName()).
|
|
Raw(`SELECT *
|
|
Raw(`SELECT *
|
|
FROM otel_events
|
|
FROM otel_events
|
|
@@ -218,7 +229,7 @@ func (e *EventHandler) SetPromKV() *EventHandler {
|
|
e.GetRegisteredGauge(e.RP.RuleMonitorAlias).WithLabelValues(
|
|
e.GetRegisteredGauge(e.RP.RuleMonitorAlias).WithLabelValues(
|
|
e.RP.AppAlias, e.RP.RuleKind, e.JR.UID,
|
|
e.RP.AppAlias, e.RP.RuleKind, e.JR.UID,
|
|
).Set(float64(e.JR.RowGaugeResult))
|
|
).Set(float64(e.JR.RowGaugeResult))
|
|
- logger.Debug("e.JR.RowGaugeResult", e.JR.RowGaugeResult)
|
|
|
|
|
|
+ logger.Debug("e.JR.RowGaugeResult: ", e.JR.RowGaugeResult)
|
|
return e
|
|
return e
|
|
}
|
|
}
|
|
|
|
|
|
@@ -252,9 +263,10 @@ func (e *EventHandler) CreateEventRecord(chdb *gorm.DB) *EventHandler {
|
|
if e.JR.IsException {
|
|
if e.JR.IsException {
|
|
row := "UNSET"
|
|
row := "UNSET"
|
|
rows := make([]map[string]string, 0)
|
|
rows := make([]map[string]string, 0)
|
|
- if e.RP.RuleValueType == "row" {
|
|
|
|
|
|
+ switch e.RP.RuleValueType {
|
|
|
|
+ case "row":
|
|
row = fmt.Sprintf("%v", e.JR.RowResult)
|
|
row = fmt.Sprintf("%v", e.JR.RowResult)
|
|
- } else {
|
|
|
|
|
|
+ case "rows":
|
|
for _, d := range e.JR.RowsResult {
|
|
for _, d := range e.JR.RowsResult {
|
|
tmp := make(map[string]string)
|
|
tmp := make(map[string]string)
|
|
for k, v := range d {
|
|
for k, v := range d {
|
|
@@ -262,6 +274,8 @@ func (e *EventHandler) CreateEventRecord(chdb *gorm.DB) *EventHandler {
|
|
}
|
|
}
|
|
rows = append(rows, tmp)
|
|
rows = append(rows, tmp)
|
|
}
|
|
}
|
|
|
|
+ default:
|
|
|
|
+ row = fmt.Sprintf("%v", e.JR.RowGaugeResult)
|
|
}
|
|
}
|
|
var exceptionName string
|
|
var exceptionName string
|
|
if e.RP.RuleValueType == "rows" {
|
|
if e.RP.RuleValueType == "rows" {
|