From 196dfb99b0329d5c52fd7089e62fbfa1b09df3c6 Mon Sep 17 00:00:00 2001 From: Utku Ozdemir Date: Wed, 31 May 2023 19:17:12 +0200 Subject: [PATCH] fix: do not probe kernel args in dashboard if not needed If the dashboard is run without the "Config URL" screen, do not initialize it, and do not probe the kernel args for the code parameter. Refactor the dashboard to do not construct the unused screens at all. Closes siderolabs/talos#7300. Signed-off-by: Utku Ozdemir --- internal/pkg/dashboard/configurl.go | 8 +++- internal/pkg/dashboard/dashboard.go | 63 ++++++++++++++++------------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/internal/pkg/dashboard/configurl.go b/internal/pkg/dashboard/configurl.go index 18ec0e639..21e882476 100644 --- a/internal/pkg/dashboard/configurl.go +++ b/internal/pkg/dashboard/configurl.go @@ -119,7 +119,13 @@ func NewConfigURLGrid(ctx context.Context, dashboard *Dashboard) *ConfigURLGrid return grid } -func (widget *ConfigURLGrid) readTemplateFromKernelArgs() string { +func (widget *ConfigURLGrid) readTemplateFromKernelArgs() (val string) { + defer func() { // catch potential panic from procfs.ProcCmdline() + if r := recover(); r != nil { + val = "error reading kernel args" + } + }() + option := procfs.ProcCmdline().Get(constants.KernelParamConfig).First() if option == nil { return unset diff --git a/internal/pkg/dashboard/dashboard.go b/internal/pkg/dashboard/dashboard.go index 4ea3c3e1d..065d15985 100644 --- a/internal/pkg/dashboard/dashboard.go +++ b/internal/pkg/dashboard/dashboard.go @@ -114,11 +114,6 @@ type Dashboard struct { pages *tview.Pages - summaryGrid *SummaryGrid - monitorGrid *MonitorGrid - networkConfigGrid *NetworkConfigGrid - configURLGrid *ConfigURLGrid - selectedScreenConfig *screenConfig screenConfigs []screenConfig footer *components.Footer @@ -157,12 +152,7 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D header := components.NewHeader() dashboard.mainGrid.AddItem(header, 0, 0, 1, 1, 0, 0, false) - dashboard.summaryGrid = NewSummaryGrid(dashboard.app) - dashboard.monitorGrid = NewMonitorGrid(dashboard.app) - dashboard.networkConfigGrid = NewNetworkConfigGrid(ctx, dashboard) - dashboard.configURLGrid = NewConfigURLGrid(ctx, dashboard) - - err := dashboard.initScreenConfigs(defOptions.screens) + err := dashboard.initScreenConfigs(ctx, defOptions.screens) if err != nil { return nil, err } @@ -208,26 +198,16 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D dashboard.apiDataListeners = []APIDataListener{ header, - dashboard.summaryGrid, - dashboard.monitorGrid, } dashboard.resourceDataListeners = []ResourceDataListener{ header, - dashboard.summaryGrid, - dashboard.networkConfigGrid, - dashboard.configURLGrid, } - dashboard.logDataListeners = []LogDataListener{ - dashboard.summaryGrid, - } + dashboard.logDataListeners = []LogDataListener{} dashboard.nodeSelectListeners = []NodeSelectListener{ header, - dashboard.summaryGrid, - dashboard.networkConfigGrid, - dashboard.configURLGrid, dashboard.footer, } @@ -235,6 +215,35 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D dashboard.footer, } + for _, config := range dashboard.screenConfigs { + screenPrimitive := config.primitive + + apiDataListener, ok := screenPrimitive.(APIDataListener) + if ok { + dashboard.apiDataListeners = append(dashboard.apiDataListeners, apiDataListener) + } + + resourceDataListener, ok := screenPrimitive.(ResourceDataListener) + if ok { + dashboard.resourceDataListeners = append(dashboard.resourceDataListeners, resourceDataListener) + } + + logDataListener, ok := screenPrimitive.(LogDataListener) + if ok { + dashboard.logDataListeners = append(dashboard.logDataListeners, logDataListener) + } + + nodeSelectListener, ok := screenPrimitive.(NodeSelectListener) + if ok { + dashboard.nodeSelectListeners = append(dashboard.nodeSelectListeners, nodeSelectListener) + } + + nodeSetListener, ok := screenPrimitive.(NodeSetListener) + if ok { + dashboard.nodeSetChangeListeners = append(dashboard.nodeSetChangeListeners, nodeSetListener) + } + } + dashboard.apiDataSource = &apidata.Source{ Client: cli, Interval: defOptions.interval, @@ -249,17 +258,17 @@ func buildDashboard(ctx context.Context, cli *client.Client, opts ...Option) (*D return dashboard, nil } -func (d *Dashboard) initScreenConfigs(screens []Screen) error { +func (d *Dashboard) initScreenConfigs(ctx context.Context, screens []Screen) error { primitiveForScreen := func(screen Screen) screenSelectListener { switch screen { case ScreenSummary: - return d.summaryGrid + return NewSummaryGrid(d.app) case ScreenMonitor: - return d.monitorGrid + return NewMonitorGrid(d.app) case ScreenNetworkConfig: - return d.networkConfigGrid + return NewNetworkConfigGrid(ctx, d) case ScreenConfigURL: - return d.configURLGrid + return NewConfigURLGrid(ctx, d) default: return nil }