Send data to Inventory views#119
Open
MichaelMraka wants to merge 5 commits intoRedHatInsights:mainfrom
Open
Conversation
Reviewer's GuideIntegrates Advisor with the Inventory View Kafka topic by tracking per-host incident/severity counts during report processing and emitting a structured per-host summary event, plus wiring up Kafka configuration and local/dev topics to support it. Sequence diagram for sending inventory view Kafka events after host updatesequenceDiagram
actor ReportProcessor
participant Service_update_host as service.update_host
participant InventoryView as inventory_view
participant KafkaProducer as confluent_kafka_Producer
participant KafkaBroker as Kafka
ReportProcessor->>Service_update_host: update_host(host_obj, reports,...)
loop For each report
Service_update_host->>InventoryView: update_inventory_view_counts(counts, rule)
InventoryView-->>Service_update_host: counts updated
end
Service_update_host-->>Service_update_host: compute num_report_objs
Service_update_host->>InventoryView: send_inventory_view_event(event_data)
alt Producer not configured
InventoryView-->>Service_update_host: return without sending
else Producer configured
InventoryView->>KafkaProducer: poll(0)
InventoryView->>KafkaProducer: produce(topic, payload, headers, callback)
KafkaProducer-->>InventoryView: enqueue message
InventoryView->>KafkaProducer: flush()
KafkaProducer->>KafkaBroker: send message
KafkaBroker-->>KafkaProducer: delivery result
KafkaProducer->>InventoryView: invoke inventory_view_delivery_report
alt Delivery success
InventoryView-->>InventoryView: log debug
else Delivery failure
InventoryView-->>InventoryView: log error
end
end
InventoryView-->>Service_update_host: return
Service_update_host-->>ReportProcessor: host update complete
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
run kafka in KRaft mode without zookeeper
701a7ac to
6450a19
Compare
fixing %3|1772543475.190|FAIL|rdkafka#consumer-2| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Connect to ipv6#[::1]:9092 failed: Connection refused (after 0ms in state CONNECT) %3|1772543475.241|FAIL|rdkafka#consumer-2| [thrd:localhost:9092/bootstrap]: localhost:9092/bootstrap: Connect to ipv4#127.0.0.1:9092 failed: Connection refused (after 0ms in state CONNECT)
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider avoiding
p.flush()on everysend_inventory_view_eventcall, as this forces a synchronous round trip per host update; using async delivery with periodic/background flush or higherlinger.mswould reduce overhead on high-traffic paths. - You wrap
send_inventory_view_eventin a broadtry/exceptinsideupdate_host, and the function itself also has a broadtry/except; this double exception swallowing makes debugging harder—centralize the error handling in one place and let the other raise.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider avoiding `p.flush()` on every `send_inventory_view_event` call, as this forces a synchronous round trip per host update; using async delivery with periodic/background flush or higher `linger.ms` would reduce overhead on high-traffic paths.
- You wrap `send_inventory_view_event` in a broad `try/except` inside `update_host`, and the function itself also has a broad `try/except`; this double exception swallowing makes debugging harder—centralize the error handling in one place and let the other raise.
## Individual Comments
### Comment 1
<location path="service/inventory_view.py" line_range="113-114" />
<code_context>
+ counts: dict with the counts data.
+ rule: dict with the rule data.
+ """
+ if rule.get('has_incident'):
+ counts['incidents'] += 1
+
+ severity = _rule_risks.get(rule.get('total_risk'))
</code_context>
<issue_to_address>
**issue (bug_risk):** `update_inventory_view_counts` assumes `counts` already has all keys initialized, which can cause errors if a plain dict is passed.
At the current call site `counts` is a `defaultdict(int)`, so `counts['incidents'] += 1` is safe. But the function is typed as accepting a generic `dict`, so callers passing a plain dict without pre-populated keys will get a `KeyError`. Either update the implementation to use `counts['incidents'] = counts.get('incidents', 0) + 1` (and similarly for severity keys), or narrow/document the type to `defaultdict(int)` so the expectation is explicit.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Send Advisor host data and aggregated risk metrics to the Inventory View service via Kafka when reports are processed.
New Features:
Enhancements:
CI:
Deployment: