Skip to content

Conversation

@sjha4
Copy link
Member

@sjha4 sjha4 commented Dec 12, 2025

What are the changes introduced in this pull request?

Rescue errors for API endpoints not being found on old N-1, N-2 smart proxies and allow the sync to succeed. Add log warnings when older smart proxy version is detected.

Considerations taken when implementing this change?

This also catches all StandardErrors and logs them as warnings instead of failing the sync cause an error impacts all content types blocking use of proxy whereas a warning would allow proxy to sync and the only issue there will be around container cert auth for hosts registered to the proxy which can be resolved by falling back to basic auth or retrying the sync after debugging the issue in case of failures while keeping proxies usable.

What are the testing steps for this pull request?

  1. Spin up an old smart proxy (N-1 or N-2).
  2. Sync some container repos and tie relevant LCE to smart proxy to make it available for the capsule.
  3. Register a host to the smart proxy.
  4. Run a complete sync.
    With this PR, instead of error, the task will succeed with warning in logs as below:
2025-12-12T12:42:47 [W|app|dda402e2] Capsule capsule.com does not support the update_hosts endpoint (likely running an older version). Skipping host updates.
2025-12-12T12:42:48 [W|app|dda402e2] Capsule capsule.com does not support the host_repository_mapping endpoint (likely running an older version). Skipping host-repository mapping updates.

Summary by Sourcery

Handle missing container gateway API endpoints on older smart proxies without failing sync tasks.

Bug Fixes:

  • Prevent container gateway host and repository sync from failing when older smart proxies lack the update_hosts or host_repository_mapping endpoints by rescuing NotFound errors.

Enhancements:

  • Add warning logs when a smart proxy is missing container gateway endpoints or when host update operations fail with other errors.

Copy link
Contributor

@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:

  • The rescue StandardError blocks are quite broad here; consider rescuing the specific error types you expect (e.g., RestClient::NotFound, ProxyAPI::ProxyException) to avoid unintentionally hiding unrelated failures.
  • The NotFound detection and logging logic is duplicated between update_container_gateway_hosts and update_host_container_repo_mapping; consider extracting a small helper method to DRY this up and keep the conditions consistent.
  • Logging the full backtrace at warn level could be noisy in production; you might want to log the message at warn and move the backtrace to debug or a separate conditional log when more detail is required.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `rescue StandardError` blocks are quite broad here; consider rescuing the specific error types you expect (e.g., `RestClient::NotFound`, `ProxyAPI::ProxyException`) to avoid unintentionally hiding unrelated failures.
- The NotFound detection and logging logic is duplicated between `update_container_gateway_hosts` and `update_host_container_repo_mapping`; consider extracting a small helper method to DRY this up and keep the conditions consistent.
- Logging the full backtrace at warn level could be noisy in production; you might want to log the message at warn and move the backtrace to debug or a separate conditional log when more detail is required.

## Individual Comments

### Comment 1
<location> `app/models/katello/concerns/smart_proxy_extensions.rb:279-277` </location>
<code_context>
           }
         end
         ProxyAPI::ContainerGateway.new(url: self.url).update_hosts({ hosts: hosts })
+      rescue StandardError => e
+        if e.is_a?(RestClient::NotFound) || (e.is_a?(ProxyAPI::ProxyException) && e.respond_to?(:wrapped_exception) && e.wrapped_exception.is_a?(RestClient::NotFound))
+          Rails.logger.warn("Capsule #{name} does not support the update_hosts endpoint (likely running an older version). Skipping host updates.")
+        else
+          Rails.logger.warn("Failed to update hosts for capsule #{name}: #{e.message}")
+          Rails.logger.warn(e.backtrace.join("\n"))
+        end
       end

</code_context>

<issue_to_address>
**issue (bug_risk):** Rescuing `StandardError` and only logging can hide unexpected failures.

Catching `StandardError` here will hide any unexpected failures in building the host list or calling the API, only emitting a warning. That can mask production issues and leave updates partially applied. Prefer rescuing only the known API-related exceptions (e.g., specific `RestClient`/`ProxyAPI` errors), and allow other errors to bubble up or be re-raised after logging (except for the `NotFound` cases you intentionally ignore).
</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.

Copy link
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

Code looks fine, we just need to text the varying error conditions.

end
ProxyAPI::ContainerGateway.new(url: self.url).update_hosts({ hosts: hosts })
rescue StandardError => e
if e.is_a?(RestClient::NotFound) || (e.is_a?(ProxyAPI::ProxyException) && e.respond_to?(:wrapped_exception) && e.wrapped_exception.is_a?(RestClient::NotFound))
Copy link
Member

Choose a reason for hiding this comment

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

Since Katello controls all the code here, it's still uncertain if the 404 will return as NotFound or a ProxyException?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a ProxyAPI::ProxyException that wraps the RestClient::NotFound error. Checking with or as a precaution but is unnecessary..Let me verify the exception type again to refresh my memory and update this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to remove the first condition and added the safe &. operator to handle any weirdness..

@sjha4 sjha4 force-pushed the support-n-x-capsules branch from d5237cc to a610595 Compare December 15, 2025 17:15
@sjha4 sjha4 force-pushed the support-n-x-capsules branch from a610595 to f3d5713 Compare December 16, 2025 14:38
Copy link
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

N-2 capsule syncing works now, thanks!

@sjha4 sjha4 merged commit ca01834 into Katello:master Dec 16, 2025
22 checks passed
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