Skip to content

Commit

Permalink
[v9.3.x] CloudWatch: Fix deeplinks to still be able to pass log group…
Browse files Browse the repository at this point in the history
… names (grafana#60216)

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



Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>

Co-authored-by: Shirley <4163034+fridgepoet@users.noreply.github.com>
  • Loading branch information
2 people authored and GuaYounesPW committed Feb 8, 2023
1 parent 55ae112 commit 1bc6e48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
Expand Down Expand Up @@ -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:*' },
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 6 additions & 9 deletions public/app/plugins/datasource/cloudwatch/utils/datalinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 1bc6e48

Please sign in to comment.