diff --git a/cmd/query/app/static_handler.go b/cmd/query/app/static_handler.go index 89dffe606c6..8084b218155 100644 --- a/cmd/query/app/static_handler.go +++ b/cmd/query/app/static_handler.go @@ -37,11 +37,13 @@ var ( // RegisterStaticHandler adds handler for static assets to the router. func RegisterStaticHandler(r *mux.Router, logger *zap.Logger, qOpts *QueryOptions, qCapabilities querysvc.StorageCapabilities) io.Closer { staticHandler, err := NewStaticAssetsHandler(qOpts.UIConfig.AssetsPath, StaticAssetsHandlerOptions{ + UIConfig: UIConfig{ + ConfigFile: qOpts.UIConfig.ConfigFile, + LogAccess: qOpts.UIConfig.LogAccess, + }, BasePath: qOpts.BasePath, - UIConfigPath: qOpts.UIConfig.ConfigFile, StorageCapabilities: qCapabilities, Logger: logger, - LogAccess: qOpts.UIConfig.LogAccess, }) if err != nil { logger.Panic("Could not create static assets handler", zap.Error(err)) @@ -62,9 +64,8 @@ type StaticAssetsHandler struct { // StaticAssetsHandlerOptions defines options for NewStaticAssetsHandler type StaticAssetsHandlerOptions struct { + UIConfig UIConfig BasePath string - UIConfigPath string - LogAccess bool StorageCapabilities querysvc.StorageCapabilities Logger *zap.Logger } @@ -91,8 +92,8 @@ func NewStaticAssetsHandler(staticAssetsRoot string, options StaticAssetsHandler return nil, err } - options.Logger.Info("Using UI configuration", zap.String("path", options.UIConfigPath)) - watcher, err := fswatcher.New([]string{options.UIConfigPath}, h.reloadUIConfig, h.options.Logger) + options.Logger.Info("Using UI configuration", zap.String("path", options.UIConfig.ConfigFile)) + watcher, err := fswatcher.New([]string{options.UIConfig.ConfigFile}, h.reloadUIConfig, h.options.Logger) if err != nil { return nil, err } @@ -109,7 +110,7 @@ func (sH *StaticAssetsHandler) loadAndEnrichIndexHTML(open func(string) (http.Fi return nil, fmt.Errorf("cannot load index.html: %w", err) } // replace UI config - if configObject, err := loadUIConfig(sH.options.UIConfigPath); err != nil { + if configObject, err := loadUIConfig(sH.options.UIConfig.ConfigFile); err != nil { return nil, err } else if configObject != nil { indexBytes = configObject.regexp.ReplaceAll(indexBytes, configObject.config) @@ -137,13 +138,13 @@ func (sH *StaticAssetsHandler) loadAndEnrichIndexHTML(open func(string) (http.Fi } func (sH *StaticAssetsHandler) reloadUIConfig() { - sH.options.Logger.Info("reloading UI config", zap.String("filename", sH.options.UIConfigPath)) + sH.options.Logger.Info("reloading UI config", zap.String("filename", sH.options.UIConfig.ConfigFile)) content, err := sH.loadAndEnrichIndexHTML(sH.assetsFS.Open) if err != nil { sH.options.Logger.Error("error while reloading the UI config", zap.Error(err)) } sH.indexHTML.Store(content) - sH.options.Logger.Info("reloaded UI config", zap.String("filename", sH.options.UIConfigPath)) + sH.options.Logger.Info("reloaded UI config", zap.String("filename", sH.options.UIConfig.ConfigFile)) } func loadIndexHTML(open func(string) (http.File, error)) ([]byte, error) { @@ -200,7 +201,7 @@ func loadUIConfig(uiConfig string) (*loadedConfig, error) { } func (sH *StaticAssetsHandler) loggingHandler(handler http.Handler) http.Handler { - if !sH.options.LogAccess { + if !sH.options.UIConfig.LogAccess { return handler } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/cmd/query/app/static_handler_test.go b/cmd/query/app/static_handler_test.go index 7f40cc4cc60..40446bdbfda 100644 --- a/cmd/query/app/static_handler_test.go +++ b/cmd/query/app/static_handler_test.go @@ -158,16 +158,20 @@ func TestRegisterStaticHandler(t *testing.T) { func TestNewStaticAssetsHandlerErrors(t *testing.T) { _, err := NewStaticAssetsHandler("fixture", StaticAssetsHandlerOptions{ - UIConfigPath: "fixture/invalid-config", - Logger: zap.NewNop(), + UIConfig: UIConfig{ + ConfigFile: "fixture/invalid-config", + }, + Logger: zap.NewNop(), }) require.Error(t, err) for _, base := range []string{"x", "x/", "/x/"} { _, err := NewStaticAssetsHandler("fixture", StaticAssetsHandlerOptions{ - UIConfigPath: "fixture/ui-config.json", - BasePath: base, - Logger: zap.NewNop(), + UIConfig: UIConfig{ + ConfigFile: "fixture/ui-config.json", + }, + BasePath: base, + Logger: zap.NewNop(), }) require.Errorf(t, err, "basePath=%s", base) assert.Contains(t, err.Error(), "invalid base path") @@ -195,8 +199,10 @@ func TestHotReloadUIConfig(t *testing.T) { zcore, logObserver := observer.New(zapcore.InfoLevel) logger := zap.New(zcore) h, err := NewStaticAssetsHandler("fixture", StaticAssetsHandlerOptions{ - UIConfigPath: cfgFileName, - Logger: logger, + UIConfig: UIConfig{ + ConfigFile: cfgFileName, + }, + Logger: logger, }) require.NoError(t, err) defer h.Close()