Skip to content
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

refact(RHINENG-15309): Refactor filtering logic related to custom staleness #2183

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kruai
Copy link
Collaborator

@kruai kruai commented Jan 14, 2025

Overview

This PR is being created to address RHINENG-15309.
The purpose of this PR is to simplify some things, but it also resolves an inconsistency with staleness_to_conditions, which is needed to unblock #2181.

  • Move ALL_STALENESS_STATES to config.py
  • Consolidate stale_timestamp filter functions
  • Move staleness_to_conditions and update_query_for_owner_id to db_filters.py, as they both generate DB filters
  • Resolve the inconsistency in staleness_to_conditions timestamp filtering functions. Some required host_type, and some did not.

PR Checklist

  • Keep PR title short, ideally under 72 characters
  • Descriptive comments provided in complex code blocks
  • Include raw query examples in the PR description, if adding/modifying SQL query
  • Tests: validate optimal/expected output
  • Tests: validate exceptions and failure scenarios
  • Tests: edge cases
  • Recovers or fails gracefully during potential resource outages (e.g. DB, Kafka)
  • Uses type hinting, if convenient
  • Documentation, if this PR changes the way other services interact with host inventory
  • Links to related PRs

Secure Coding Practices Documentation Reference

You can find documentation on this checklist here.

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

@kruai kruai requested a review from a team as a code owner January 14, 2025 17:22
@@ -12,6 +12,7 @@
PRODUCER_ACKS = {"0": 0, "1": 1, "all": "all"}

HOST_TYPES = ["edge", None]
ALL_STALENESS_STATES = ("fresh", "stale", "stale_warning")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a no possibility of checking "culled" state?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All I'm doing is moving this constant from host_repository.py to config.py, not changing any values. But no, we don't allow querying hosts that are in the culled state

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is needed so I filed RHINENG-15328.

@@ -170,6 +180,21 @@ def _staleness_filter(
return [or_(*staleness_conditions)]


def staleness_to_conditions(
staleness, staleness_states, host_type, timestamp_filter_func, omit_host_type_filter: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should stick with one name staleness_states or staleness_type? The caller calls it type but the argument uses states; unnecessary change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is retaining the same signature as what it had when it was in culling.py.
Also, I don't see staleness_type used anywhere; can you please point me to that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh it was staleness_types on line 206, 207, and 228 in lib/host_repository.py

api/filtering/db_filters.py Show resolved Hide resolved
Copy link
Contributor

@thearifismail thearifismail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants