From 60b5e6ca9584d6f80ed318ff0dcb83d4a77222f7 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 9 Feb 2021 09:44:12 +0100 Subject: [PATCH] CloudMonitoring: Prevent resource type variable function from crashing (#30901) * check if label response has resource type prop * use nullish coalescing operator --- .../cloud-monitoring/CloudMonitoringMetricFindQuery.ts | 2 +- .../cloud-monitoring/components/VariableQueryEditor.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts b/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts index bcc98d03bac..cbcd2a5152c 100644 --- a/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts +++ b/public/app/plugins/datasource/cloud-monitoring/CloudMonitoringMetricFindQuery.ts @@ -112,7 +112,7 @@ export default class CloudMonitoringMetricFindQuery { } const refId = 'handleResourceTypeQueryQueryType'; const labels = await this.datasource.getLabels(selectedMetricType, refId, projectName); - return labels['resource.type'].map(this.toFindQueryResult); + return labels['resource.type']?.map(this.toFindQueryResult) ?? []; } async handleAlignersQuery({ selectedMetricType, projectName }: CloudMonitoringVariableQuery) { diff --git a/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx index 72c0a76782e..53b139c5413 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/VariableQueryEditor.tsx @@ -150,7 +150,7 @@ export class CloudMonitoringVariableQueryEditor extends PureComponent this.onPropsChange()); } async onMetricTypeChange(metricType: string) { @@ -158,7 +158,7 @@ export class CloudMonitoringVariableQueryEditor extends PureComponent this.onPropsChange()); } onLabelKeyChange(labelKey: string) {