Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subscription filters #1172

Merged
merged 5 commits into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ async function centralLoggingSubscription(event: CloudFormationCustomResourceEve
await Promise.all(
filterLogGroups.map(async logGroup => {
// Get Subscription filter and remove
const filterName = `${CloudWatchRulePrefix}${logGroup.logGroupName}`;
const subscriptinFilters = await getSubscriptionFilters(logGroup.logGroupName!);
if (subscriptinFilters && subscriptinFilters.length > 0) {
// Remove existing Subscription filters
for (const subscriptinFilter of subscriptinFilters) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName!);
if (subscriptinFilter.filterName === filterName) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName);
}
}
}
// Change Log Retention for Log Group
Expand All @@ -121,22 +124,16 @@ async function centralLoggingSubscriptionUpdate(event: CloudFormationCustomResou
const logGroups = await getLogGroups();
const filterLogGroups = logGroups.filter(lg => !isExcluded(globalExclusions, lg.logGroupName!));

await Promise.all(
logGroups.map(async logGroup => {
// Remove "PBMM-" Subscription filter from all log Groups if exists on update
const filterName = `${CloudWatchRulePrefix}${logGroup.logGroupName}`;
await removeSubscriptionFilter(logGroup.logGroupName!, filterName);
}),
);

await Promise.all(
filterLogGroups.map(async logGroup => {
// Get Subscription filter and remove
const subscriptinFilters = await getSubscriptionFilters(logGroup.logGroupName!);
const filterName = `${CloudWatchRulePrefix}${logGroup.logGroupName}`;
if (subscriptinFilters && subscriptinFilters.length > 0) {
// Remove existing Subscription filters
for (const subscriptinFilter of subscriptinFilters) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName!);
if (subscriptinFilter.filterName === filterName) {
await removeSubscriptionFilter(logGroup.logGroupName!, subscriptinFilter.filterName);
}
}
}
// Change Log Retention for Log Group
Expand Down