outpost: configure error reporting based off of main instance config

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-11-29 14:42:19 +01:00
parent a6abeb50c6
commit 9a393848b2
4 changed files with 11 additions and 27 deletions

View File

@ -67,8 +67,6 @@ class OutpostConfig:
authentik_host_browser: str = ""
log_level: str = CONFIG.y("log_level")
error_reporting_enabled: bool = CONFIG.y_bool("error_reporting.enabled")
error_reporting_environment: str = CONFIG.y("error_reporting.environment", "customer")
object_naming_template: str = field(default="ak-outpost-%(name)s")
docker_network: Optional[str] = field(default=None)

View File

@ -22,8 +22,6 @@ import (
)
const ConfigLogLevel = "log_level"
const ConfigErrorReportingEnabled = "error_reporting_enabled"
const ConfigErrorReportingEnvironment = "error_reporting_environment"
// APIController main controller which connects to the authentik api via http and ws
type APIController struct {
@ -68,7 +66,6 @@ func NewAPIController(akURL url.URL, token string) *APIController {
return nil
}
outpost := outposts.Results[0]
doGlobalSetup(outpost.Config)
log.WithField("name", outpost.Name).Debug("Fetched outpost configuration")
@ -79,6 +76,8 @@ func NewAPIController(akURL url.URL, token string) *APIController {
}
log.Debug("Fetched global configuration")
doGlobalSetup(outpost, akConfig)
ac := &APIController{
Client: apiClient,
GlobalConfig: akConfig,

View File

@ -1,6 +1,7 @@
package ak
import (
"fmt"
"net/http"
"os"
"strings"
@ -8,17 +9,18 @@ import (
"github.com/getsentry/sentry-go"
httptransport "github.com/go-openapi/runtime/client"
log "github.com/sirupsen/logrus"
"goauthentik.io/api"
"goauthentik.io/internal/constants"
)
func doGlobalSetup(config map[string]interface{}) {
func doGlobalSetup(outpost api.Outpost, globalConfig api.Config) {
log.SetFormatter(&log.JSONFormatter{
FieldMap: log.FieldMap{
log.FieldKeyMsg: "event",
log.FieldKeyTime: "timestamp",
},
})
switch config[ConfigLogLevel].(string) {
switch outpost.Config[ConfigLogLevel].(string) {
case "trace":
log.SetLevel(log.TraceLevel)
case "debug":
@ -34,29 +36,17 @@ func doGlobalSetup(config map[string]interface{}) {
}
log.WithField("logger", "authentik.outpost").WithField("hash", constants.BUILD()).WithField("version", constants.VERSION).Info("Starting authentik outpost")
sentryEnv := "customer-outpost"
sentryEnable := true
if cSentryEnv, ok := config[ConfigErrorReportingEnvironment]; ok {
if ccSentryEnv, ok := cSentryEnv.(string); ok {
sentryEnv = ccSentryEnv
}
}
var dsn string
if cSentryEnable, ok := config[ConfigErrorReportingEnabled]; ok {
if ccSentryEnable, ok := cSentryEnable.(bool); ok {
sentryEnable = ccSentryEnable
}
}
if sentryEnable {
dsn = "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8"
if globalConfig.ErrorReporting.Enabled {
sentryEnv := fmt.Sprintf("%s-outpost-%s", globalConfig.ErrorReporting.Environment, outpost.Type)
dsn := "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8"
log.WithField("env", sentryEnv).Debug("Error reporting enabled")
err := sentry.Init(sentry.ClientOptions{
Dsn: dsn,
Environment: sentryEnv,
TracesSampleRate: 1,
TracesSampleRate: float64(globalConfig.ErrorReporting.TracesSampleRate),
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
log.WithField("env", sentryEnv).WithError(err).Warning("Failed to initialise sentry")
}
}
}

View File

@ -27,9 +27,6 @@ Outposts fetch their configuration from authentik. Below are all the options you
```yaml
# Log level that the outpost will set
log_level: debug
# Enable/disable error reporting for the outpost, based on the authentik settings
error_reporting_enabled: true
error_reporting_environment: beryjuorg-prod
########################################
# The settings below are only relevant when using a managed outpost
########################################