-
Notifications
You must be signed in to change notification settings - Fork 82
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
(RHINENG-12028): serialize_host refactoring #2240
(RHINENG-12028): serialize_host refactoring #2240
Conversation
89b4136
to
524217f
Compare
3c5f7e1
to
daad157
Compare
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, just need the get_staleness_timestamps
to be moved to global scope.
I agree with @jpramos123's comments, but I think the code looks good beyond that. Good work! |
LGTM to except the moving of |
Thanks @thearifismail, @kruai, and @jpramos123 for your comments. I'll address that asap. |
daad157
to
c752431
Compare
c752431
to
6220f6b
Compare
/retest |
6220f6b
to
700ebd7
Compare
Issues identified: Repetitive staleness calculation: * The stale_timestamp, stale_warning_timestamp, and culled_timestamp assignments are redundant for edge and conventional hosts. * We should extract this logic into a helper function. Field processing in a long if-else chain: * The current approach of checking each field separately makes it harder to read. * Using a dictionary comprehension may make it cleaner. Unused arguments (additional_fields defaulted to tuple()): * We should use None as a default, and convert it to a tuple inside the function. Better separation of concerns: * Extract helper functions to make the serialize_host function more modular. Improvements Proposal: Encapsulating the staleness calculation: * Extracting the calculation into a get_staleness_timestamps() helper function to avoid duplicate logic. Reducing repetitive "if" Checks: * By using a dictionary field_mapping to map field names to their corresponding serialization logic. * By doing this, we eliminate long "if" chains, making it cleaner and easier to modify. Optimizing System Profile management: * By using a dictionary comprehension to filter system_profile_facts efficiently. Improving readability and Maintainability: * By bringing a better logical separation of concerns. * By bringing an easier way to extend the host data (we just need to modify the field_mapping and add/remove fields). Signed-off-by: Gaël Chamoulaud <[email protected]> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
700ebd7
to
7d4e3a7
Compare
Overview
This PR is being created to address RHINENG-12028.
See my comment with all the explanations about this refactoring and improvements that can be done, in the Jira ticket above or in the commit message.
PR Checklist
Secure Coding Practices Documentation Reference
You can find documentation on this checklist here.
Secure Coding Checklist