grafana/pkg/services/ngalert/state
Joe Blubaugh b476ae62fb
Alerting: Write and Delete multiple alert instances. (#55350)
Prior to this change, all alert instance writes and deletes happened
individually, in their own database transaction. This change batches up
writes or deletes for a given rule's evaluation loop into a single
transaction before applying it.

These new transactions are off by default, guarded by the feature toggle "alertingBigTransactions"

Before:

```
goos: darwin
goarch: arm64
pkg: github.com/grafana/grafana/pkg/services/ngalert/store
BenchmarkAlertInstanceOperations-8           398           2991381 ns/op         1133537 B/op      27703 allocs/op
--- BENCH: BenchmarkAlertInstanceOperations-8
    util.go:127: alert definition: {orgID: 1, UID: FovKXiRVzm} with title: "an alert definition FTvFXmRVkz" interval: 60 created
    util.go:127: alert definition: {orgID: 1, UID: foDFXmRVkm} with title: "an alert definition fovFXmRVkz" interval: 60 created
    util.go:127: alert definition: {orgID: 1, UID: VQvFuigVkm} with title: "an alert definition VwDKXmR4kz" interval: 60 created
PASS
ok      github.com/grafana/grafana/pkg/services/ngalert/store   1.619s
```

After:

```
goos: darwin
goarch: arm64
pkg: github.com/grafana/grafana/pkg/services/ngalert/store
BenchmarkAlertInstanceOperations-8          1440            816484 ns/op          352297 B/op       6529 allocs/op
--- BENCH: BenchmarkAlertInstanceOperations-8
    util.go:127: alert definition: {orgID: 1, UID: 302r_igVzm} with title: "an alert definition q0h9lmR4zz" interval: 60 created
    util.go:127: alert definition: {orgID: 1, UID: 71hrlmR4km} with title: "an alert definition nJ29_mR4zz" interval: 60 created
    util.go:127: alert definition: {orgID: 1, UID: Cahr_mR4zm} with title: "an alert definition ja2rlmg4zz" interval: 60 created
PASS
ok      github.com/grafana/grafana/pkg/services/ngalert/store   1.383s
```

So we cut time by about 75% and memory allocations by about 60% when
storing and deleting 100 instances.
2022-10-06 14:22:58 +08:00
..
historian Alerting: Move annotation functionality behind a history persistence interface (#56133) 2022-10-05 15:32:20 -05:00
cache_test.go Alerting: Update state manager to accept reserved labels (#52189) 2022-07-14 15:59:59 -04:00
cache.go Alerting: Delete state from the database on reset (#53919) 2022-08-25 14:12:22 -04:00
manager_private_test.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
manager_test.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
manager.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
persist.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
state_test.go Alerting: Fix send resolved notifications (#54793) 2022-09-15 17:25:05 +01:00
state.go Alerting: Fix send resolved notifications (#54793) 2022-09-15 17:25:05 +01:00
template_test.go Chore: Remove context.TODO (#43458) 2021-12-28 10:26:18 +01:00
template.go Chore: Remove context.TODO (#43458) 2021-12-28 10:26:18 +01:00
testing.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00