Alerting: Disable unified alerting by default in Enterprise Grafana (#42476)

* fallback to enable false if Enterprise is true

* anyBoolean
This commit is contained in:
Yuriy Tseretyan 2021-11-29 14:51:15 -05:00 committed by GitHub
parent 1f8336e5fe
commit 005c8f8894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package setting
import (
"bufio"
"math/rand"
"net/url"
"os"
"path"
@ -428,17 +429,23 @@ func TestGetCDNPathWithAlphaVersion(t *testing.T) {
}
func TestAlertingEnabled(t *testing.T) {
anyBoolean := func() bool {
return rand.Int63()%2 == 0
}
testCases := []struct {
desc string
unifiedAlertingEnabled string
legacyAlertingEnabled string
featureToggleSet bool
isEnterprise bool
verifyCfg func(*testing.T, Cfg, *ini.File)
}{
{
desc: "when legacy alerting is enabled and unified is disabled",
legacyAlertingEnabled: "true",
unifiedAlertingEnabled: "false",
isEnterprise: anyBoolean(),
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -456,6 +463,7 @@ func TestAlertingEnabled(t *testing.T) {
desc: "when legacy alerting is disabled and unified is enabled",
legacyAlertingEnabled: "false",
unifiedAlertingEnabled: "true",
isEnterprise: anyBoolean(),
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -473,6 +481,7 @@ func TestAlertingEnabled(t *testing.T) {
desc: "when both alerting are enabled",
legacyAlertingEnabled: "true",
unifiedAlertingEnabled: "true",
isEnterprise: anyBoolean(),
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -486,6 +495,7 @@ func TestAlertingEnabled(t *testing.T) {
desc: "when legacy alerting is invalid (or not defined) and unified is disabled",
legacyAlertingEnabled: "",
unifiedAlertingEnabled: "false",
isEnterprise: anyBoolean(),
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -503,6 +513,7 @@ func TestAlertingEnabled(t *testing.T) {
desc: "when legacy alerting is invalid (or not defined) and unified is enabled",
legacyAlertingEnabled: "",
unifiedAlertingEnabled: "true",
isEnterprise: anyBoolean(),
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -517,9 +528,10 @@ func TestAlertingEnabled(t *testing.T) {
},
},
{
desc: "when legacy alerting is enabled and unified is invalid (or not defined)",
desc: "when legacy alerting is enabled and unified is invalid (or not defined) [OSS]",
legacyAlertingEnabled: "true",
unifiedAlertingEnabled: "",
isEnterprise: false,
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -533,9 +545,28 @@ func TestAlertingEnabled(t *testing.T) {
},
},
{
desc: "when legacy alerting is disabled and unified is invalid (or not defined)",
desc: "when legacy alerting is enabled and unified is invalid (or not defined) [Enterprise]",
legacyAlertingEnabled: "true",
unifiedAlertingEnabled: "",
isEnterprise: true,
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
err = cfg.readFeatureToggles(f)
require.NoError(t, err)
err = cfg.ReadUnifiedAlertingSettings(f)
require.NoError(t, err)
assert.NotNil(t, cfg.UnifiedAlerting.Enabled)
assert.Equal(t, *cfg.UnifiedAlerting.Enabled, false)
assert.NotNil(t, AlertingEnabled)
assert.Equal(t, *AlertingEnabled, true)
},
},
{
desc: "when legacy alerting is disabled and unified is invalid (or not defined) [OSS]",
legacyAlertingEnabled: "false",
unifiedAlertingEnabled: "invalid",
isEnterprise: false,
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -550,9 +581,28 @@ func TestAlertingEnabled(t *testing.T) {
},
},
{
desc: "when both are invalid (or not defined)",
desc: "when legacy alerting is disabled and unified is invalid (or not defined) [Enterprise]",
legacyAlertingEnabled: "false",
unifiedAlertingEnabled: "invalid",
isEnterprise: true,
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
err = cfg.readFeatureToggles(f)
require.NoError(t, err)
err = cfg.ReadUnifiedAlertingSettings(f)
require.NoError(t, err)
assert.NotNil(t, cfg.UnifiedAlerting.Enabled)
assert.Equal(t, *cfg.UnifiedAlerting.Enabled, false)
assert.NotNil(t, AlertingEnabled)
assert.Equal(t, *AlertingEnabled, false)
},
},
{
desc: "when both are invalid (or not defined) [OSS]",
legacyAlertingEnabled: "invalid",
unifiedAlertingEnabled: "invalid",
isEnterprise: false,
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -564,10 +614,29 @@ func TestAlertingEnabled(t *testing.T) {
assert.Nil(t, AlertingEnabled)
},
},
{
desc: "when both are invalid (or not defined) [Enterprise]",
legacyAlertingEnabled: "invalid",
unifiedAlertingEnabled: "invalid",
isEnterprise: true,
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
err = cfg.readFeatureToggles(f)
require.NoError(t, err)
err = cfg.ReadUnifiedAlertingSettings(f)
require.NoError(t, err)
assert.NotNil(t, cfg.UnifiedAlerting.Enabled)
assert.Equal(t, *cfg.UnifiedAlerting.Enabled, false)
assert.NotNil(t, AlertingEnabled)
assert.Equal(t, *AlertingEnabled, true)
},
},
{
desc: "when both are false",
legacyAlertingEnabled: "false",
unifiedAlertingEnabled: "false",
isEnterprise: anyBoolean(),
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
err := readAlertingSettings(f)
require.NoError(t, err)
@ -583,8 +652,14 @@ func TestAlertingEnabled(t *testing.T) {
},
}
var isEnterpriseOld = IsEnterprise
t.Cleanup(func() {
IsEnterprise = isEnterpriseOld
})
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
IsEnterprise = tc.isEnterprise
t.Cleanup(func() {
AlertingEnabled = nil
})

View File

@ -87,6 +87,14 @@ func (cfg *Cfg) readUnifiedAlertingEnabledSetting(section *ini.Section) (*bool,
AlertingEnabled = &legacyAlerting
return &enabled, nil
}
if IsEnterprise {
enabled = false
if AlertingEnabled == nil {
legacyEnabled := true
AlertingEnabled = &legacyEnabled
}
return &enabled, nil
}
// next, check whether legacy flag is set
if AlertingEnabled != nil && !*AlertingEnabled {
enabled = true