Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
monitoring: fix default true for hideObservabilitySiteAlerts (#12189)
Browse files Browse the repository at this point in the history
fixes https://github.com/sourcegraph/sourcegraph/pull/12155#discussion_r454655541 - setting the default in the schema is not sufficient
  • Loading branch information
bobheadxi authored Jul 15, 2020
1 parent 4aba276 commit 870221e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
9 changes: 7 additions & 2 deletions cmd/frontend/graphqlbackend/site_alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,13 @@ func determineOutOfDateAlert(isAdmin bool, months int, offline bool) *Alert {
// observabilityActiveAlertsAlert directs admins to check Grafana if critical alerts are firing
func observabilityActiveAlertsAlert(prometheusURL string) func(AlertFuncArgs) []*Alert {
return func(args AlertFuncArgs) []*Alert {
observabilitySiteAlertsDisabled := args.ViewerFinalSettings != nil && args.ViewerFinalSettings.AlertsHideObservabilitySiteAlerts
if !args.IsSiteAdmin || len(prometheusURL) == 0 || observabilitySiteAlertsDisabled {
// true by default - change settings.schema.json if this changes
observabilitySiteAlertsDisabled := true
if args.ViewerFinalSettings != nil && args.ViewerFinalSettings.AlertsHideObservabilitySiteAlerts != nil {
observabilitySiteAlertsDisabled = *args.ViewerFinalSettings.AlertsHideObservabilitySiteAlerts
}

if !args.IsSiteAdmin || prometheusURL == "" || observabilitySiteAlertsDisabled {
return nil
}

Expand Down
33 changes: 25 additions & 8 deletions cmd/frontend/graphqlbackend/site_alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func Test_determineOutOfDateAlert(t *testing.T) {
}

func TestObservabilityActiveAlertsAlert(t *testing.T) {
f := false
type args struct {
prometheusURL string
args AlertFuncArgs
Expand All @@ -115,22 +116,36 @@ func TestObservabilityActiveAlertsAlert(t *testing.T) {
{
name: "not admin",
args: args{
args: AlertFuncArgs{IsSiteAdmin: true},
args: AlertFuncArgs{
IsSiteAdmin: true,
ViewerFinalSettings: &schema.Settings{
AlertsHideObservabilitySiteAlerts: &f,
},
},
},
want: nil,
},
{
name: "prometheus disabled",
args: args{
args: AlertFuncArgs{IsSiteAdmin: true},
args: AlertFuncArgs{
IsSiteAdmin: true,
ViewerFinalSettings: &schema.Settings{
AlertsHideObservabilitySiteAlerts: &f,
}},
prometheusURL: "",
},
want: nil,
},
{
name: "prometheus malformed",
args: args{
args: AlertFuncArgs{IsSiteAdmin: true},
args: AlertFuncArgs{
IsSiteAdmin: true,
ViewerFinalSettings: &schema.Settings{
AlertsHideObservabilitySiteAlerts: &f,
},
},
prometheusURL: " http://prometheus:9090",
},
want: []*Alert{{
Expand All @@ -141,7 +156,12 @@ func TestObservabilityActiveAlertsAlert(t *testing.T) {
{
name: "prometheus unreachable",
args: args{
args: AlertFuncArgs{IsSiteAdmin: true},
args: AlertFuncArgs{
IsSiteAdmin: true,
ViewerFinalSettings: &schema.Settings{
AlertsHideObservabilitySiteAlerts: &f,
},
},
prometheusURL: "http://no-prometheus:9090",
},
want: []*Alert{{
Expand All @@ -150,13 +170,10 @@ func TestObservabilityActiveAlertsAlert(t *testing.T) {
}},
},
{
name: "no alerts if alerts are disabled",
name: "alerts disabled by default",
args: args{
args: AlertFuncArgs{
IsSiteAdmin: true,
ViewerFinalSettings: &schema.Settings{
AlertsHideObservabilitySiteAlerts: true,
},
},
prometheusURL: "http://no-prometheus:9090",
},
Expand Down
9 changes: 1 addition & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,7 @@ github.com/sourcegraph/jsonx v0.0.0-20200625022044-c22a595bbad7 h1:G58fa9uWw59V5
github.com/sourcegraph/jsonx v0.0.0-20200625022044-c22a595bbad7/go.mod h1:7jkSQ2sdxwXMaIDxKJotTt+hwKnT9b/wbJFU7/ObUEY=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/sourcegraph/zoekt v0.0.0-20200622101713-7b13614a083e h1:g7164BqqH/2SXaWaUjHtgUL3808yFfrbnKZ/JiWmiTI=
github.com/sourcegraph/zoekt v0.0.0-20200622101713-7b13614a083e/go.mod h1:WleTVLMEfvGF6uZ/mSWXVUH1H4NPxAcu6YbJ0TORdWc=
github.com/sourcegraph/zoekt v0.0.0-20200713222406-e18ef28c5e83 h1:EB6RKE5d+i1zw2+yprhkZz97kQNt5syWw8dO/oucd4s=
github.com/sourcegraph/zoekt v0.0.0-20200713222406-e18ef28c5e83/go.mod h1:WleTVLMEfvGF6uZ/mSWXVUH1H4NPxAcu6YbJ0TORdWc=
github.com/sourcegraph/zoekt v0.0.0-20200713223616-6c04e2e54f66 h1:YSsYlwZkAO3Fc+PlXtFbTBNqFCQNVFAxRhFPIabiHI8=
github.com/sourcegraph/zoekt v0.0.0-20200713223616-6c04e2e54f66/go.mod h1:WleTVLMEfvGF6uZ/mSWXVUH1H4NPxAcu6YbJ0TORdWc=
github.com/sourcegraph/zoekt v0.0.0-20200714193922-27c53f42a968 h1:bAVNFzQTs93cBtXvrORtcvawWsaOH/ZfsOYL8KgtTxs=
github.com/sourcegraph/zoekt v0.0.0-20200714193922-27c53f42a968/go.mod h1:WleTVLMEfvGF6uZ/mSWXVUH1H4NPxAcu6YbJ0TORdWc=
github.com/sourcegraph/zoekt v0.0.0-20200714221025-dea986a54d01 h1:Qp+BmPgBkC4e0J5hAXS+UpdoPhQTkCrxYxkoyrxQ1nI=
github.com/sourcegraph/zoekt v0.0.0-20200714221025-dea986a54d01/go.mod h1:WleTVLMEfvGF6uZ/mSWXVUH1H4NPxAcu6YbJ0TORdWc=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down
2 changes: 1 addition & 1 deletion schema/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion schema/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
"alerts.hideObservabilitySiteAlerts": {
"description": "Disables observability-related site alert banners.",
"type": "boolean",
"default": true
"default": true,
"!go": { "pointer": true }
},
"extensions": {
"description": "The Sourcegraph extensions to use. Enable an extension by adding a property `\"my/extension\": true` (where `my/extension` is the extension ID). Override a previously enabled extension and disable it by setting its value to `false`.",
Expand Down
3 changes: 2 additions & 1 deletion schema/settings_stringdata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 870221e

Please sign in to comment.