Skip to content

Conversation

@r14chandra
Copy link
Contributor

@r14chandra r14chandra commented Nov 18, 2025

Why do we need this change? πŸ’­

Resolves RHINENG-17707

Documentation update? πŸ“

  • Yes
  • No

Security Checklist πŸ”’

Upon raising this PR please go through RedHatInsights/secure-coding-checklist

πŸ’‚β€β™‚οΈ Checklist 🎯

  • Bugfix
  • New Feature
  • Refactor
  • Unittests Added
  • DRY code
  • Dependency Added
  • DB Migration Added

Additional πŸ“£

Feel free to add any other relevant details such as links, notes, screenshots, here.

Summary by Sourcery

Integrate Unleash feature flag gating into the legacy backend by adding a helper function and using it in consumers to conditionally bypass processing when the ROS V2 flag is active.

New Features:

  • Add is_feature_flag_enabled helper to integrate Unleash feature flag checks
  • Skip event processing in inventory and insights engine consumers when the UNLEASH_ROS_V2_FLAG is enabled for an organization

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 18, 2025

Reviewer's Guide

Introduces an Unleash-based feature flag check for the legacy ROS backend by adding a helper in the Unleash client and gating message processing in both inventory and insights engine consumers based on UNLEASH_ROS_V2_FLAG.

Sequence diagram for feature flag check in inventory events consumer

sequenceDiagram
participant InventoryEventsConsumer
participant UnleashClient
Note over InventoryEventsConsumer: On message received
InventoryEventsConsumer->UnleashClient: is_feature_flag_enabled(org_id, UNLEASH_ROS_V2_FLAG, prefix)
UnleashClient-->>InventoryEventsConsumer: true/false
alt Feature flag enabled
InventoryEventsConsumer->>InventoryEventsConsumer: continue (skip processing)
else Feature flag disabled
InventoryEventsConsumer->>InventoryEventsConsumer: process event
end
Loading

Sequence diagram for feature flag check in insights engine consumer

sequenceDiagram
participant InsightsEngineConsumer
participant UnleashClient
Note over InsightsEngineConsumer: On message received
InsightsEngineConsumer->UnleashClient: is_feature_flag_enabled(org_id, UNLEASH_ROS_V2_FLAG, prefix)
UnleashClient-->>InsightsEngineConsumer: true/false
alt Feature flag enabled
InsightsEngineConsumer->>InsightsEngineConsumer: continue (skip processing)
else Feature flag disabled
InsightsEngineConsumer->>InsightsEngineConsumer: handle_msg(msg)
end
Loading

Class diagram for new Unleash feature flag helper

classDiagram
class UnleashClient {
  +initialize_client()
  +is_enabled(flag_name, context)
  +is_initialized
}
class is_feature_flag_enabled {
  +is_feature_flag_enabled(org_id, flag_name, service_name)
}
UnleashClient <.. is_feature_flag_enabled : uses
Loading

Class diagram for updated consumers with feature flag check

classDiagram
class InventoryEventsConsumer {
  +run()
  -event_type_map
  -prefix
}
class InsightsEngineConsumer {
  +run()
  +handle_msg(msg)
  -prefix
}
class IsFeatureFlagEnabled {
  +is_feature_flag_enabled(org_id, flag_name, service_name)
}
InventoryEventsConsumer ..> IsFeatureFlagEnabled : calls
InsightsEngineConsumer ..> IsFeatureFlagEnabled : calls
Loading

File-Level Changes

Change Details Files
Add Unleash feature flag helper
  • Define is_feature_flag_enabled(org_id, flag_name, service_name)
  • Create context and fetch flag status via unleash_client
  • Log debug statement and return enabled state
ros/lib/unleash.py
Gate inventory events processing with feature flag
  • Import is_feature_flag_enabled and UNLEASH_ROS_V2_FLAG
  • Check flag status early in run() and skip processing if enabled
ros/processor/inventory_events_consumer.py
Gate insights engine consumer with feature flag
  • Import is_feature_flag_enabled
  • Extract org_id from message payload before handling
  • Skip message handling when flag enabled
ros/processor/insights_engine_consumer.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In is_feature_flag_enabled you pass service_name only for loggingβ€”consider including it in the unleash context (e.g. appName) or removing the unused parameter to keep the API surface minimal.
  • In insights_engine_consumer you call get('org_id') which can return Noneβ€”add explicit handling or a default value to avoid passing a None userId into the Unleash client.
  • Since you’re evaluating the same flag for each org_id across many messages, consider caching unleash_client.is_enabled results per (org_id, flag_name) during a run to reduce repeated network calls.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In is_feature_flag_enabled you pass service_name only for loggingβ€”consider including it in the unleash context (e.g. appName) or removing the unused parameter to keep the API surface minimal.
- In insights_engine_consumer you call get('org_id') which can return Noneβ€”add explicit handling or a default value to avoid passing a None userId into the Unleash client.
- Since you’re evaluating the same flag for each org_id across many messages, consider caching unleash_client.is_enabled results per (org_id, flag_name) during a run to reduce repeated network calls.

## Individual Comments

### Comment 1
<location> `ros/processor/insights_engine_consumer.py:76` </location>
<code_context>
             try:
                 msg = json.loads(msg.value().decode("utf-8"))
+
+                org_id = msg["input"]["platform_metadata"].get('org_id')
+                if is_feature_flag_enabled(org_id, UNLEASH_ROS_V2_FLAG, self.prefix):
+                    continue
</code_context>

<issue_to_address>
**issue (bug_risk):** Potential KeyError if 'input' or 'platform_metadata' is missing in msg.

Using .get() for these keys will prevent exceptions if the message structure is unexpected or missing fields.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click πŸ‘ or πŸ‘Ž on each comment and I'll use the feedback to improve your reviews.

@r14chandra r14chandra merged commit f059db7 into RedHatInsights:main Nov 20, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants