mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 11:32:16 +08:00
Alerting: Disable unified alerting by default in Enterprise Grafana (#42476)
* fallback to enable false if Enterprise is true * anyBoolean
This commit is contained in:
@ -2,6 +2,7 @@ package setting
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -428,17 +429,23 @@ func TestGetCDNPathWithAlphaVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertingEnabled(t *testing.T) {
|
func TestAlertingEnabled(t *testing.T) {
|
||||||
|
anyBoolean := func() bool {
|
||||||
|
return rand.Int63()%2 == 0
|
||||||
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
unifiedAlertingEnabled string
|
unifiedAlertingEnabled string
|
||||||
legacyAlertingEnabled string
|
legacyAlertingEnabled string
|
||||||
featureToggleSet bool
|
featureToggleSet bool
|
||||||
|
isEnterprise bool
|
||||||
verifyCfg func(*testing.T, Cfg, *ini.File)
|
verifyCfg func(*testing.T, Cfg, *ini.File)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "when legacy alerting is enabled and unified is disabled",
|
desc: "when legacy alerting is enabled and unified is disabled",
|
||||||
legacyAlertingEnabled: "true",
|
legacyAlertingEnabled: "true",
|
||||||
unifiedAlertingEnabled: "false",
|
unifiedAlertingEnabled: "false",
|
||||||
|
isEnterprise: anyBoolean(),
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -456,6 +463,7 @@ func TestAlertingEnabled(t *testing.T) {
|
|||||||
desc: "when legacy alerting is disabled and unified is enabled",
|
desc: "when legacy alerting is disabled and unified is enabled",
|
||||||
legacyAlertingEnabled: "false",
|
legacyAlertingEnabled: "false",
|
||||||
unifiedAlertingEnabled: "true",
|
unifiedAlertingEnabled: "true",
|
||||||
|
isEnterprise: anyBoolean(),
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -473,6 +481,7 @@ func TestAlertingEnabled(t *testing.T) {
|
|||||||
desc: "when both alerting are enabled",
|
desc: "when both alerting are enabled",
|
||||||
legacyAlertingEnabled: "true",
|
legacyAlertingEnabled: "true",
|
||||||
unifiedAlertingEnabled: "true",
|
unifiedAlertingEnabled: "true",
|
||||||
|
isEnterprise: anyBoolean(),
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
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",
|
desc: "when legacy alerting is invalid (or not defined) and unified is disabled",
|
||||||
legacyAlertingEnabled: "",
|
legacyAlertingEnabled: "",
|
||||||
unifiedAlertingEnabled: "false",
|
unifiedAlertingEnabled: "false",
|
||||||
|
isEnterprise: anyBoolean(),
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
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",
|
desc: "when legacy alerting is invalid (or not defined) and unified is enabled",
|
||||||
legacyAlertingEnabled: "",
|
legacyAlertingEnabled: "",
|
||||||
unifiedAlertingEnabled: "true",
|
unifiedAlertingEnabled: "true",
|
||||||
|
isEnterprise: anyBoolean(),
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
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",
|
legacyAlertingEnabled: "true",
|
||||||
unifiedAlertingEnabled: "",
|
unifiedAlertingEnabled: "",
|
||||||
|
isEnterprise: false,
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
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",
|
legacyAlertingEnabled: "false",
|
||||||
unifiedAlertingEnabled: "invalid",
|
unifiedAlertingEnabled: "invalid",
|
||||||
|
isEnterprise: false,
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
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",
|
legacyAlertingEnabled: "invalid",
|
||||||
unifiedAlertingEnabled: "invalid",
|
unifiedAlertingEnabled: "invalid",
|
||||||
|
isEnterprise: false,
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -564,10 +614,29 @@ func TestAlertingEnabled(t *testing.T) {
|
|||||||
assert.Nil(t, AlertingEnabled)
|
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",
|
desc: "when both are false",
|
||||||
legacyAlertingEnabled: "false",
|
legacyAlertingEnabled: "false",
|
||||||
unifiedAlertingEnabled: "false",
|
unifiedAlertingEnabled: "false",
|
||||||
|
isEnterprise: anyBoolean(),
|
||||||
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
verifyCfg: func(t *testing.T, cfg Cfg, f *ini.File) {
|
||||||
err := readAlertingSettings(f)
|
err := readAlertingSettings(f)
|
||||||
require.NoError(t, err)
|
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 {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
|
IsEnterprise = tc.isEnterprise
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
AlertingEnabled = nil
|
AlertingEnabled = nil
|
||||||
})
|
})
|
||||||
|
@ -87,6 +87,14 @@ func (cfg *Cfg) readUnifiedAlertingEnabledSetting(section *ini.Section) (*bool,
|
|||||||
AlertingEnabled = &legacyAlerting
|
AlertingEnabled = &legacyAlerting
|
||||||
return &enabled, nil
|
return &enabled, nil
|
||||||
}
|
}
|
||||||
|
if IsEnterprise {
|
||||||
|
enabled = false
|
||||||
|
if AlertingEnabled == nil {
|
||||||
|
legacyEnabled := true
|
||||||
|
AlertingEnabled = &legacyEnabled
|
||||||
|
}
|
||||||
|
return &enabled, nil
|
||||||
|
}
|
||||||
// next, check whether legacy flag is set
|
// next, check whether legacy flag is set
|
||||||
if AlertingEnabled != nil && !*AlertingEnabled {
|
if AlertingEnabled != nil && !*AlertingEnabled {
|
||||||
enabled = true
|
enabled = true
|
||||||
|
Reference in New Issue
Block a user