From 7fbc3e6ece91ed1f179959cd8f5d551fb5e0750d Mon Sep 17 00:00:00 2001 From: lukasz Date: Thu, 20 Jul 2023 14:25:59 +0200 Subject: [PATCH] Add maxPodLogsToRender setting Signed-off-by: lukasz --- server/application/application.go | 9 +++++++-- util/settings/settings.go | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/server/application/application.go b/server/application/application.go index fe9697dc77056e..f1ccdd71acc4a2 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -1569,8 +1569,13 @@ func (s *Server) PodLogs(q *application.ApplicationPodLogsQuery, ws application. return nil } - if len(pods) > maxPodLogsToRender { - return errors.New("Max pods to view logs are reached. Please provide more granular query.") + maxPodLogsToRender, err := s.settingsMgr.GetMaxPodLogsToRender() + if err != nil { + return fmt.Errorf("error getting MaxPodLogsToRender config: %w", err) + } + + if int64(len(pods)) > maxPodLogsToRender { + return errors.New("max pods to view logs are reached. Please provide more granular query") } var streams []chan logEntry diff --git a/util/settings/settings.go b/util/settings/settings.go index 9cd38417e081ef..3532ad091968ce 100644 --- a/util/settings/settings.go +++ b/util/settings/settings.go @@ -101,6 +101,8 @@ type ArgoCDSettings struct { InClusterEnabled bool `json:"inClusterEnabled"` // ServerRBACLogEnforceEnable temporary var indicates whether rbac will be enforced on logs ServerRBACLogEnforceEnable bool `json:"serverRBACLogEnforceEnable"` + // MaxPodLogsToRender the maximum number of pod logs to render + MaxPodLogsToRender int64 `json:"maxPodLogsToRender"` // ExecEnabled indicates whether the UI exec feature is enabled ExecEnabled bool `json:"execEnabled"` // ExecShells restricts which shells are allowed for `exec` and in which order they are tried @@ -475,6 +477,8 @@ const ( inClusterEnabledKey = "cluster.inClusterEnabled" // settingsServerRBACLogEnforceEnable is the key to configure whether logs RBAC enforcement is enabled settingsServerRBACLogEnforceEnableKey = "server.rbac.log.enforce.enable" + // MaxPodLogsToRender the maximum number of pod logs to render + settingsMaxPodLogsToRender = "server.maxPodLogsToRender" // helmValuesFileSchemesKey is the key to configure the list of supported helm values file schemas helmValuesFileSchemesKey = "helm.valuesFileSchemes" // execEnabledKey is the key to configure whether the UI exec feature is enabled @@ -756,6 +760,19 @@ func (mgr *SettingsManager) GetServerRBACLogEnforceEnable() (bool, error) { return strconv.ParseBool(argoCDCM.Data[settingsServerRBACLogEnforceEnableKey]) } +func (mgr *SettingsManager) GetMaxPodLogsToRender() (int64, error) { + argoCDCM, err := mgr.getConfigMap() + if err != nil { + return 10, err + } + + if argoCDCM.Data[settingsMaxPodLogsToRender] == "" { + return 10, nil + } + + return strconv.ParseInt(argoCDCM.Data[settingsMaxPodLogsToRender], 10, 64) +} + func (mgr *SettingsManager) GetDeepLinks(deeplinkType string) ([]DeepLink, error) { argoCDCM, err := mgr.getConfigMap() if err != nil { @@ -1412,6 +1429,13 @@ func updateSettingsFromConfigMap(settings *ArgoCDSettings, argoCDCM *apiv1.Confi if settings.PasswordPattern == "" { settings.PasswordPattern = common.PasswordPatten } + if maxPodLogsToRenderStr, ok := argoCDCM.Data[settingsMaxPodLogsToRender]; ok { + if val, err := strconv.ParseInt(maxPodLogsToRenderStr, 10, 64); err != nil { + log.Warnf("Failed to parse '%s' key: %v", settingsMaxPodLogsToRender, err) + } else { + settings.MaxPodLogsToRender = val + } + } settings.InClusterEnabled = argoCDCM.Data[inClusterEnabledKey] != "false" settings.ExecEnabled = argoCDCM.Data[execEnabledKey] == "true" execShells := argoCDCM.Data[execShellsKey]