From ae64dcf0638e1b860dd3e56cdd97abb7c90833c0 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Mon, 8 Feb 2021 07:51:31 +0100 Subject: [PATCH] make sure service and slo display name is passed to segment comp (#30900) --- .../cloud-monitoring/components/SLOQueryEditor.tsx | 14 +++++++++----- .../datasource/cloud-monitoring/datasource.ts | 4 ++-- .../plugins/datasource/cloud-monitoring/types.ts | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx b/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx index e567da2abd0..d4238b52860 100644 --- a/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx +++ b/public/app/plugins/datasource/cloud-monitoring/components/SLOQueryEditor.tsx @@ -21,7 +21,9 @@ export const defaultQuery: (dataSource: CloudMonitoringDatasource) => SLOQuery = aliasBy: '', selectorName: 'select_slo_health', serviceId: '', + serviceName: '', sloId: '', + sloName: '', }); export function SLOQueryEditor({ @@ -42,7 +44,7 @@ export function SLOQueryEditor({ datasource.getSLOServices(query.projectName).then((services) => [ @@ -53,14 +55,16 @@ export function SLOQueryEditor({ ...services, ]) } - onChange={({ value: serviceId = '' }) => onChange({ ...query, serviceId, sloId: '' })} + onChange={({ value: serviceId = '', label: serviceName = '' }) => + onChange({ ...query, serviceId, serviceName, sloId: '' }) + } /> datasource.getServiceLevelObjectives(query.projectName, query.serviceId).then((sloIds) => [ @@ -71,10 +75,10 @@ export function SLOQueryEditor({ ...sloIds, ]) } - onChange={async ({ value: sloId = '' }) => { + onChange={async ({ value: sloId = '', label: sloName = '' }) => { const slos = await datasource.getServiceLevelObjectives(query.projectName, query.serviceId); const slo = slos.find(({ value }) => value === datasource.templateSrv.replace(sloId)); - onChange({ ...query, sloId, goal: slo?.goal }); + onChange({ ...query, sloId, sloName, goal: slo?.goal }); }} /> diff --git a/public/app/plugins/datasource/cloud-monitoring/datasource.ts b/public/app/plugins/datasource/cloud-monitoring/datasource.ts index 63ef0db86c7..41bc91442ff 100644 --- a/public/app/plugins/datasource/cloud-monitoring/datasource.ts +++ b/public/app/plugins/datasource/cloud-monitoring/datasource.ts @@ -257,9 +257,9 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend< async getSLOServices(projectName: string): Promise>> { return this.api.get(`${this.templateSrv.replace(projectName)}/services?pageSize=1000`, { - responseMap: ({ name }: { name: string }) => ({ + responseMap: ({ name, displayName }: { name: string; displayName: string }) => ({ value: name.match(/([^\/]*)\/*$/)![1], - label: name.match(/([^\/]*)\/*$/)![1], + label: displayName || name.match(/([^\/]*)\/*$/)![1], }), }); } diff --git a/public/app/plugins/datasource/cloud-monitoring/types.ts b/public/app/plugins/datasource/cloud-monitoring/types.ts index fb934837c0d..613ae864be8 100644 --- a/public/app/plugins/datasource/cloud-monitoring/types.ts +++ b/public/app/plugins/datasource/cloud-monitoring/types.ts @@ -92,7 +92,9 @@ export interface SLOQuery { aliasBy?: string; selectorName: string; serviceId: string; + serviceName: string; sloId: string; + sloName: string; goal?: number; }