Skip to content

Conversation

@jeremylenz
Copy link
Collaborator

@jeremylenz jeremylenz commented Oct 3, 2025

What are the changes introduced in this pull request?

Requires theforeman/foreman#10713

In foreman_rh_cloud there are a quite many places where we need to know if it's an IoP setup or not. On the backend this is easy: we'd just call ForemanRhCloud.with_iop_smart_proxy?. But from React/JS, it's a bit tricky and there are a couple methods:

  1. Include this value inside an existing API response and use it
  2. Make an XHR request to a special API endpoint

Neither of these is ideal, for various reasons

  1. While the request is pending, we're in a state of "don't know" rather than true/false - what do we display on screen at this moment?
  2. In certain cases (like when a host doesn't have an insights facet) it's not possible to use the API response

With this change, the .with_iop_smart_proxy? value is added to ForemanContext and we can use it anywhere without making an API call.

Additionally, since IoP is now more than just Advisor engine, I've taken the liberty of renaming our React hook.

Considerations taken when implementing this change?

I didn't remove the endpoint completely. IoP services may still need to call it some day..?

What are the testing steps for this pull request?

get an IoP setup
Load pages that make this request and observe lack of request with the PR checked out

Summary by Sourcery

Register the foreman_rh_cloud iop flag in the plugin metadata registry and refactor the configuration hook and related components to use the new useIopConfig hook for conditional rendering and API request skipping

New Features:

  • Register foreman_rh_cloud iop flag in the Foreman plugin metadata registry

Enhancements:

  • Introduce useIopConfig hook to read IoP mode from app metadata or fallback to API
  • Replace useAdvisorEngineConfig with useIopConfig across multiple Insights and host details components
  • Conditionally render Insights components and toolbar items based on IoP mode
  • Add isRelevant check for CVE count column using the IoP metadata flag

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 3, 2025

Reviewer's Guide

This PR introduces a new IOP-based feature flag for the foreman_rh_cloud plugin by registering metadata on plugin load and refactors all components to use a new useIopConfig hook that reads from context metadata (falling back to the API only if needed).

Class diagram for updated ConfigHooks and useIopConfig

classDiagram
    class useIopConfig {
        +result: boolean (from context metadata)
        +skipApiRequest: boolean
        +advisorEngineConfig: object (from API)
        +return: boolean (context or API)
    }
    useIopConfig --|> useAPI : uses
    useIopConfig --|> useForemanContext : uses
    class useAPI {
        +response: object
    }
    class useForemanContext {
        +metadata: object
    }
Loading

File-Level Changes

Change Details Files
Register foreman_rh_cloud app metadata with an iop flag
  • Add metadata registration in plugin.rb
  • Use Foreman::Plugin.app_metadata_registry to expose iop
lib/foreman_rh_cloud/plugin.rb
Introduce and refactor to useIopConfig hook
  • Rename useAdvisorEngineConfig to useIopConfig
  • Read iop from ForemanContext metadata
  • Skip API request when metadata exists
webpack/common/Hooks/ConfigHooks.js
Replace all advisor engine checks with IOP-based flag
  • Import and use useIopConfig in place of useAdvisorEngineConfig
  • Remove branches for local advisor engine
webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js
webpack/InsightsHostDetailsTab/NewHostDetailsTab.js
webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js
webpack/InsightsCloudSync/Components/ToolbarDropdown.js
webpack/InsightsCloudSync/InsightsCloudSync.js
webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js
Adjust column relevance based on IOP metadata
  • Add isRelevant check using context.metadata.foreman_rh_cloud.iop
webpack/ForemanColumnExtensions/index.js

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

@chris1984 chris1984 marked this pull request as ready for review October 4, 2025 01:35
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:

  • Consider centralizing the fallback default for the IOP flag inside your useIopConfig hook so consumers don't have to replicate the ?? true logic in the ForemanColumnExtensions and elsewhere.
  • Rename useIopConfig (and its return value) to something like useIopSmartProxyEnabled or isIopSmartProxy to better convey that it checks IoP smart proxy availability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider centralizing the fallback default for the IOP flag inside your useIopConfig hook so consumers don't have to replicate the `?? true` logic in the ForemanColumnExtensions and elsewhere.
- Rename useIopConfig (and its return value) to something like useIopSmartProxyEnabled or isIopSmartProxy to better convey that it checks IoP smart proxy availability.

## Individual Comments

### Comment 1
<location> `webpack/common/Hooks/ConfigHooks.js:13` </location>
<code_context>
+  const skipApiRequest = result !== undefined;
   const { response: advisorEngineConfig } = useAPI(
-    'get',
+    skipApiRequest ? null : 'get',
     ADVISOR_ENGINE_CONFIG_PATH,
     {
</code_context>

<issue_to_address>
**issue (bug_risk):** Passing `null` as the HTTP method may cause issues in some API hooks.

Please confirm that `useAPI` can handle a `null` method without errors, or refactor to ensure a valid method is always provided.
</issue_to_address>

### Comment 2
<location> `webpack/ForemanColumnExtensions/index.js:77` </location>
<code_context>
   {
     columnName: 'cves_count',
     title: __('Total CVEs'),
+    // eslint-disable-next-line camelcase
+    isRelevant: context => context?.metadata?.foreman_rh_cloud.iop ?? true,
     wrapper: hostDetails => <CVECountCell hostDetails={hostDetails} />,
     weight: 2600,
</code_context>

<issue_to_address>
**suggestion:** Defaulting to `true` for `isRelevant` may unintentionally show the column.

If you want the column hidden when `iop` is undefined, use `?? false` instead.

```suggestion
    isRelevant: context => context?.metadata?.foreman_rh_cloud.iop ?? false,
```
</issue_to_address>

### Comment 3
<location> `webpack/common/Hooks/ConfigHooks.js:21` </location>
<code_context>

   // eslint-disable-next-line camelcase
-  return advisorEngineConfig?.use_iop_mode;
+  return skipApiRequest ? result : advisorEngineConfig?.use_iop_mode;
 };
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Return value may be inconsistent in type between context and API response.

Normalize the return value to ensure consistent type and semantics, preventing subtle bugs from type mismatches.
</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.

@jeremylenz
Copy link
Collaborator Author

Github was not working right so I closed this and opened #1116

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