Skip to content

Commit

Permalink
check if a user can list apps before trying to fetch the monitoring a…
Browse files Browse the repository at this point in the history
…pp (rancher#9826)
  • Loading branch information
mantis-toboggan-md authored Oct 6, 2023
1 parent 63d6ffd commit 702c54e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
14 changes: 8 additions & 6 deletions shell/components/AlertTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ export default {
},
async fetchDeps() {
try {
const am = await this.$store.dispatch('cluster/find', { type: ENDPOINTS, id: `${ this.monitoringNamespace }/${ this.alertServiceEndpoint }` });
if (this.$store.getters['cluster/canList'](ENDPOINTS)) {
try {
const am = await this.$store.dispatch('cluster/find', { type: ENDPOINTS, id: `${ this.monitoringNamespace }/${ this.alertServiceEndpoint }` });
if (!isEmpty(am) && !isEmpty(am.subsets)) {
this.alertManagerPoller.start();
}
} catch {
if (!isEmpty(am) && !isEmpty(am.subsets)) {
this.alertManagerPoller.start();
}
} catch {
}
}
},
}
Expand Down
14 changes: 12 additions & 2 deletions shell/components/EtcdInfoBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@ export default {
components: { Banner, Loading },
async fetch() {
const inStore = this.$store.getters['currentProduct'].inStore;
const res = await this.$store.dispatch(`${ inStore }/find`, { type: CATALOG.APP, id: 'cattle-monitoring-system/rancher-monitoring' });
const monitoringVersion = res?.currentVersion;
let monitoringVersion = '';
if (this.$store.getters[`${ inStore }/canList}`](CATALOG.APP)) {
try {
const res = await this.$store.dispatch(`${ inStore }/find`, { type: CATALOG.APP, id: 'cattle-monitoring-system/rancher-monitoring' });
monitoringVersion = res?.currentVersion;
} catch (err) {
}
}
const leader = await hasLeader(monitoringVersion, this.$store.dispatch, this.currentCluster.id);
this.hasLeader = leader ? this.t('generic.yes') : this.t('generic.no');
Expand Down
11 changes: 8 additions & 3 deletions shell/components/GrafanaDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ export default {
},
async fetch() {
const inStore = this.$store.getters['currentProduct'].inStore;
const res = await this.$store.dispatch(`${ inStore }/find`, { type: CATALOG.APP, id: 'cattle-monitoring-system/rancher-monitoring' });
this.monitoringVersion = res?.currentVersion;
if (this.$store.getters[`${ inStore }/canList`](CATALOG.APP)) {
try {
const res = await this.$store.dispatch(`${ inStore }/find`, { type: CATALOG.APP, id: 'cattle-monitoring-system/rancher-monitoring' });
this.monitoringVersion = res?.currentVersion;
} catch (err) {}
}
},
data() {
return {
loading: false, error: false, interval: null, errorTimer: null, monitoringVersion: null
loading: false, error: false, interval: null, errorTimer: null, monitoringVersion: ''
};
},
computed: {
Expand Down
23 changes: 14 additions & 9 deletions shell/pages/c/_cluster/monitoring/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ export default {
const { $store, externalLinks } = this;
this.v1Installed = await haveV1MonitoringWorkloads($store);
const hash = await allHash({
apps: $store.dispatch('cluster/findAll', { type: CATALOG.APP }),
endpoints: $store.dispatch('cluster/findAll', { type: ENDPOINTS }),
});
const hash = {};
if (!isEmpty(hash.endpoints)) {
if ($store.getters['cluster/canList'](CATALOG.APP)) {
hash.apps = $store.dispatch('cluster/findAll', { type: CATALOG.APP });
}
if ($store.getters['cluster/schemaFor'](ENDPOINTS)) {
hash.endpoints = $store.dispatch('cluster/findAll', { type: ENDPOINTS });
}
const res = await allHash(hash);
if (res.endpoints && !isEmpty(res.endpoints)) {
const amMatch = findBy(externalLinks, 'group', 'alertmanager');
const grafanaMatch = findBy(externalLinks, 'group', 'grafana');
const promeMatch = externalLinks.filter(
Expand All @@ -110,23 +115,23 @@ export default {
// Generate Grafana link
const currentCluster = this.$store.getters['currentCluster'];
const rancherMonitoring = !isEmpty(hash.apps) ? findBy(hash.apps, 'id', 'cattle-monitoring-system/rancher-monitoring') : '';
const rancherMonitoring = !isEmpty(res.apps) ? findBy(res.apps, 'id', 'cattle-monitoring-system/rancher-monitoring') : '';
const clusterPrefix = getClusterPrefix(rancherMonitoring?.currentVersion || '', currentCluster.id);
grafanaMatch.link = `${ clusterPrefix }/api/v1/namespaces/cattle-monitoring-system/services/http:rancher-monitoring-grafana:80/proxy/`;
const alertmanager = findBy(
hash.endpoints,
res.endpoints,
'id',
`${ CATTLE_MONITORING_NAMESPACE }/rancher-monitoring-alertmanager`
);
const grafana = findBy(
hash.endpoints,
res.endpoints,
'id',
`${ CATTLE_MONITORING_NAMESPACE }/rancher-monitoring-grafana`
);
const prometheus = findBy(
hash.endpoints,
res.endpoints,
'id',
`${ CATTLE_MONITORING_NAMESPACE }/rancher-monitoring-prometheus`
);
Expand Down
3 changes: 1 addition & 2 deletions shell/utils/grafana.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ export async function allDashboardsExist(store, clusterId, embeddedUrls, storeNa

let monitoringVersion = '';

if (!projectId) {
if (!projectId && store.getters[`${ storeName }/canList`](CATALOG.APP)) {
try {
res = await store.dispatch(`${ storeName }/find`, {
type: CATALOG.APP,
id: 'cattle-monitoring-system/rancher-monitoring'
});
} catch (err) {
return false;
}

monitoringVersion = res?.currentVersion;
Expand Down

0 comments on commit 702c54e

Please sign in to comment.