feat(alerting): show panel specific alert annotations, #5694

This commit is contained in:
Torkel Ödegaard
2016-09-09 11:30:55 +02:00
parent 0ac4ece00d
commit 4a2f2fba73
15 changed files with 156 additions and 114 deletions

View File

@@ -38,6 +38,21 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I
params = append(params, query.AlertId)
}
if query.AlertId != 0 {
sql.WriteString(` AND alert_id = ?`)
params = append(params, query.AlertId)
}
if query.DashboardId != 0 {
sql.WriteString(` AND dashboard_id = ?`)
params = append(params, query.DashboardId)
}
if query.PanelId != 0 {
sql.WriteString(` AND panel_id = ?`)
params = append(params, query.PanelId)
}
sql.WriteString(` AND epoch BETWEEN ? AND ?`)
params = append(params, query.From, query.To)

View File

@@ -13,6 +13,8 @@ func addAnnotationMig(mg *Migrator) {
{Name: "org_id", Type: DB_BigInt, Nullable: false},
{Name: "alert_id", Type: DB_BigInt, Nullable: true},
{Name: "user_id", Type: DB_BigInt, Nullable: true},
{Name: "dashboard_id", Type: DB_BigInt, Nullable: true},
{Name: "panel_id", Type: DB_BigInt, Nullable: true},
{Name: "type", Type: DB_NVarchar, Length: 25, Nullable: false},
{Name: "title", Type: DB_Text, Nullable: false},
{Name: "text", Type: DB_Text, Nullable: false},
@@ -25,17 +27,18 @@ func addAnnotationMig(mg *Migrator) {
Indices: []*Index{
{Cols: []string{"org_id", "alert_id"}, Type: IndexType},
{Cols: []string{"org_id", "type"}, Type: IndexType},
{Cols: []string{"dashboard_id", "panel_id"}, Type: IndexType},
{Cols: []string{"epoch"}, Type: IndexType},
},
}
mg.AddMigration("Drop old annotation table v2", NewDropTableMigration("annotation"))
mg.AddMigration("Drop old annotation table v3", NewDropTableMigration("annotation"))
mg.AddMigration("create annotation table v3", NewAddTableMigration(table))
mg.AddMigration("create annotation table v4", NewAddTableMigration(table))
// create indices
mg.AddMigration("add index annotation org_id & alert_id v2", NewAddIndexMigration(table, table.Indices[0]))
mg.AddMigration("add index annotation org_id & type v2", NewAddIndexMigration(table, table.Indices[1]))
mg.AddMigration("add index annotation epoch", NewAddIndexMigration(table, table.Indices[2]))
mg.AddMigration("add index annotation org_id & alert_id v3", NewAddIndexMigration(table, table.Indices[0]))
mg.AddMigration("add index annotation org_id & type v3", NewAddIndexMigration(table, table.Indices[1]))
mg.AddMigration("add index annotation dashboard_id panel_id", NewAddIndexMigration(table, table.Indices[2]))
mg.AddMigration("add index annotation epoch v3", NewAddIndexMigration(table, table.Indices[3]))
}