-
Notifications
You must be signed in to change notification settings - Fork 573
fix: type hinting fixes and additional code checks #4790
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
base: main
Are you sure you want to change the base?
Conversation
Enhancement - GuidelinesThese guidelines serve as a reminder set of considerations when addressing adding a new schema feature to the code. Documentation and Context
Code Standards and Practices
Testing
Additional Schema Related Checks
|
detection_rules/etc/*/* @mikaayenson @eric-forte-elastic @terrancedejesus | ||
detection_rules/etc/packages.yaml @mikaayenson @eric-forte-elastic @traut | ||
detection_rules/etc/*.json @mikaayenson @eric-forte-elastic @traut | ||
detection_rules/etc/*/* @mikaayenson @eric-forte-elastic @traut |
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.
detection_rules/etc/*/* @mikaayenson @eric-forte-elastic @traut | |
detection_rules/etc/*/* @mikaayenson @eric-forte-elastic @traut | |
# exclude files from code owners | |
detection_rules/etc/non-ecs-schema.json |
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.
per our team discussion in the team sync today.
query += " | LIMIT 10" | ||
click.echo("No LIMIT detected in query. Added LIMIT 10 to truncate output.") | ||
return query | ||
|
||
def run_individual_query(self, query: str, wait_timeout: int): | ||
def run_individual_query(self, query: str, _: int): |
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.
🥂
@@ -65,13 +66,14 @@ def setUpClass(cls): | |||
except Exception as e: | |||
RULE_LOADER_FAIL = True | |||
RULE_LOADER_FAIL_MSG = str(e) | |||
raise |
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.
Is the message supposed to be rolled up instead of failing here?
config = '## Setup\n\n' | ||
beats_integration_pattern = config + 'The {} Fleet integration, Filebeat module, or similarly ' \ | ||
'structured data is required to be compatible with this rule.' | ||
config = "## Setup\n\n" |
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.
Should we just delete this test or is it a bug?
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.
TLDR I think we can delete this test.
I think the intent for this unittest.skip was similar to / the inverse of
@unittest.skipIf(PACKAGE_STACK_VERSION < Version("8.3.0"),
"Test only applicable to 8.3+ stacks regarding related integrations build time field.")
Which were both added in 2429 to address
In 8.3, we added new build-time fields to our rules, specifically required_fields,related_integrations,setup. This feature request focuses solely on the related_integrations field.
At this time to determine which integrations to build the integrations manifest file, we rely on the integrations folder to determine this and then reference these names in package-storage. For matching, we rely solely on event.dataset fields in these integration queries
The issue:
We do not include the endpoint integration to this integrations manifest. In addition, we cannot rely on event.dataset, we need to look for the logs-endpoint* index for this.
osquery_note_pattern = ( | ||
"> **Note**:\n> This investigation guide uses the [Osquery Markdown Plugin]" | ||
"(https://www.elastic.co/guide/en/security/current/invest-guide-run-osquery.html) " | ||
"introduced in Elastic Stack version 8.5.0. Older Elastic Stack versions will display " | ||
"unrendered Markdown in this guide." | ||
) | ||
invest_note_pattern = ( | ||
'> This investigation guide uses the [Investigate Markdown Plugin]' | ||
'(https://www.elastic.co/guide/en/security/current/interactive-investigation-guides.html)' | ||
' introduced in Elastic Stack version 8.8.0. Older Elastic Stack versions will display ' | ||
'unrendered Markdown in this guide.') | ||
"> This investigation guide uses the [Investigate Markdown Plugin]" | ||
"(https://www.elastic.co/guide/en/security/current/interactive-investigation-guides.html)" | ||
" introduced in Elastic Stack version 8.8.0. Older Elastic Stack versions will display " | ||
"unrendered Markdown in this guide." | ||
) |
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.
We should double check that when the transform occurs, its still formatted correctly.
print(f"Downloading beats {release_name}") | ||
response = requests.get(url) | ||
|
||
print(f"Downloaded {len(response.content) / 1024.0 / 1024.0:.2f} MB release.") | ||
|
||
fs = {} | ||
fs: dict[str, Any] = {} |
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.
should we type hint the parsed
field below
# def get_schema_from_eql(tree: eql.ast.BaseNode, beats: list, version: str = None) -> dict: | ||
# """Get a schema based on datasets and modules in an EQL AST.""" | ||
# datasets, modules = get_datasets_and_modules(tree) | ||
# return get_schema_from_datasets(beats, modules, datasets, version=version) |
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.
Unused?
suggested_path: Path = Path(DEFAULT_PREBUILT_RULES_DIRS[0]) / contents["name"] | ||
path = Path(path or input(f"File path for rule [{suggested_path}]: ") or suggested_path).resolve() |
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.
Seems a bit odd to type hint as Path when we explicitly set as a Path object. We also dont type hint the next field path
.
"""Format unit test names into expected format for direct calling.""" | ||
raw = [t.rsplit('.', maxsplit=2) for t in tests] | ||
formatted = [] | ||
raw = [t.rsplit(".", maxsplit=2) for t in tests] |
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.
raw = [t.rsplit(".", maxsplit=2) for t in tests] | |
raw: list[list[str]] = [t.rsplit(".", maxsplit=2) for t in tests] |
?
paths = [Path(c) for c in columns[1:]] | ||
return cls(columns[0], *paths) |
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.
Is there a way to clean this up?
worksheet.freeze_panes(1, 0) | ||
worksheet.set_column(0, 0, 25) | ||
worksheet.set_column(1, 1, 10) | ||
worksheet = self.add_worksheet("Summary") # type: ignore[reportUnknownMemberType] |
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.
Can we add this to the function # type: ignore[reportUnknownMemberType]
instead of inline.
"""Get schema for KQL.""" | ||
indexes = indexes or () | ||
converted = flatten_multi_fields(get_schema(version, name='ecs_flat')) | ||
indexes = indexes or [] |
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.
Curious as to why this was a tuple
|
Pull Request
Issue link(s):
Summary - What I changed
ruff
andpyright
checks in CI workflowpyright
has no complainsHow To Test
Checklist
bug
,enhancement
,schema
,maintenance
,Rule: New
,Rule: Deprecation
,Rule: Tuning
,Hunt: New
, orHunt: Tuning
so guidelines can be generatedmeta:rapid-merge
label if planning to merge within 24 hoursContributor checklist