mirror of
https://github.com/grafana/grafana.git
synced 2025-09-25 21:34:01 +08:00

* 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.
24 lines
418 B
Go
24 lines
418 B
Go
package ualert
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
|
)
|
|
|
|
// newTestMigration generates an empty migration to use in tests.
|
|
func newTestMigration(t *testing.T) *migration {
|
|
t.Helper()
|
|
|
|
return &migration{
|
|
mg: &migrator.Migrator{
|
|
|
|
Logger: log.New("test"),
|
|
},
|
|
seenUIDs: uidSet{
|
|
set: make(map[string]struct{}),
|
|
},
|
|
}
|
|
}
|