-
Notifications
You must be signed in to change notification settings - Fork 513
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
[Bug] Version Comparison Bug in Related Integrations Field at Build Time #2331
[Bug] Version Comparison Bug in Related Integrations Field at Build Time #2331
Conversation
I also questioned why this did not fail for 8.4 or 8.5 branches and that is because the comparison returns Since the |
>>> Version("8.3") <= Version("8.3.0")
True
>>> Version("8.3.0") <= Version("8.3")
False
>>> Version("8.3.0") == Version("8.3")
False |
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.
Minor suggestions. Otherwise LGTM
Co-authored-by: Mika Ayenson <[email protected]>
Co-authored-by: Mika Ayenson <[email protected]>
Co-authored-by: Mika Ayenson <[email protected]>
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.
The bug was outside of the changes here, so I would roll most back, except L78. I added a comment for the actual bug.
Separate from this was another bug, where the manifests were not properly sorted before iterating.
rename:
- latest_major_integration_manifests = \
{k: v for k, v in integration_manifests.items() if Version(k)[0] == max_major}
+ integration_version = Version(int_ver)
Then sort before the loop:
- for version, manifest in latest_major_integration_manifests.items():
+ for version, manifest in sorted(integration_manifests_versions.items(), key=lambda x: tuple(x[0]), reverse=True):
Finally, I think it may be better to raise an error on the function rather than return None
On L93:
- print(f"no compatible version for integration {package}:{integration}")
- return None
+ raise ValueError(f"no compatible version for integration {package}:{integration} "
I may not understand fully how None
would be used, so could be wrong on the last one, but if it is always a validation error, it would be better to raise it here, closer to the issue
Thanks for the find! Yes the sorting was not being done on this but both implementations needed adjusted to properly sort them after testing. The following was implemented and tested.
|
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.
Small suggestions if it helps readability
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.
LGTM if it passes tests (I would iterate through a few branches to make sure)
Co-authored-by: Mika Ayenson <[email protected]>
Co-authored-by: Mika Ayenson <[email protected]>
Manual push to 8.3 -> https://github.com/elastic/detection-rules/actions/runs/3151885290 |
…ime (#2331) * addresses version comparison bug for related_integrations field during build * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * addressed package version loading bug * addressed flake errors * adjusted find_least_compatible_version function to address sorting and semantic version comparison * adjusted major version comparison in compare_versions sub function * removed compare_versions sub function and included logic in iteration * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * added OrderedDict to version and manifest iteration to enforce sorted dict object Co-authored-by: Mika Ayenson <[email protected]> (cherry picked from commit 4abd3b8)
…ime (#2331) * addresses version comparison bug for related_integrations field during build * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * addressed package version loading bug * addressed flake errors * adjusted find_least_compatible_version function to address sorting and semantic version comparison * adjusted major version comparison in compare_versions sub function * removed compare_versions sub function and included logic in iteration * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * added OrderedDict to version and manifest iteration to enforce sorted dict object Co-authored-by: Mika Ayenson <[email protected]> (cherry picked from commit 4abd3b8)
…ime (#2331) * addresses version comparison bug for related_integrations field during build * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * addressed package version loading bug * addressed flake errors * adjusted find_least_compatible_version function to address sorting and semantic version comparison * adjusted major version comparison in compare_versions sub function * removed compare_versions sub function and included logic in iteration * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * added OrderedDict to version and manifest iteration to enforce sorted dict object Co-authored-by: Mika Ayenson <[email protected]> (cherry picked from commit 4abd3b8)
…ime (#2331) * addresses version comparison bug for related_integrations field during build * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * addressed package version loading bug * addressed flake errors * adjusted find_least_compatible_version function to address sorting and semantic version comparison * adjusted major version comparison in compare_versions sub function * removed compare_versions sub function and included logic in iteration * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * added OrderedDict to version and manifest iteration to enforce sorted dict object Co-authored-by: Mika Ayenson <[email protected]> (cherry picked from commit 4abd3b8)
…ime (#2331) * addresses version comparison bug for related_integrations field during build * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * addressed package version loading bug * addressed flake errors * adjusted find_least_compatible_version function to address sorting and semantic version comparison * adjusted major version comparison in compare_versions sub function * removed compare_versions sub function and included logic in iteration * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * added OrderedDict to version and manifest iteration to enforce sorted dict object Co-authored-by: Mika Ayenson <[email protected]> (cherry picked from commit 4abd3b8)
…ime (#2331) * addresses version comparison bug for related_integrations field during build * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/misc.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * addressed package version loading bug * addressed flake errors * adjusted find_least_compatible_version function to address sorting and semantic version comparison * adjusted major version comparison in compare_versions sub function * removed compare_versions sub function and included logic in iteration * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * Update detection_rules/integrations.py Co-authored-by: Mika Ayenson <[email protected]> * added OrderedDict to version and manifest iteration to enforce sorted dict object Co-authored-by: Mika Ayenson <[email protected]> (cherry picked from commit 4abd3b8)
Summary
We recently merged a PR that adjusted how the
related_integrations
build-time field determined which integrations are valid. After checks passed and the PR was merged, we noticed a backport failure for the8.3
branch.During debugging, we noticed that the build time field for
related_integrations
did not have aversion
value set in the dictionary object, thus failing schema validation. The reason it did not have a version value was because of the comparison logic inintegrations.find_least_compatible_version.compare_versions
. L83 will compare the versions to ensure the integration version is less than or equal to the current stack version which is derived frompackages.yml
.Therefore it was doing this comparison logic with
8.3.0
(integration package) <=8.3
(package version) and ultimately returningFalse
which then assigned theversion
key a value ofNone
which does not comply with the schema.A closer inspection shows that the package version sources from L268 of
misc.py
.Solution
To solve this, we updated
misc.load_current_package_version
to have an argumentpatch
which is set toFalse
by default. IfTrue
, the package version will be given a default patch number of0
when returned.We then needed to update the call to this function from
_add_related_integrations
method inrule.py
so it calls the same function but passes the argumentpatch=True
.I then tested this by running
python -m view-rule /Users/tdejesus/code/src/detection-rules/rules/integrations/gcp/collection_gcp_pub_sub_subscription_creation.toml
where it failed before and no errors occurred as shown below.I also ran unit tests to ensure they passed as this is where the errors and build originally failed during backporting for the 8.3 branch and these were successful. Note, I did this from the 8.3 branch with the last commit of the PR merged prior to ensure the same error occurred before and after the solution implementation.