Uploaded image for project: 'Subscription Watch'
  1. Subscription Watch
  2. SWATCH-3931

Build SQL Query Foundation for "Get Hosts From Events" Processing

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Normal Normal
    • None
    • None
    • None
    • True
    • Hide

      None

      Show
      None
    • False

      Context
      This is a precursor card to front-load the complex SQL work before implementing the main "get hosts from events" functionality. The SQL queries will be tricky to implement efficiently, so we want to solve this complexity upfront.

      This card builds the SQL foundation for the future host update processing that will replace direct HBI database queries with event-based processing.

      Acceptance Criteria

      • Event Selection Query: SQL to select events where tallyStateSaysSo AND HBI sourced for org AND service_type = hbi_host
      • Host Matching Query: SQL to select hosts that match those instances from the event selection
      • Multi-Table Updates: Prepare for upsert operations on hosts, instance_measurements, and buckets tables
      • Delete Event Handling: Handle case where event type is delete vs. create/update
      • Repository Method: New repository method created for host-from-events queries
      • TestContainer Verification: Source code test using TestContainer for verification of query correctness

      Technical Approach - Pseudocode Implementation
      Step 1: Event Selection - SELECT * FROM events WHERE tallyStateSaysSo AND hbi_sourced FOR org AND service_type = 'hbi_host'

      Step 2: Host Matching (potentially tricky) - IF Results > 0: SELECT * hosts that match those instances from those events

      Step 3: Multi-Table Operations - upsert hosts, instance_measurements, and buckets...(if event type isn't delete)

      Step 4: No Results Handling - IF Results: 0 //no host (or buckets) update, hosts might still be there from previous runs

      Step 5: Snapshot Generation - accumulate usage for the whole org based on the existing state of the swatch host & its buckets (aka make snapshots)

              Unassigned Unassigned
              lburnett0 Lindsey Burnett
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: