grafana/pkg/services/ngalert/models
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
..
admin_configuration_test.go Alerting: send alerts to external, internal, or both alertmanagers (#40341) 2022-02-01 20:36:55 -03:00
admin_configuration.go Alerting: send alerts to external, internal, or both alertmanagers (#40341) 2022-02-01 20:36:55 -03:00
alert_query_test.go Alerting: Display query from grafana-managed alert rules on /api/v1/rules (#45969) 2022-03-14 10:39:20 +00:00
alert_query.go Alerting: add YAML support for relative time range (#51694) 2022-07-04 06:03:34 -04:00
alert_rule_test.go Alerting: add YAML support for relative time range (#51694) 2022-07-04 06:03:34 -04:00
alert_rule.go Alerting: Move stray model structs in store package to model package (#55968) 2022-09-29 15:47:56 -05:00
alertmanager.go Alerting: add collision safe update function for alertmanager configurations (#46692) 2022-03-23 09:31:46 +01:00
image_test.go Alerting: Delete expired images from the database (#53236) 2022-08-09 15:28:36 +01:00
image.go Alerting: Delete expired images from the database (#53236) 2022-08-09 15:28:36 +01:00
instance_labels.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
instance.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00
provisioning.go Drop ProvenanceOrgAdapter and build into store API instead (#48137) 2022-04-26 10:30:57 -05:00
testing.go Alerting: Write and Delete multiple alert instances. (#55350) 2022-10-06 14:22:58 +08:00