-
Notifications
You must be signed in to change notification settings - Fork 335
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
AlertMerger query optimizations #1030
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,10 @@ def _paginate(func, func_kwargs): | |
def rule_names(self): | ||
"""Find all of the distinct rule names in the table. | ||
|
||
@deprecated | ||
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. is this still used internally? I'd say, if not, just 86 it 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. It's used in a variety of places; as far as I can tell it's used in a lot of tests. My worry was it was used in a bunch of public methods, which other customers might be using... that said, I think it's a good idea cuz using this method is just not a good idea. I'll hunt down the references in a separate PR 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. Separate note: "just 86 it" 🤣 I watch too much food TV 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. YOU or I watch too much!? I worked in a restaurant 😛 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 just surprised I understood the kitchen jargon 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. LOL |
||
This method is deprecated due to requiring a full table scan prior to returning any | ||
records. | ||
|
||
Returns: | ||
set: Set of string rule names | ||
""" | ||
|
@@ -68,6 +72,36 @@ def rule_names(self): | |
} | ||
return set(item['RuleName'] for item in self._paginate(self._table.scan, kwargs)) | ||
|
||
def rule_names_generator(self): | ||
"""Returns a generator that yields unique rule_names of items on the table | ||
|
||
Each unique name is yielded only once. Additionally, because the names materialized over | ||
several paginated calls, it is not 100% guaranteed to return every possible rule_name on | ||
the Alert Table; if there are other operations that are writing items to the DynamoDB table, | ||
it is possible for certain names to get skipped. | ||
|
||
Returns: | ||
generator | ||
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. please include the type that the generator will yield |
||
""" | ||
kwargs = { | ||
'ProjectionExpression': 'RuleName', | ||
'Select': 'SPECIFIC_ATTRIBUTES', | ||
|
||
# It is acceptable to use inconsistent reads here to reduce read capacity units | ||
# consumed, as there is already no guarantee of consistent in the rule names due to | ||
# pagination. | ||
'ConsistentRead': False, | ||
} | ||
|
||
rule_names = set() | ||
for item in self._paginate(self._table.scan, kwargs): | ||
name = item['RuleName'] | ||
if name in rule_names: | ||
continue | ||
|
||
rule_names.add(name) | ||
yield name | ||
|
||
def get_alert_records(self, rule_name, alert_proc_timeout_sec): | ||
"""Find all alerts for the given rule which need to be dispatched to the alert processor. | ||
|
||
|
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.
omit the
alert_count
and use something like the following: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'll test this on my own but regardless—)
Does
enumerate
preserve the generator? It won't materialize the generator values up-front likelist
, right?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.
@Ryxias yep it will preserve the generator underneath
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.
@Ryxias
Output: