Skip to content

Commit

Permalink
Merge pull request #365 from checkr/zz/add-sentry-env
Browse files Browse the repository at this point in the history
Add sentry env configuration
  • Loading branch information
zhouzhuojie authored May 14, 2020
2 parents ef0fe94 + 0b51c0b commit d9bca69
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func setupSentry() {
logrus.FatalLevel,
logrus.ErrorLevel,
})
if Config.SentryEnvironment != "" {
hook.SetEnvironment(Config.SentryEnvironment)
}
if err != nil {
logrus.WithField("err", err).Error("failed to hook logurs to sentry")
return
Expand Down
39 changes: 24 additions & 15 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,57 @@ import (

func TestSetupSentry(t *testing.T) {
Config.SentryEnabled = true
assert.NotPanics(t, func() {
setupSentry()
})
Config.SentryEnabled = false
Config.SentryEnvironment = "test"
defer func() {
Config.SentryEnabled = false
Config.SentryEnvironment = ""
}()

assert.NotPanics(t, func() { setupSentry() })
}

func TestSetupNewRelic(t *testing.T) {
Config.NewRelicEnabled = true
assert.Panics(t, func() {
setupNewrelic()
})
Config.NewRelicEnabled = false
defer func() {
Config.NewRelicEnabled = false
}()

assert.Panics(t, func() { setupNewrelic() })
}

func TestSetupStatsd(t *testing.T) {
Config.StatsdEnabled = true
assert.NotPanics(t, func() {
setupStatsd()
})
Config.StatsdEnabled = false
defer func() {
Config.StatsdEnabled = false
}()

assert.NotPanics(t, func() { setupStatsd() })
}

func TestSetupPrometheus(t *testing.T) {
prometheus.DefaultRegisterer = prometheus.NewRegistry()
Config.PrometheusEnabled = false
setupPrometheus()
assert.Nil(t, Global.Prometheus.EvalCounter)

Config.PrometheusEnabled = true
defer func() { Config.PrometheusEnabled = false }()
setupPrometheus()
assert.NotNil(t, Global.Prometheus.EvalCounter)
assert.NotNil(t, Global.Prometheus.RequestCounter)
assert.Nil(t, Global.Prometheus.RequestHistogram)
Config.PrometheusEnabled = false
}

func TestSetupPrometheusWithLatencies(t *testing.T) {
prometheus.DefaultRegisterer = prometheus.NewRegistry()
Config.PrometheusEnabled = true
Config.PrometheusIncludeLatencyHistogram = true
defer func() {
Config.PrometheusEnabled = false
Config.PrometheusIncludeLatencyHistogram = false
}()

setupPrometheus()
assert.NotNil(t, Global.Prometheus.EvalCounter)
assert.NotNil(t, Global.Prometheus.RequestCounter)
assert.NotNil(t, Global.Prometheus.RequestHistogram)
Config.PrometheusEnabled = false
}
5 changes: 3 additions & 2 deletions pkg/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ var Config = struct {
CORSEnabled bool `env:"FLAGR_CORS_ENABLED" envDefault:"true"`

// SentryEnabled - enable Sentry and Sentry DSN
SentryEnabled bool `env:"FLAGR_SENTRY_ENABLED" envDefault:"false"`
SentryDSN string `env:"FLAGR_SENTRY_DSN" envDefault:""`
SentryEnabled bool `env:"FLAGR_SENTRY_ENABLED" envDefault:"false"`
SentryDSN string `env:"FLAGR_SENTRY_DSN" envDefault:""`
SentryEnvironment string `env:"FLAGR_SENTRY_ENVIRONMENT" envDefault:""`

// NewRelicEnabled - enable the NewRelic monitoring for all the endpoints and DB operations
NewRelicEnabled bool `env:"FLAGR_NEWRELIC_ENABLED" envDefault:"false"`
Expand Down

0 comments on commit d9bca69

Please sign in to comment.