CloudWatch: Fix deeplinks to still be able to pass log group names (#59809)

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
This commit is contained in:
Shirley 2022-12-07 17:40:15 +01:00 committed by GitHub
parent a4c884e808
commit 5c08f03512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -35,6 +35,7 @@ describe('addDataLinksToLogsResponse', () => {
refId: 'A',
expression: 'stats count(@message) by bin(1h)',
logGroupNames: ['fake-log-group-one', 'fake-log-group-two'],
logGroups: [{}], // empty log groups should be ignored and fall back to logGroupNames
region: 'us-east-1',
},
],
@ -115,6 +116,7 @@ describe('addDataLinksToLogsResponse', () => {
{
refId: 'A',
expression: 'stats count(@message) by bin(1h)',
logGroupNames: [''],
logGroups: [
{ value: 'arn:aws:logs:us-east-1:111111111111:log-group:/aws/lambda/test:*' },
{ value: 'arn:aws:logs:us-east-2:222222222222:log-group:/ecs/prometheus:*' },
@ -174,6 +176,7 @@ describe('addDataLinksToLogsResponse', () => {
{
refId: 'A',
expression: 'stats count(@message) by bin(1h)',
logGroupNames: [''],
logGroups: [{ value: 'arn:aws:logs:us-east-1:111111111111:log-group:/aws/lambda/test' }],
region: 'us-east-1',
} as CloudWatchQuery,

View File

@ -70,16 +70,13 @@ function createAwsConsoleLink(
replace: (target: string, fieldName?: string) => string,
getVariableValue: (value: string) => string[]
) {
const arns = target.logGroups?.flatMap((group) => {
if (group.value === undefined) {
return [];
}
return [group.value.replace(/:\*$/, '')]; // remove `:*` from end of arn
});
const logGroupNames = target.logGroupNames;
const sources = arns ?? logGroupNames;
const arns = (target.logGroups ?? [])
.filter((group) => group?.value)
.map((group) => (group.value ?? '').replace(/:\*$/, '')); // remove `:*` from end of arn
const logGroupNames = target.logGroupNames ?? [];
const sources = arns?.length ? arns : logGroupNames;
const interpolatedExpression = target.expression ? replace(target.expression) : '';
const interpolatedGroups = sources?.flatMap(getVariableValue) ?? [];
const interpolatedGroups = sources?.flatMap(getVariableValue);
const urlProps: AwsUrl = {
end: range.to.toISOString(),