diff --git a/public/app/plugins/datasource/cloudwatch/datasource.test.ts b/public/app/plugins/datasource/cloudwatch/datasource.test.ts index f70b15f9caa..dc15557ee8a 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.test.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.test.ts @@ -306,7 +306,7 @@ describe('datasource', () => { }); }); - it('should add links to log queries', async () => { + it('should add a data link field to log queries', async () => { const { datasource } = setupForLogs(); const observable = datasource.query({ @@ -344,7 +344,7 @@ describe('datasource', () => { }, ]); - expect(emits[0].data[0].fields.find((f: Field) => f.name === '@message').config.links).toMatchObject([ + expect(emits[0].data[0].fields.find((f: Field) => f.name === '').config.links).toMatchObject([ { title: 'View in CloudWatch console', url: "https://us-west-1.console.aws.amazon.com/cloudwatch/home?region=us-west-1#logs-insights:queryDetail=~(end~'2016-12-31T16*3a00*3a00.000Z~start~'2016-12-31T15*3a00*3a00.000Z~timeType~'ABSOLUTE~tz~'UTC~editorString~'some*20query~isLiveTail~false~source~(~'test))", diff --git a/public/app/plugins/datasource/cloudwatch/utils/datalinks.test.ts b/public/app/plugins/datasource/cloudwatch/utils/datalinks.test.ts index 4be2304940a..e5762640d59 100644 --- a/public/app/plugins/datasource/cloudwatch/utils/datalinks.test.ts +++ b/public/app/plugins/datasource/cloudwatch/utils/datalinks.test.ts @@ -1,4 +1,4 @@ -import { DataQueryRequest, DataQueryResponse, dateMath } from '@grafana/data'; +import { DataQueryRequest, DataQueryResponse, dateMath, FieldType } from '@grafana/data'; import { setDataSourceSrv } from '@grafana/runtime'; import { DatasourceSrv } from 'app/features/plugins/datasource_srv'; @@ -19,10 +19,12 @@ describe('addDataLinksToLogsResponse', () => { { name: '@message', config: {}, + values: ['log message one', 'log message two'], }, { name: '@xrayTraceId', config: {}, + values: ['id1', 'id2'], }, ], refId: 'A', @@ -65,14 +67,6 @@ describe('addDataLinksToLogsResponse', () => { fields: [ { name: '@message', - config: { - links: [ - { - url: "https://us-east-1.console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs-insights:queryDetail=~(end~'2016-12-31T16*3a00*3a00.000Z~start~'2016-12-31T15*3a00*3a00.000Z~timeType~'ABSOLUTE~tz~'UTC~editorString~'stats*20count*28*40message*29*20by*20bin*281h*29~isLiveTail~false~source~(~'fake-log-group-one~'fake-log-group-two))", - title: 'View in CloudWatch console', - }, - ], - }, }, { name: '@xrayTraceId', @@ -90,6 +84,19 @@ describe('addDataLinksToLogsResponse', () => { ], }, }, + { + name: '', + type: FieldType.string, + values: ['View this query in CloudWatch console', 'View this query in CloudWatch console'], + config: { + links: [ + { + url: "https://us-east-1.console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs-insights:queryDetail=~(end~'2016-12-31T16*3a00*3a00.000Z~start~'2016-12-31T15*3a00*3a00.000Z~timeType~'ABSOLUTE~tz~'UTC~editorString~'stats*20count*28*40message*29*20by*20bin*281h*29~isLiveTail~false~source~(~'fake-log-group-one~'fake-log-group-two))", + title: 'View in CloudWatch console', + }, + ], + }, + }, ], refId: 'A', }, @@ -97,7 +104,7 @@ describe('addDataLinksToLogsResponse', () => { }); }); - it('should add data links to response from log groups, trimming :*', async () => { + it('should add a data link field to response from log groups, trimming :*', async () => { const mockResponse: DataQueryResponse = { data: [ { @@ -141,6 +148,11 @@ describe('addDataLinksToLogsResponse', () => { fields: [ { name: '@message', + }, + { + name: '', + type: FieldType.string, + values: [], config: { links: [ { @@ -198,6 +210,11 @@ describe('addDataLinksToLogsResponse', () => { fields: [ { name: '@message', + }, + { + name: '', + type: FieldType.string, + values: [], config: { links: [ { diff --git a/public/app/plugins/datasource/cloudwatch/utils/datalinks.ts b/public/app/plugins/datasource/cloudwatch/utils/datalinks.ts index 8f7c5c38827..e69ae4e4e17 100644 --- a/public/app/plugins/datasource/cloudwatch/utils/datalinks.ts +++ b/public/app/plugins/datasource/cloudwatch/utils/datalinks.ts @@ -1,4 +1,12 @@ -import { DataFrame, DataLink, DataQueryRequest, DataQueryResponse, ScopedVars, TimeRange } from '@grafana/data'; +import { + DataFrame, + DataLink, + DataQueryRequest, + DataQueryResponse, + FieldType, + ScopedVars, + TimeRange, +} from '@grafana/data'; import { getDataSourceSrv } from '@grafana/runtime'; import { AwsUrl, encodeUrl } from '../aws_url'; @@ -33,14 +41,22 @@ export async function addDataLinksToLogsResponse( if (xrayLink) { field.config.links = [xrayLink]; } - } else { - // Right now we add generic link to open the query in xray console to every field so it shows in the logs row - // details. Unfortunately this also creates link for all values inside table which look weird. - field.config.links = [ - createAwsConsoleLink(curTarget, request.range, interpolatedRegion, replace, getVariableValue), - ]; } } + + // add a link to the cloudwatch console as a separate field that will be displayed as a link + if (dataFrame.fields.length) { + dataFrame.fields.push({ + name: '', + type: FieldType.string, + values: dataFrame.fields[0]?.values?.length + ? new Array(dataFrame.fields[0].values.length).fill('View this query in CloudWatch console') + : [], + config: { + links: [createAwsConsoleLink(curTarget, request.range, interpolatedRegion, replace, getVariableValue)], + }, + }); + } } }