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 = "" authentik_host_browser: str = ""
log_level: str = CONFIG.y("log_level") 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") object_naming_template: str = field(default="ak-outpost-%(name)s")
docker_network: Optional[str] = field(default=None) docker_network: Optional[str] = field(default=None)

View file

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

View file

@ -1,6 +1,7 @@
package ak package ak
import ( import (
"fmt"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -8,17 +9,18 @@ import (
"github.com/getsentry/sentry-go" "github.com/getsentry/sentry-go"
httptransport "github.com/go-openapi/runtime/client" httptransport "github.com/go-openapi/runtime/client"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"goauthentik.io/api"
"goauthentik.io/internal/constants" "goauthentik.io/internal/constants"
) )
func doGlobalSetup(config map[string]interface{}) { func doGlobalSetup(outpost api.Outpost, globalConfig api.Config) {
log.SetFormatter(&log.JSONFormatter{ log.SetFormatter(&log.JSONFormatter{
FieldMap: log.FieldMap{ FieldMap: log.FieldMap{
log.FieldKeyMsg: "event", log.FieldKeyMsg: "event",
log.FieldKeyTime: "timestamp", log.FieldKeyTime: "timestamp",
}, },
}) })
switch config[ConfigLogLevel].(string) { switch outpost.Config[ConfigLogLevel].(string) {
case "trace": case "trace":
log.SetLevel(log.TraceLevel) log.SetLevel(log.TraceLevel)
case "debug": 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") log.WithField("logger", "authentik.outpost").WithField("hash", constants.BUILD()).WithField("version", constants.VERSION).Info("Starting authentik outpost")
sentryEnv := "customer-outpost" if globalConfig.ErrorReporting.Enabled {
sentryEnable := true sentryEnv := fmt.Sprintf("%s-outpost-%s", globalConfig.ErrorReporting.Environment, outpost.Type)
if cSentryEnv, ok := config[ConfigErrorReportingEnvironment]; ok { dsn := "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8"
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"
log.WithField("env", sentryEnv).Debug("Error reporting enabled") log.WithField("env", sentryEnv).Debug("Error reporting enabled")
err := sentry.Init(sentry.ClientOptions{ err := sentry.Init(sentry.ClientOptions{
Dsn: dsn, Dsn: dsn,
Environment: sentryEnv, Environment: sentryEnv,
TracesSampleRate: 1, TracesSampleRate: float64(globalConfig.ErrorReporting.TracesSampleRate),
}) })
if err != nil { 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 ```yaml
# Log level that the outpost will set # Log level that the outpost will set
log_level: debug 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 # The settings below are only relevant when using a managed outpost
######################################## ########################################