Alerting: Add compressed protobuf-based alert state storage (#99193)

This commit is contained in:
Alexander Akhmetov
2025-01-27 18:47:33 +01:00
committed by GitHub
parent 6edd4f5a7c
commit cb43f4b696
24 changed files with 1437 additions and 134 deletions
@@ -143,4 +143,6 @@ func (oss *OSSMigrations) AddMigration(mg *Migrator) {
accesscontrol.AddReceiverCreateScopeMigration(mg)
ualert.AddAlertRuleUpdatedByMigration(mg)
ualert.AddAlertRuleStateTable(mg)
}
@@ -0,0 +1,29 @@
package ualert
import "github.com/grafana/grafana/pkg/services/sqlstore/migrator"
// AddAlertRuleStateTable adds column to store alert rule state data.
func AddAlertRuleStateTable(mg *migrator.Migrator) {
alertStateTable := migrator.Table{
Name: "alert_rule_state",
Columns: []*migrator.Column{
{Name: "id", Type: migrator.DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
{Name: "org_id", Type: migrator.DB_BigInt, Nullable: false},
{Name: "rule_uid", Type: migrator.DB_NVarchar, Length: UIDMaxLength, Nullable: false},
{Name: "data", Type: migrator.DB_LongBlob, Nullable: false},
{Name: "updated_at", Type: migrator.DB_DateTime, Nullable: false},
},
Indices: []*migrator.Index{
{Cols: []string{"org_id", "rule_uid"}, Type: migrator.UniqueIndex},
},
}
mg.AddMigration(
"add alert_rule_state table",
migrator.NewAddTableMigration(alertStateTable),
)
mg.AddMigration(
"add index to alert_rule_state on org_id and rule_uid columns",
migrator.NewAddIndexMigration(alertStateTable, alertStateTable.Indices[0]),
)
}