diff --git a/business/dashboards.go b/business/dashboards.go index 9c5895a8d2..0ae14198a4 100644 --- a/business/dashboards.go +++ b/business/dashboards.go @@ -569,14 +569,19 @@ func (in *DashboardsService) GetCustomDashboardRefs(namespace, app, version stri if len(runtimes) == 0 { cfg := config.Get() - filters := make(map[string]string) - if app != "" { - filters[cfg.IstioLabels.AppLabelName] = app - } - if version != "" { - filters[cfg.IstioLabels.VersionLabelName] = version + discoveryEnabled := cfg.ExternalServices.CustomDashboards.DiscoveryEnabled + if discoveryEnabled == config.DashboardsDiscoveryEnabled || + (discoveryEnabled == config.DashboardsDiscoveryAuto && + len(pods) <= cfg.ExternalServices.CustomDashboards.DiscoveryAutoThreshold) { + filters := make(map[string]string) + if app != "" { + filters[cfg.IstioLabels.AppLabelName] = app + } + if version != "" { + filters[cfg.IstioLabels.VersionLabelName] = version + } + runtimes = in.discoverDashboards(namespace, filters) } - runtimes = in.discoverDashboards(namespace, filters) } return runtimes } diff --git a/config/config.go b/config/config.go index 6d1648ce17..59fb27d680 100644 --- a/config/config.go +++ b/config/config.go @@ -59,6 +59,12 @@ const ( OidcClientSecretFile = "/kiali-secret/oidc-secret" ) +const ( + DashboardsDiscoveryEnabled = "true" + DashboardsDiscoveryDisabled = "false" + DashboardsDiscoveryAuto = "auto" +) + // Global configuration for the application. var configuration Config var rwMutex sync.RWMutex @@ -112,10 +118,12 @@ type PrometheusConfig struct { // CustomDashboardsConfig describes configuration specific to Custom Dashboards type CustomDashboardsConfig struct { - Enabled bool `yaml:"enabled,omitempty"` - IsCoreComponent bool `yaml:"is_core_component,omitempty"` - NamespaceLabel string `yaml:"namespace_label,omitempty"` - Prometheus PrometheusConfig `yaml:"prometheus,omitempty"` + DiscoveryEnabled string `yaml:"discovery_enabled,omitempty"` + DiscoveryAutoThreshold int `yaml:"discovery_auto_threshold,omitempty"` + Enabled bool `yaml:"enabled,omitempty"` + IsCoreComponent bool `yaml:"is_core_component,omitempty"` + NamespaceLabel string `yaml:"namespace_label,omitempty"` + Prometheus PrometheusConfig `yaml:"prometheus,omitempty"` } // GrafanaConfig describes configuration used for Grafana links @@ -388,8 +396,10 @@ func NewConfig() (c *Config) { }, ExternalServices: ExternalServices{ CustomDashboards: CustomDashboardsConfig{ - Enabled: true, - NamespaceLabel: "kubernetes_namespace", + DiscoveryEnabled: DashboardsDiscoveryAuto, + DiscoveryAutoThreshold: 10, + Enabled: true, + NamespaceLabel: "kubernetes_namespace", }, Grafana: GrafanaConfig{ Auth: Auth{