mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Add database migration for recording rule fields (#87012)
* Create recording rule fields in model * Add migration * Write to database, support in version table * extend fingerprint * Force fields to be empty on validate * Another storage spot, tests for fingerprint * Explicitly set defaults in provisioning API * Tests for main API validation * Add diff tests even though fields are unpopulated for now * Use struct tag approach instead of FromDB/ToDB hooks as it better handles nulls when deserializing * test for deser * Backout RecordTo for now since it's not decided in the doc * back out of migration too * Drop datasourceref for now * address linter complaints * Try a single outer struct with all fields embedded
This commit is contained in:
@@ -311,5 +311,10 @@ func (r ruleWithFolder) Fingerprint() fingerprint {
|
||||
writeInt(int64(rule.RuleGroupIndex))
|
||||
writeString(string(rule.NoDataState))
|
||||
writeString(string(rule.ExecErrState))
|
||||
if rule.Record != nil {
|
||||
binary.LittleEndian.PutUint64(tmp, uint64(rule.Record.Fingerprint()))
|
||||
writeBytes(tmp)
|
||||
}
|
||||
|
||||
return fingerprint(sum.Sum64())
|
||||
}
|
||||
|
||||
@@ -192,6 +192,7 @@ func TestRuleWithFolderFingerprint(t *testing.T) {
|
||||
RuleGroupIndex: 1,
|
||||
NoDataState: "test-nodata",
|
||||
ExecErrState: "test-err",
|
||||
Record: &models.Record{Metric: "my_metric", From: "A"},
|
||||
For: 12,
|
||||
Annotations: map[string]string{
|
||||
"key-annotation": "value-annotation",
|
||||
@@ -230,6 +231,7 @@ func TestRuleWithFolderFingerprint(t *testing.T) {
|
||||
RuleGroupIndex: 22,
|
||||
NoDataState: "test-nodata2",
|
||||
ExecErrState: "test-err2",
|
||||
Record: &models.Record{Metric: "my_metric2", From: "B"},
|
||||
For: 1141,
|
||||
Annotations: map[string]string{
|
||||
"key-annotation2": "value-annotation",
|
||||
|
||||
Reference in New Issue
Block a user