From faa68920aabbf87996868d25d9434ddbbff67922 Mon Sep 17 00:00:00 2001 From: Aashish Sharma Date: Fri, 31 May 2024 01:32:35 +0530 Subject: [PATCH] mgr/dashboard: fix context switcher and multi-cluster add cluster feature In multi-cluster dashboard, fix CORS error on switching the context switcher and allow to add more than one clusters in prometheus federation Fixes: https://tracker.ceph.com/issues/66307 Signed-off-by: Aashish Sharma --- src/pybind/mgr/cephadm/module.py | 2 ++ .../templates/services/prometheus/prometheus.yml.j2 | 2 +- .../mgr/dashboard/controllers/multi_cluster.py | 12 +++++++----- .../cluster/multi-cluster/multi-cluster.component.ts | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 03230f1a2df..2314b853b7e 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -3194,6 +3194,8 @@ Then run the following: @handle_orch_error def get_prometheus_cert(self) -> str: prometheus_cert = self.get_store(PrometheusService.PROMETHEUS_CERT_CFG_KEY) + if prometheus_cert is None: + prometheus_cert = '' return prometheus_cert @handle_orch_error diff --git a/src/pybind/mgr/cephadm/templates/services/prometheus/prometheus.yml.j2 b/src/pybind/mgr/cephadm/templates/services/prometheus/prometheus.yml.j2 index f45328efb6d..83f603c2d6e 100644 --- a/src/pybind/mgr/cephadm/templates/services/prometheus/prometheus.yml.j2 +++ b/src/pybind/mgr/cephadm/templates/services/prometheus/prometheus.yml.j2 @@ -196,7 +196,7 @@ scrape_configs: {% endif %} {% for url, details in clusters_credentials.items() %} - - job_name: 'federate' + - job_name: 'federate_{{ loop.index }}' scrape_interval: 15s honor_labels: true metrics_path: '/federate' diff --git a/src/pybind/mgr/dashboard/controllers/multi_cluster.py b/src/pybind/mgr/dashboard/controllers/multi_cluster.py index 4d97ddd29e1..753914949be 100644 --- a/src/pybind/mgr/dashboard/controllers/multi_cluster.py +++ b/src/pybind/mgr/dashboard/controllers/multi_cluster.py @@ -248,7 +248,7 @@ class MultiCluster(RESTController): multicluster_config.update({'current_url': config['url']}) multicluster_config.update({'current_user': config['user']}) Settings.MULTICLUSTER_CONFIG = json.dumps(multicluster_config) - return Settings.MULTICLUSTER_CONFIG + return multicluster_config @Endpoint('PUT') @UpdatePermission @@ -268,11 +268,13 @@ class MultiCluster(RESTController): 'reconnect') prometheus_url = self._proxy('GET', url, 'api/multi-cluster/get_prometheus_api_url', - token=cluster_token) + token=cluster_token, verify=ssl_verify, + cert=ssl_certificate) prometheus_access_info = self._proxy('GET', url, 'ui-api/multi-cluster/get_prometheus_access_info', # noqa E501 #pylint: disable=line-too-long - token=cluster_token) + token=cluster_token, verify=ssl_verify, + cert=ssl_certificate) if username and cluster_token and prometheus_url and prometheus_access_info: if "config" in multicluster_config: @@ -303,7 +305,7 @@ class MultiCluster(RESTController): cluster['ssl_verify'] = verify cluster['ssl_certificate'] = ssl_certificate if verify else '' Settings.MULTICLUSTER_CONFIG = json.dumps(multicluster_config) - return Settings.MULTICLUSTER_CONFIG + return multicluster_config @Endpoint(method='DELETE') @DeletePermission @@ -343,7 +345,7 @@ class MultiCluster(RESTController): break Settings.MULTICLUSTER_CONFIG = json.dumps(multicluster_config) - return Settings.MULTICLUSTER_CONFIG + return multicluster_config @Endpoint() @ReadPermission diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts index dc13d4c09ff..229666c9a6b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/multi-cluster/multi-cluster.component.ts @@ -326,7 +326,7 @@ export class MultiClusterComponent implements OnInit, OnDestroy { } const clusters: ClusterInfo[] = []; - this.queriesResults.TOTAL_CAPACITY?.forEach((totalCapacityMetric: any) => { + this.queriesResults.TOTAL_CAPACITY?.forEach((totalCapacityMetric: any, index:number) => { const clusterName = totalCapacityMetric.metric.cluster; const totalCapacity = parseInt(totalCapacityMetric.value[1]); const getMgrMetadata = this.findCluster(this.queriesResults?.MGR_METADATA, clusterName); @@ -339,8 +339,9 @@ export class MultiClusterComponent implements OnInit, OnDestroy { const osds = this.findClusterData(this.queriesResults?.OSDS, clusterName); const status = this.findClusterData(this.queriesResults?.HEALTH_STATUS, clusterName); const available_capacity = totalCapacity - usedCapacity; + const federateJobName = `federate_${index + 1}`; const federateMetrics = this.queriesResults?.FEDERATE_UP_METRIC.filter( - (metric: any) => metric.metric.job === 'federate' + (metric: any) => metric.metric.job === federateJobName ); this.checkFederateMetricsStatus(federateMetrics); -- 2.47.3