grafana/pkg/services/ngalert/schedule
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
..
alerts_sender_mock.go Chore: Upgrade Go to 1.19.1 (#54902) 2022-09-12 12:03:49 +02:00
compat_test.go Alerting: Resolve stale state + add state reason to notifications (#49352) 2022-09-21 13:24:47 -04:00
compat.go Alerting: Resolve stale state + add state reason to notifications (#49352) 2022-09-21 13:24:47 -04:00
fetcher_test.go Alerting: Scheduler to use AlertRule (#52354) 2022-07-26 09:40:06 -04:00
fetcher.go Alerting: Scheduler to fetch folders along with rules (#52842) 2022-08-31 11:08:19 -04:00
registry_test.go Alerting: Scheduler to fetch folders along with rules (#52842) 2022-08-31 11:08:19 -04:00
registry.go Docs: Deprecating packages_api and removing it from our pipelines (#54473) 2022-09-01 18:15:44 +02:00
schedule_mock.go Alerting: Update rules delete endpoint to handle rules in group (#53790) 2022-08-24 15:33:33 -04:00
schedule_test.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
schedule_unit_test.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
schedule.go Alerting: Start ticker only when scheduler starts (#56339) 2022-10-05 09:35:02 -04:00
testing.go Alerting: Decouple schedule package from store (#55858) 2022-09-27 13:48:12 -05:00