未验证 提交 3c7c836b 编写于 作者: D DemoLiang 提交者: GitHub

[FIX][issue#433]优化告警收敛,查询告警事件统计数据数据时使用created做between查询数据库时耗时非常久的问题,修改问使用etime...

[FIX][issue#433]优化告警收敛,查询告警事件统计数据数据时使用created做between查询数据库时耗时非常久的问题,修改问使用etime 可以命中etime索引,提升查询性能,4C8G查询100W告警事件大概9s耗时,修改为etime大概700ms耗时 (#435)
上级 7068faaa
......@@ -200,8 +200,8 @@ func EventAlertUpgradeUnMarshal(str string) (EventAlertUpgrade, error) {
return obj, err
}
func EventCnt(hashid uint64, stime, etime string, isUpgrade bool) (int64, error) {
session := DB["mon"].Where("hashid = ? and event_type = ? and created between ? and ?", hashid, config.ALERT, stime, etime)
func EventCnt(hashid uint64, stime, etime int64, isUpgrade bool) (int64, error) {
session := DB["mon"].Where("hashid = ? and event_type = ? and etime between ? and ?", hashid, config.ALERT, stime, etime)
if isUpgrade {
return session.In("status", GetFlagsByStatus([]string{STATUS_UPGRADE, STATUS_SEND})).Count(new(Event))
......
......@@ -173,7 +173,7 @@ func isInConverge(event *models.Event) bool {
startTs = recoveryTs
}
cnt, err := models.EventCnt(event.HashId, models.ParseEtime(startTs), models.ParseEtime(now), event.RealUpgrade)
cnt, err := models.EventCnt(event.HashId, startTs, now, event.RealUpgrade)
if err != nil {
logger.Errorf("get event count failed, err: %v", err)
return false
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册