grafana/pkg/services
Joe Blubaugh 5e4fd94413
Alerting: Write and Delete multiple alert instances. (#54072)
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.

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.

This change also updates some of our tests so that they run successfully against postgreSQL - we were using random Int64s, but postgres integers, which our tables use, max out at 2^31-1
2022-09-02 11:17:20 +08:00
..
accesscontrol RBAC: Add function to generate wildcards from prefix (#54275) 2022-08-26 17:10:35 +02:00
alerting RBAC: Enable rbac when creating new settings (#53531) 2022-08-11 15:37:31 +02:00
annotations Move SignedInUser to user service and RoleType and Roles to org (#53445) 2022-08-10 11:56:48 +02:00
apikey Chore: move from xorm to sqlx apikey store (#53434) 2022-08-23 11:01:35 -04:00
auth Handle ioutil deprecations (#53526) 2022-08-10 15:37:51 +02:00
cleanup Chore: Move login attempt methods to separate service (#54479) 2022-09-01 18:08:42 +02:00
comments Chore: Remove disable user, disable batch users and searchusers methods from store interface (#53717) 2022-08-16 14:24:57 +02:00
contexthandler ContextHandler: Use stdlib format for middleware (#54219) 2022-08-25 14:35:21 +02:00
correlations Correlations: Use correct fallback handlers (#54511) 2022-09-01 12:29:44 +02:00
dashboard_thumbs Chore: Add dashboard thumbnails service (#54500) 2022-08-31 16:45:41 -04:00
dashboardimport Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
dashboards public-dashboards: Add log statement when public dashboard enabled or disabled (#54133) 2022-08-26 11:28:54 -08:00
dashboardsnapshots Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
dashboardversion Chore: replace xorm by sqlx in dashboardversion service (#53869) 2022-08-25 16:04:16 -05:00
datasourceproxy backend/datasources: move datasources models into the datasources service package (#51267) 2022-06-27 12:23:15 -04:00
datasources Chore: SQL Store Split of datasource (#54262) 2022-08-26 11:03:38 -04:00
encryption Encryption: Fall back to AES-CFB on empty algorithm metadata (#53266) 2022-08-04 09:37:53 +02:00
export Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
featuremgmt Explore: Add Mixed Datasource (#53429) 2022-08-31 09:24:20 -05:00
guardian RBAC: Split up service into several components (#54002) 2022-08-24 13:29:17 +02:00
hooks Migrate to Wire for dependency injection (#32289) 2021-08-25 15:11:22 +02:00
kmsproviders Encryption: Refactor secrets.Service initialization (#51091) 2022-07-07 09:48:25 +02:00
ldap Handle ioutil deprecations (#53526) 2022-08-10 15:37:51 +02:00
libraryelements RBAC: Enable rbac when creating new settings (#53531) 2022-08-11 15:37:31 +02:00
librarypanels RBAC: Enable rbac when creating new settings (#53531) 2022-08-11 15:37:31 +02:00
licensing RBAC: Make RBAC action names more consistent (#49730) 2022-06-02 13:14:48 +01:00
live Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
login RBAC: Split up service into several components (#54002) 2022-08-24 13:29:17 +02:00
loginattempt Chore: Move login attempt methods to separate service (#54479) 2022-09-01 18:08:42 +02:00
multildap Split Create User (#50502) 2022-06-28 14:32:25 +02:00
ngalert Alerting: Write and Delete multiple alert instances. (#54072) 2022-09-02 11:17:20 +08:00
notifications User management: Use HMAC-SHA256 to generate time limit codes (password reset tokens) (#42334) 2022-08-18 16:01:09 +02:00
oauthtoken Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
org Chore: Move updateorg out of sqlstore (#54111) 2022-08-23 12:26:21 -05:00
playlist Chore: Replace xorm with sqlx (#52575) 2022-08-16 13:17:14 -05:00
plugindashboards Plugins: Split plugin manager into smaller components (#54384) 2022-08-30 17:30:43 +02:00
pluginsettings Chore: Move plugin settings store code into a dedicated service (#53560) 2022-08-11 09:50:53 +02:00
preference Chore: remove xorm from preference (#53803) 2022-08-17 22:07:20 -04:00
provisioning Alerting: use raw query data in provisioning to bypass interpolation of macros (#54293) 2022-08-26 23:54:30 +02:00
publicdashboards Public Dashboards: Add Expressions Support (#54336) 2022-08-31 09:11:10 -06:00
query Public Dashboards: Add Expressions Support (#54336) 2022-08-31 09:11:10 -06:00
queryhistory Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
quota Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
rendering Rendering: Add support for renderer token (#54425) 2022-08-30 12:09:38 +02:00
screenshot Move SignedInUser to user service and RoleType and Roles to org (#53445) 2022-08-10 11:56:48 +02:00
search Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
searchusers Chore: Remove disable user, disable batch users and searchusers methods from store interface (#53717) 2022-08-16 14:24:57 +02:00
searchV2 Search: ordering tests (#54432) 2022-08-30 18:58:19 +02:00
secrets improve log in plugin check (#54599) 2022-09-01 13:47:37 -04:00
serviceaccounts RBAC: Remove DeclareFixedRoles wrapper on Access control and inject service (#54153) 2022-08-26 09:59:34 +02:00
shorturls Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
sqlstore Alerting: Write and Delete multiple alert instances. (#54072) 2022-09-02 11:17:20 +08:00
star add sqlx_store into star service (#53430) 2022-08-17 11:17:23 -05:00
store Storage: add WithContents option to storage.Get() (#53105) 2022-08-30 15:23:16 +02:00
teamguardian Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
temp_user Chore: Add tempuser service (#53325) 2022-08-12 12:13:23 -04:00
thumbs Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343) 2022-08-11 13:28:55 +02:00
updatechecker Handle ioutil deprecations (#53526) 2022-08-10 15:37:51 +02:00
user RBAC: Split up service into several components (#54002) 2022-08-24 13:29:17 +02:00
userauth Chore: Split delete user method (#52216) 2022-07-19 16:01:05 +02:00
validations Migrate to Wire for dependency injection (#32289) 2021-08-25 15:11:22 +02:00