[v9.2.x] Alerting: Prevent uid collision in migration when db is case-insensitive (#60834)

Alerting: Prevent uid collision in migration when db is case-insensitive (#60494)

* Alerting: Prevent short uid collision in legacy migration when db is case-insensitive

Two factors come into play that cause sporadic uid conflicts during legacy alert migration:
- MySQL and MySQL-compatible backends use case-insensitive collation.
- Our short uid generator is not a uniform RNG and generates uids in such a way that generations in quick succession have a higher probability of creating similar uids.

Normally we would be guaranteed unique short uid generation, however if the source alphabet contains
duplicate characters (for example, if we use case-insensitive comparison) this guarantee is void.

Generating even ~1000 uids in quick succession is nearly guaranteed to create a case-insensitive
duplicate.

(cherry picked from commit 570b62091c)

Co-authored-by: Matthew Jacobson <matthew.jacobson@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-12-29 16:15:42 -05:00
committed by GitHub
co-authored by Matthew Jacobson
parent 3863c0d4ba
commit 596ba76332
5 changed files with 107 additions and 40 deletions
@@ -16,6 +16,8 @@ func newTestMigration(t *testing.T) *migration {
Logger: log.New("test"),
},
seenChannelUIDs: make(map[string]struct{}),
seenUIDs: uidSet{
set: make(map[string]struct{}),
},
}
}