The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/cloudwatch/utils/datalinks.test.ts

95 lines
2.5 KiB

import { DataQueryResponse, dateMath } from '@grafana/data';
import { addDataLinksToLogsResponse } from './datalinks';
import { setDataSourceSrv } from '@grafana/runtime';
describe('addDataLinksToLogsResponse', () => {
it('should add data links to response', async () => {
const mockResponse: DataQueryResponse = {
data: [
{
fields: [
{
name: '@message',
config: {},
},
{
name: '@xrayTraceId',
config: {},
},
],
refId: 'A',
},
],
};
const mockOptions: any = {
targets: [
{
refId: 'A',
expression: 'stats count(@message) by bin(1h)',
logGroupNames: ['fake-log-group-one', 'fake-log-group-two'],
region: 'us-east-1',
},
],
};
const time = {
from: dateMath.parse('2016-12-31 15:00:00Z', false)!,
to: dateMath.parse('2016-12-31 16:00:00Z', false)!,
};
setDataSourceSrv({
async get() {
return {
name: 'Xray',
};
},
} as any);
await addDataLinksToLogsResponse(
mockResponse,
mockOptions,
{ ...time, raw: time },
(s) => s ?? '',
(r) => r,
'xrayUid'
);
expect(mockResponse).toMatchObject({
data: [
{
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',
config: {
links: [
{
url: '',
title: 'Xray',
internal: {
query: { query: '${__value.raw}', region: 'us-east-1', queryType: 'getTrace' },
datasourceUid: 'xrayUid',
datasourceName: 'Xray',
},
},
],
},
},
],
refId: 'A',
},
],
});
});
});