mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(annotations): added support to show grafana stored annotations in graphs, #5982
This commit is contained in:
@@ -38,6 +38,9 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I
|
||||
params = append(params, query.AlertId)
|
||||
}
|
||||
|
||||
sql.WriteString(` AND epoch BETWEEN ? AND ?`)
|
||||
params = append(params, query.From, query.To)
|
||||
|
||||
if query.Type != "" {
|
||||
sql.WriteString(` AND type = ?`)
|
||||
params = append(params, string(query.Type))
|
||||
@@ -47,7 +50,7 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I
|
||||
query.Limit = 10
|
||||
}
|
||||
|
||||
sql.WriteString(fmt.Sprintf("ORDER BY timestamp DESC LIMIT %v", query.Limit))
|
||||
sql.WriteString(fmt.Sprintf("ORDER BY epoch DESC LIMIT %v", query.Limit))
|
||||
|
||||
items := make([]*annotations.Item, 0)
|
||||
if err := x.Sql(sql.String(), params...).Find(&items); err != nil {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func addAnnotationMig(mg *Migrator) {
|
||||
|
||||
table := Table{
|
||||
Name: "annotation",
|
||||
Columns: []*Column{
|
||||
@@ -19,20 +20,22 @@ func addAnnotationMig(mg *Migrator) {
|
||||
{Name: "prev_state", Type: DB_NVarchar, Length: 25, Nullable: false},
|
||||
{Name: "new_state", Type: DB_NVarchar, Length: 25, Nullable: false},
|
||||
{Name: "data", Type: DB_Text, Nullable: false},
|
||||
{Name: "timestamp", Type: DB_DateTime, Nullable: false},
|
||||
{Name: "epoch", Type: DB_BigInt, Nullable: false},
|
||||
},
|
||||
Indices: []*Index{
|
||||
{Cols: []string{"org_id", "alert_id"}, Type: IndexType},
|
||||
{Cols: []string{"org_id", "type"}, Type: IndexType},
|
||||
{Cols: []string{"timestamp"}, Type: IndexType},
|
||||
{Cols: []string{"epoch"}, Type: IndexType},
|
||||
},
|
||||
}
|
||||
|
||||
mg.AddMigration("create annotation table v1", NewAddTableMigration(table))
|
||||
mg.AddMigration("Drop old annotation table v2", NewDropTableMigration("annotation"))
|
||||
|
||||
mg.AddMigration("create annotation table v3", NewAddTableMigration(table))
|
||||
|
||||
// create indices
|
||||
mg.AddMigration("add index annotation org_id & alert_id ", NewAddIndexMigration(table, table.Indices[0]))
|
||||
mg.AddMigration("add index annotation org_id & alert_id v2", NewAddIndexMigration(table, table.Indices[0]))
|
||||
|
||||
mg.AddMigration("add index annotation org_id & type", NewAddIndexMigration(table, table.Indices[1]))
|
||||
mg.AddMigration("add index annotation timestamp", NewAddIndexMigration(table, table.Indices[2]))
|
||||
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]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user