Skip to content

Conversation

@rodrigonull
Copy link
Member

@rodrigonull rodrigonull commented Nov 18, 2025

Overview

This PR is being created to address RHINENG-22144.

Depends on: #3108

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

Summary by Sourcery

Migrate host inventory code to use normalized system_profile_static and system_profile_dynamic tables and dedicated canonical fact columns, replace JSONB serialization for canonical_facts and system_profile_facts, introduce host_type as a denormalized column with database trigger, and update serialization, query, filtering, event header, and tests accordingly

New Features:

  • Add separate Host model columns for insights_id, subscription_manager_id, satellite_id, fqdn, bios_uuid, ip_addresses, mac_addresses, provider_id, and provider_type
  • Introduce host_type denormalized column on hosts table with migration and trigger to derive its value from static system profile data
  • Implement utilities for normalized system profile handling (_build_system_profile_from_normalized and extract_system_profile_fields_for_headers)

Enhancements:

  • Refactor serialize_host and related serialization functions to use the new canonical fact columns and normalized static/dynamic system profile relationships instead of JSONB blobs
  • Optimize host queries to defer legacy JSONB columns and conditionally join normalized system profile tables based on requested fields
  • Replace the old _serialize_uuid helper with serialize_uuid and update event header generation across queues and APIs to include individual canonical facts and system profile fields
  • Simplify db_filters to use Host.host_type directly and switch to outerjoin for model relationships

Tests:

  • Add test fixtures to create database triggers for host_type synchronization
  • Update existing tests to expect direct canonical fields, use serialize_uuid, and mark legacy workload compatibility tests as xfail

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 18, 2025

Reviewer's Guide

This PR migrates system profile handling from a JSONB blob to normalized static and dynamic tables (with a helper to assemble them), extends canonical facts with new fields and standardizes UUID serialization, introduces a denormalized host_type column (backed by a trigger) and updates filtering and event header logic to leverage these changes.

Sequence diagram for event header generation using normalized system profile

sequenceDiagram
    participant Host
    participant HostStaticSystemProfile
    participant EventProducer
    Host->>HostStaticSystemProfile: Access static_system_profile
    HostStaticSystemProfile-->>Host: Provide host_type, operating_system, bootc_status
    Host->>EventProducer: Pass extracted fields for event header
    EventProducer->>EventProducer: Build event header with host_type, os_name, bootc_booted
Loading

Entity relationship diagram for new system_profile_* tables and host_type sync

erDiagram
    HOSTS ||--o| SYSTEM_PROFILES_STATIC : has
    HOSTS ||--o| SYSTEM_PROFILES_DYNAMIC : has
    SYSTEM_PROFILES_STATIC {
        UUID host_id
        VARCHAR(50) host_type
        JSONB bootc_status
        JSONB operating_system
    }
    SYSTEM_PROFILES_DYNAMIC {
        UUID host_id
        DATETIME captured_date
    }
    HOSTS {
        UUID id
        VARCHAR(50) host_type
    }
Loading

Class diagram for updated Host model and system profile handling

classDiagram
    class Host {
        +UUID id
        +String account
        +String org_id
        +String display_name
        +String ansible_host
        +UUID insights_id
        +UUID subscription_manager_id
        +String satellite_id
        +String fqdn
        +String bios_uuid
        +List ip_addresses
        +List mac_addresses
        +String provider_id
        +String provider_type
        +UUID openshift_cluster_id
        +String host_type
        +JSONB system_profile_facts
        +List groups
        +DateTime last_check_in
        +HostStaticSystemProfile static_system_profile
        +HostDynamicSystemProfile dynamic_system_profile
        +update(input_host, update_system_profile)
        +operating_system()
        +_add_or_update_normalized_system_profiles(input_system_profile)
    }
    class HostStaticSystemProfile {
        +UUID host_id
        +String host_type
        +JSONB bootc_status
        +JSONB operating_system
        ...
    }
    class HostDynamicSystemProfile {
        +UUID host_id
        +DateTime captured_date
        ...
    }
    Host "1" -- "1" HostStaticSystemProfile : static_system_profile
    Host "1" -- "1" HostDynamicSystemProfile : dynamic_system_profile
Loading

File-Level Changes

Change Details Files
Normalize system_profile serialization
  • Add _build_system_profile_from_normalized to assemble profile from static/dynamic tables
  • Replace direct JSONB system_profile_facts access in serialize_host, serialize_host_for_export_svc and serialize_host_system_profile
  • Update tests to mock and expect normalized system_profile usage
app/serialization.py
tests/fixtures/app_fixtures.py
tests/test_host_mq_service.py
tests/test_unit.py
Refactor UUID serialization and expand canonical_facts fields
  • Rename _serialize_uuid to serialize_uuid and update all call sites
  • Add new canonical_facts fields (insights_id, subscription_manager_id, satellite_id, fqdn, bios_uuid, ip_addresses, mac_addresses, provider_id, provider_type) in serialization and message headers
  • Adjust tests and helper utilities to assert new fields and use serialize_uuid
app/serialization.py
app/queue/events.py
app/queue/host_mq.py
lib/outbox_repository.py
tests/helpers/mq_utils.py
tests/test_unit.py
Introduce host_type column with sync trigger and adjust filtering
  • Add alembic migration to add host_type to hosts with a trigger syncing from system_profiles_static
  • Denormalize host_type in Host model and remove JSONB-derived property
  • Revise SYSTEM_TYPE_FILTERS and query logic in db_filters and host_query_db to use Host.host_type directly
migrations/versions/abc123def456_add_host_type_to_hosts_table.py
app/models/host.py
api/filtering/db_filters.py
api/host_query_db.py
tests/test_api_hosts_get.py
Update event header construction for normalized system_profile fields
  • Add extract_system_profile_fields_for_headers helper to pull host_type, operating_system and bootc_booted
  • Replace system_profile_facts header extraction with static_system_profile fields across host_mq, events, API endpoints, group_repository and host_synchronize
  • Ensure headers include correct flags for bootc_booted and OS
app/queue/events.py
app/queue/host_mq.py
app/api/host.py
lib/group_repository.py
lib/host_synchronize.py
api/staleness.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@rodrigonull rodrigonull force-pushed the RHINENG-22144 branch 3 times, most recently from f7c2afd to 5ce3fa6 Compare November 27, 2025 14:42
@rodrigonull rodrigonull force-pushed the RHINENG-22144 branch 3 times, most recently from 3b13910 to 94001c1 Compare November 28, 2025 16:34
@rodrigonull
Copy link
Member Author

/retest

@jpramos123 jpramos123 force-pushed the RHINENG-22144 branch 2 times, most recently from 37edccc to 2d801a8 Compare December 2, 2025 20:07
rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
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.

3 participants