Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ to `http://localhost:3100`. You can disable this by re-running the console with

Navigate to <http://localhost:9000/monitoring/logs> to see the running plugin.

### Local Development Troubleshooting
1. Disable cache. Select 'disable cache' in your browser's DevTools > Network > 'disable cache'. Or use private/incognito mode in your browser.
2. Enable higher log verbosity by setting `-log-level=trace` when starting the plugin backend. For more options to set log level see [logrus documentation](https://github.com/sirupsen/logrus?tab=readme-ov-file#level-logging).

### Running tests

#### Unit tests
Expand Down
3 changes: 3 additions & 0 deletions cmd/plugin-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
staticPathArg = flag.String("static-path", "", "static files path to serve frontend (default: './web/dist')")
configPathArg = flag.String("config-path", "", "config files path (default: './config')")
pluginConfigArg = flag.String("plugin-config-path", "", "plugin yaml configuration")
logLevelArg = flag.String("log-level", "error", "verbosity of logs\noptions: ['panic', 'fatal', 'error', 'warn', 'info', 'debug', 'trace']\n'trace' level will log all incoming requests\n(default 'error')")
log = logrus.WithField("module", "main")
)

Expand All @@ -31,6 +32,7 @@ func main() {
staticPath := mergeEnvValue("LOGGING_VIEW_PLUGIN_STATIC_PATH", *staticPathArg, "./web/dist")
configPath := mergeEnvValue("LOGGING_VIEW_PLUGIN_MANIFEST_CONFIG_PATH", *configPathArg, "./config")
pluginConfigPath := mergeEnvValue("LOGGING_VIEW_PLUGIN_CONFIG_PATH", *pluginConfigArg, "/etc/plugin/config.yaml")
logLevel := mergeEnvValue("LOGGING_VIEW_PLUGIN_LOG_LEVEL", *logLevelArg, "error")

featuresList := strings.Fields(strings.Join(strings.Split(strings.ToLower(features), ","), " "))

Expand All @@ -49,6 +51,7 @@ func main() {
StaticPath: staticPath,
ConfigPath: configPath,
PluginConfigPath: pluginConfigPath,
LogLevel: logLevel,
})
}

Expand Down
18 changes: 15 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Config struct {
StaticPath string
ConfigPath string
PluginConfigPath string
LogLevel string
}

type PluginConfig struct {
Expand All @@ -51,26 +52,37 @@ func Start(cfg *Config) {
router := setupRoutes(cfg)
router.Use(corsHeaderMiddleware(cfg))

loggedRouter := handlers.LoggingHandler(slog.Logger.Out, router)

// clients must use TLS 1.2 or higher
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
}

logrusLevel, err := logrus.ParseLevel(cfg.LogLevel)
if err != nil {
logrus.WithError(err).Fatal("unable to set the log level")
logrusLevel = logrus.ErrorLevel
}

httpServer := &http.Server{
Handler: loggedRouter,
Handler: router,
Addr: fmt.Sprintf(":%d", cfg.Port),
TLSConfig: tlsConfig,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
}

if logrusLevel == logrus.TraceLevel {
loggedRouter := handlers.LoggingHandler(slog.Logger.Out, router)
httpServer.Handler = loggedRouter
}

if cfg.CertFile != "" && cfg.PrivateKeyFile != "" {
slog.Infof("listening on https://:%d", cfg.Port)
logrus.SetLevel(logrusLevel)
panic(httpServer.ListenAndServeTLS(cfg.CertFile, cfg.PrivateKeyFile))
} else {
slog.Infof("listening on http://:%d", cfg.Port)
logrus.SetLevel(logrusLevel)
panic(httpServer.ListenAndServe())
}
}
Expand Down