-
Notifications
You must be signed in to change notification settings - Fork 137
Allow a way to set filterName and filterPattern when creating a Subscription filter #224
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
Open
cmavromichalis
wants to merge
1
commit into
SumoLogic:main
Choose a base branch
from
cmavromichalis:subscription_filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,20 +77,20 @@ function filterNewLogGroups(event, logGroupRegex) { | |
| return IsTagMatchToLogGroup(tagMatcherForLogGroup, logGroupTags) | ||
| } | ||
|
|
||
| async function createSubscriptionFilter(lambdaLogGroupName, destinationArn, roleArn, additionalArgs) { | ||
| async function createSubscriptionFilter(lambdaLogGroupName, destinationArn, filterName, filterPattern, roleArn, additionalArgs) { | ||
| var params={}; | ||
| if (destinationArn.startsWith("arn:aws:lambda")) { | ||
| params = { | ||
| destinationArn: destinationArn, | ||
| filterName: 'SumoLGLBDFilter', | ||
| filterPattern: '', | ||
| filterName: filterName, | ||
| filterPattern: filterPattern, | ||
| logGroupName: lambdaLogGroupName | ||
| }; | ||
| } else { | ||
| params = { | ||
| destinationArn: destinationArn, | ||
| filterName: 'SumoLGLBDFilter', | ||
| filterPattern: '', | ||
| filterName: filterName, | ||
| filterPattern: filterPattern | ||
| logGroupName: lambdaLogGroupName, | ||
| roleArn: roleArn | ||
| }; | ||
|
|
@@ -112,14 +112,16 @@ async function subscribeExistingLogGroups(logGroups, retryCounter, additionalArg | |
| var logGroupRegex = validateRegex(process.env.LOG_GROUP_PATTERN); | ||
| console.log("logGroupRegexPattern: ", logGroupRegex); | ||
| var destinationArn = process.env.DESTINATION_ARN; | ||
| var filterName = process.env.FILTER_NAME | ||
| var filterPattern = process.env.FILTER_PATTERN | ||
| var roleArn = process.env.ROLE_ARN; | ||
| const failedLogGroupNames = []; | ||
| await logGroups.reduce(async (previousPromise, nextLogGroup) => { | ||
| await previousPromise; | ||
| const { logGroupName } = nextLogGroup; | ||
| let filterStatus = await filterExistingLogGroups(logGroupName, logGroupRegex); | ||
| if (filterStatus) { | ||
| return createSubscriptionFilter(logGroupName, destinationArn, roleArn, additionalArgs).catch(function (err) { | ||
| return createSubscriptionFilter(logGroupName, destinationArn, filterName, filterPattern, roleArn, additionalArgs).catch(function (err) { | ||
| if (err && err.message === "Rate exceeded") { | ||
| failedLogGroupNames.push({ logGroupName: logGroupName }); | ||
| } | ||
|
|
@@ -197,11 +199,13 @@ async function delay(ms) { | |
| async function processEvents(env, event, additionalArgs, errorHandler, retryCounter=0) { | ||
| var logGroupName = event.detail.requestParameters.logGroupName; | ||
| var logGroupRegex = validateRegex(env.LOG_GROUP_PATTERN); | ||
| var filterName = env.FILTER_NAME | ||
| var filterPattern = env.FILTER_PATTERN | ||
|
Comment on lines
+202
to
+203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if these should also be validated with validateRegex or validated a different way? |
||
| console.log("logGroupRegex: ", logGroupRegex); | ||
| if (filterNewLogGroups(event, logGroupRegex)) { | ||
| console.log("Subscribing: ", logGroupName, env.DESTINATION_ARN); | ||
| try { | ||
| await createSubscriptionFilter(logGroupName, env.DESTINATION_ARN, env.ROLE_ARN, additionalArgs); | ||
| await createSubscriptionFilter(logGroupName, env.DESTINATION_ARN, filterName, filterPattern, env.ROLE_ARN, additionalArgs); | ||
| } catch (err) { | ||
| errorHandler(err, "Error in Subscribing."); | ||
| if (err && err.message === "Rate exceeded" && retryCounter <= maxRetryCounter) { | ||
|
|
@@ -243,4 +247,4 @@ exports.handler = async function (event, context, callback) { | |
| } else { | ||
| await processEvents(process.env, event, additionalArgs, errorHandler); | ||
| } | ||
| }; | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if these should also be validated with validateRegex or validated a different way?