Unistore: Reuse MySQL and Postgres Grafana core config instead of the object (#94223)

* Reuse MySQL and Postgres Grafana config instead of the object

- Only reuse the Grafana DB object for SQLite. Support for SQLite will be added in a different PR
- Fail when reusing the Grafana DB object if it is using DB instrumentation
- In the case that we have to reuse a Grafana DB with its instrumentation, fail with an error that describes a workaround
- Add regression tests to reproduce incident 2144

* remove temp file

* fix linter

* fix linter x2

* fix linter x3
This commit is contained in:
Diego Augusto Molina
2024-10-04 09:07:20 -03:00
committed by GitHub
parent a82f102878
commit 7d32d5eff4
9 changed files with 562 additions and 81 deletions
+55 -15
View File
@@ -17,35 +17,75 @@ func setSectionKeyValues(section *setting.DynamicSection, m map[string]string) {
}
}
func newTestSectionGetter(m map[string]string) *sectionGetter {
func newTestConfGetter(m map[string]string, keyPrefix string) confGetter {
section := setting.NewCfg().SectionWithEnvOverrides("entity_api")
setSectionKeyValues(section, m)
return &sectionGetter{
DynamicSection: section,
}
return newConfGetter(section, keyPrefix)
}
func TestSectionGetter(t *testing.T) {
t.Parallel()
var (
key = "the key"
val = string(invalidUTF8ByteSequence)
key = "the key"
keyBoolTrue = "I'm true"
keyBoolFalse = "not me!"
prefix = "this is some prefix"
val = string(invalidUTF8ByteSequence)
)
g := newTestSectionGetter(map[string]string{
key: val,
t.Run("with prefix", func(t *testing.T) {
t.Parallel()
g := newTestConfGetter(map[string]string{
prefix + key: val,
prefix + keyBoolTrue: "YES",
prefix + keyBoolFalse: "0",
}, prefix)
require.False(t, g.Bool("whatever bool"))
require.NoError(t, g.Err())
require.False(t, g.Bool(keyBoolFalse))
require.NoError(t, g.Err())
require.True(t, g.Bool(keyBoolTrue))
require.NoError(t, g.Err())
require.Empty(t, g.String("whatever string"))
require.NoError(t, g.Err())
require.Empty(t, g.String(key))
require.Error(t, g.Err())
require.ErrorIs(t, g.Err(), errInvalidUTF8Sequence)
})
v := g.String("whatever")
require.Empty(t, v)
require.NoError(t, g.Err())
t.Run("without prefix", func(t *testing.T) {
t.Parallel()
v = g.String(key)
require.Empty(t, v)
require.Error(t, g.Err())
require.ErrorIs(t, g.Err(), errInvalidUTF8Sequence)
g := newTestConfGetter(map[string]string{
key: val,
keyBoolTrue: "true",
keyBoolFalse: "f",
}, "")
require.False(t, g.Bool("whatever bool"))
require.NoError(t, g.Err())
require.False(t, g.Bool(keyBoolFalse))
require.NoError(t, g.Err())
require.True(t, g.Bool(keyBoolTrue))
require.NoError(t, g.Err())
require.Empty(t, g.String("whatever string"))
require.NoError(t, g.Err())
require.Empty(t, g.String(key))
require.Error(t, g.Err())
require.ErrorIs(t, g.Err(), errInvalidUTF8Sequence)
})
}
func TestMakeDSN(t *testing.T) {