Skip to content

MGMT-20958: Logging and error handling#12

Merged
carbonin merged 6 commits intoopenshift-assisted:masterfrom
carbonin:logging-and-error-handling
Jul 7, 2025
Merged

MGMT-20958: Logging and error handling#12
carbonin merged 6 commits intoopenshift-assisted:masterfrom
carbonin:logging-and-error-handling

Conversation

@carbonin
Copy link
Copy Markdown
Collaborator

@carbonin carbonin commented Jul 3, 2025

Add better logging for when tools are run.
Additionally add better error handling when calling the assisted service APIs.
Finally standardize the log formatting and remove file logging when running in a container.

After this change logging looks like:

INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:23,334 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:23,335 - root - INFO     - 139785087563584:24441 - Retrieving list of all clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:138)->list_clusters
2025-07-03 10:23:23,452 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:23,562 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:23,563 - root - INFO     - 139785087563584:24441 - Listing all clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:140)->list_clusters
2025-07-03 10:23:23,796 - root - INFO     - 139785087563584:24441 - Successfully listed clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:142)->list_clusters
2025-07-03 10:23:23,797 - root - INFO     - 139785087563584:24441 - Successfully retrieved 3 clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:150)->list_clusters
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:25,949 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:25,950 - root - INFO     - 139785087563584:24441 - Retrieving available OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:354)->list_versions
2025-07-03 10:23:26,090 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Getting OpenShift versions (only_latest: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:444)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:449)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:357)->list_versions
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:27,599 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:27,599 - root - INFO     - 139785087563584:24441 - Creating cluster: name=agent-test, version=4.20.0-ec.3, base_domain=test.example.com, single_node=True - (/home/ncarboni/Source/assisted-service-mcp/server.py:254)->create_cluster
2025-07-03 10:23:27,745 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:27,829 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:27,830 - root - INFO     - 139785087563584:24441 - Creating cluster 'agent-test' with version 4.20.0-ec.3 (single_node: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:283)->create_cluster
2025-07-03 10:23:27,954 - root - ERROR    - 139785087563584:24441 - API error while creating cluster 'agent-test': Status: 400, Reason: Bad Request, Body: {"code":"400","href":"","id":400,"kind":"Error","reason":"Invalid format for Tags: created_by=mcp. Tags should be a comma-separated list (e.g. tag1,tag2,tag3). Each tag can consist of the following characters: Alphanumeric (aA-zZ, 0-9), underscore (_) and white-spaces."}
 - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:295)->create_cluster

Summary by CodeRabbit

  • New Features

    • Added detailed logging throughout the application, including debug and info messages for key operations and API calls.
    • Introduced comprehensive error handling for all network and API interactions, with structured error logging.
  • Chores

    • Added an environment variable to control file logging, allowing logs to be directed only to standard error when desired.
    • Improved logging configuration for better flexibility in different environments.
    • Restricted container port exposure to localhost for enhanced security during local development.

@carbonin carbonin requested a review from eranco74 July 3, 2025 14:24
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 3, 2025
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jul 3, 2025

@carbonin: This pull request references MGMT-20958 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Add better logging for when tools are run.
Additionally add better error handling when calling the assisted service APIs.
Finally standardize the log formatting and remove file logging when running in a container.

After this change logging looks like:

INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:23,334 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:23,335 - root - INFO     - 139785087563584:24441 - Retrieving list of all clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:138)->list_clusters
2025-07-03 10:23:23,452 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:23,562 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:23,563 - root - INFO     - 139785087563584:24441 - Listing all clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:140)->list_clusters
2025-07-03 10:23:23,796 - root - INFO     - 139785087563584:24441 - Successfully listed clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:142)->list_clusters
2025-07-03 10:23:23,797 - root - INFO     - 139785087563584:24441 - Successfully retrieved 3 clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:150)->list_clusters
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:25,949 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:25,950 - root - INFO     - 139785087563584:24441 - Retrieving available OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:354)->list_versions
2025-07-03 10:23:26,090 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Getting OpenShift versions (only_latest: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:444)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:449)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:357)->list_versions
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:27,599 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:27,599 - root - INFO     - 139785087563584:24441 - Creating cluster: name=agent-test, version=4.20.0-ec.3, base_domain=test.example.com, single_node=True - (/home/ncarboni/Source/assisted-service-mcp/server.py:254)->create_cluster
2025-07-03 10:23:27,745 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:27,829 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:27,830 - root - INFO     - 139785087563584:24441 - Creating cluster 'agent-test' with version 4.20.0-ec.3 (single_node: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:283)->create_cluster
2025-07-03 10:23:27,954 - root - ERROR    - 139785087563584:24441 - API error while creating cluster 'agent-test': Status: 400, Reason: Bad Request, Body: {"code":"400","href":"","id":400,"kind":"Error","reason":"Invalid format for Tags: created_by=mcp. Tags should be a comma-separated list (e.g. tag1,tag2,tag3). Each tag can consist of the following characters: Alphanumeric (aA-zZ, 0-9), underscore (_) and white-spaces."}
- (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:295)->create_cluster

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jul 3, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: carbonin

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 3, 2025

"""

Walkthrough

The changes introduce comprehensive logging and error handling improvements across the codebase. Logging is now more detailed in both API client and server modules, with structured log messages and robust exception handling. The logging system is also updated to support environment-based configuration, allowing file logging to be toggled via an environment variable, which is now set in the Dockerfile. Additionally, the Makefile limits container port exposure to localhost.

Changes

File(s) Change Summary
Dockerfile Changed base image source; added LOG_TO_FILE=false environment variable to disable file logging in container.
server.py Added detailed logging at key control flow points using a logger; no changes to logic or public APIs.
service_client/assisted_service_api.py Wrapped all API calls with try-except for ApiException and general exceptions; added structured logging.
service_client/logger.py Added default format to SensitiveFormatter; constructor now takes optional format; file logging toggled by LOG_TO_FILE env variable.
Makefile Modified run target to bind container port 8000 only to localhost (127.0.0.1:8000).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Server
    participant InventoryClient
    participant AssistedServiceAPI

    User->>Server: Send API request
    Server->>Server: Log request start
    Server->>InventoryClient: Call API method
    InventoryClient->>InventoryClient: Log API call start
    InventoryClient->>AssistedServiceAPI: Perform API request
    AssistedServiceAPI-->>InventoryClient: Respond (or error)
    InventoryClient->>InventoryClient: Log success or error
    InventoryClient-->>Server: Return result or raise exception
    Server->>Server: Log operation completion or error
    Server-->>User: Return response
Loading

Suggested labels

lgtm

Poem

🐇
Logs now dance in streams, not files,
With errors caught and traced in style.
From clusters, hosts, and bundles too,
Each step is logged—no more "guess who?"
The rabbit cheers with twitching nose:
"Now every bug, the logbook shows!"

"""


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 3, 2025
@openshift-ci openshift-ci Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 3, 2025
@carbonin carbonin force-pushed the logging-and-error-handling branch from ad06674 to 5ddc039 Compare July 3, 2025 14:25
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 3, 2025
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jul 3, 2025

@carbonin: This pull request references MGMT-20958 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Add better logging for when tools are run.
Additionally add better error handling when calling the assisted service APIs.
Finally standardize the log formatting and remove file logging when running in a container.

After this change logging looks like:

INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:23,334 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:23,335 - root - INFO     - 139785087563584:24441 - Retrieving list of all clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:138)->list_clusters
2025-07-03 10:23:23,452 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:23,562 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:23,563 - root - INFO     - 139785087563584:24441 - Listing all clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:140)->list_clusters
2025-07-03 10:23:23,796 - root - INFO     - 139785087563584:24441 - Successfully listed clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:142)->list_clusters
2025-07-03 10:23:23,797 - root - INFO     - 139785087563584:24441 - Successfully retrieved 3 clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:150)->list_clusters
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:25,949 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:25,950 - root - INFO     - 139785087563584:24441 - Retrieving available OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:354)->list_versions
2025-07-03 10:23:26,090 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Getting OpenShift versions (only_latest: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:444)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:449)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:357)->list_versions
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:27,599 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:27,599 - root - INFO     - 139785087563584:24441 - Creating cluster: name=agent-test, version=4.20.0-ec.3, base_domain=test.example.com, single_node=True - (/home/ncarboni/Source/assisted-service-mcp/server.py:254)->create_cluster
2025-07-03 10:23:27,745 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:27,829 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:27,830 - root - INFO     - 139785087563584:24441 - Creating cluster 'agent-test' with version 4.20.0-ec.3 (single_node: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:283)->create_cluster
2025-07-03 10:23:27,954 - root - ERROR    - 139785087563584:24441 - API error while creating cluster 'agent-test': Status: 400, Reason: Bad Request, Body: {"code":"400","href":"","id":400,"kind":"Error","reason":"Invalid format for Tags: created_by=mcp. Tags should be a comma-separated list (e.g. tag1,tag2,tag3). Each tag can consist of the following characters: Alphanumeric (aA-zZ, 0-9), underscore (_) and white-spaces."}
- (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:295)->create_cluster

Summary by CodeRabbit

  • New Features

  • Added detailed logging throughout the application, including debug and info messages for key operations and API calls.

  • Introduced comprehensive error handling for all network and API interactions, with structured error logging.

  • Chores

  • Added an environment variable to control file logging, allowing logs to be directed only to standard error when desired.

  • Improved logging configuration for better flexibility in different environments.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@carbonin carbonin force-pushed the logging-and-error-handling branch from 6605e63 to 85f077b Compare July 3, 2025 17:36
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jul 3, 2025

@carbonin: This pull request references MGMT-20958 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Add better logging for when tools are run.
Additionally add better error handling when calling the assisted service APIs.
Finally standardize the log formatting and remove file logging when running in a container.

After this change logging looks like:

INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:23,334 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:23,335 - root - INFO     - 139785087563584:24441 - Retrieving list of all clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:138)->list_clusters
2025-07-03 10:23:23,452 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:23,562 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:23,563 - root - INFO     - 139785087563584:24441 - Listing all clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:140)->list_clusters
2025-07-03 10:23:23,796 - root - INFO     - 139785087563584:24441 - Successfully listed clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:142)->list_clusters
2025-07-03 10:23:23,797 - root - INFO     - 139785087563584:24441 - Successfully retrieved 3 clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:150)->list_clusters
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:25,949 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:25,950 - root - INFO     - 139785087563584:24441 - Retrieving available OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:354)->list_versions
2025-07-03 10:23:26,090 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Getting OpenShift versions (only_latest: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:444)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:449)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:357)->list_versions
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:27,599 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:27,599 - root - INFO     - 139785087563584:24441 - Creating cluster: name=agent-test, version=4.20.0-ec.3, base_domain=test.example.com, single_node=True - (/home/ncarboni/Source/assisted-service-mcp/server.py:254)->create_cluster
2025-07-03 10:23:27,745 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:27,829 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:27,830 - root - INFO     - 139785087563584:24441 - Creating cluster 'agent-test' with version 4.20.0-ec.3 (single_node: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:283)->create_cluster
2025-07-03 10:23:27,954 - root - ERROR    - 139785087563584:24441 - API error while creating cluster 'agent-test': Status: 400, Reason: Bad Request, Body: {"code":"400","href":"","id":400,"kind":"Error","reason":"Invalid format for Tags: created_by=mcp. Tags should be a comma-separated list (e.g. tag1,tag2,tag3). Each tag can consist of the following characters: Alphanumeric (aA-zZ, 0-9), underscore (_) and white-spaces."}
- (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:295)->create_cluster

Summary by CodeRabbit

  • New Features

  • Added detailed logging throughout the application, including debug and info messages for key operations and API calls.

  • Introduced comprehensive error handling for all network and API interactions, with structured error logging.

  • Chores

  • Added an environment variable to control file logging, allowing logs to be directed only to standard error when desired.

  • Improved logging configuration for better flexibility in different environments.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Without this I was unable to access the service using an MCP client or
curl
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jul 3, 2025

@carbonin: This pull request references MGMT-20958 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Add better logging for when tools are run.
Additionally add better error handling when calling the assisted service APIs.
Finally standardize the log formatting and remove file logging when running in a container.

After this change logging looks like:

INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:23,334 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:23,335 - root - INFO     - 139785087563584:24441 - Retrieving list of all clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:138)->list_clusters
2025-07-03 10:23:23,452 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:23,562 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:23,563 - root - INFO     - 139785087563584:24441 - Listing all clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:140)->list_clusters
2025-07-03 10:23:23,796 - root - INFO     - 139785087563584:24441 - Successfully listed clusters - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:142)->list_clusters
2025-07-03 10:23:23,797 - root - INFO     - 139785087563584:24441 - Successfully retrieved 3 clusters - (/home/ncarboni/Source/assisted-service-mcp/server.py:150)->list_clusters
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:25,949 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:25,950 - root - INFO     - 139785087563584:24441 - Retrieving available OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:354)->list_versions
2025-07-03 10:23:26,090 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:26,178 - root - INFO     - 139785087563584:24441 - Getting OpenShift versions (only_latest: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:444)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:449)->get_openshift_versions
2025-07-03 10:23:26,271 - root - INFO     - 139785087563584:24441 - Successfully retrieved OpenShift versions - (/home/ncarboni/Source/assisted-service-mcp/server.py:357)->list_versions
INFO:     127.0.0.1:47670 - "POST /messages/?session_id=38931e7e66a14052ba2090dd1b0fbb0c HTTP/1.1" 202 Accepted
2025-07-03 10:23:27,599 - mcp.server.lowlevel.server - INFO     - 139785087563584:24441 - Processing request of type CallToolRequest - (/home/ncarboni/Source/assisted-service-mcp/.venv/lib64/python3.13/site-packages/mcp/server/lowlevel/server.py:523)->_handle_request
2025-07-03 10:23:27,599 - root - INFO     - 139785087563584:24441 - Creating cluster: name=agent-test, version=4.20.0-ec.3, base_domain=test.example.com, single_node=True - (/home/ncarboni/Source/assisted-service-mcp/server.py:254)->create_cluster
2025-07-03 10:23:27,745 - root - INFO     - 139785087563584:24441 - Fetching pull secret from https://api.openshift.com/api/accounts_mgmt/v1/access_token - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:51)->_get_pull_secret
2025-07-03 10:23:27,829 - root - INFO     - 139785087563584:24441 - Successfully fetched pull secret - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:54)->_get_pull_secret
2025-07-03 10:23:27,830 - root - INFO     - 139785087563584:24441 - Creating cluster 'agent-test' with version 4.20.0-ec.3 (single_node: True) - (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:283)->create_cluster
2025-07-03 10:23:27,954 - root - ERROR    - 139785087563584:24441 - API error while creating cluster 'agent-test': Status: 400, Reason: Bad Request, Body: {"code":"400","href":"","id":400,"kind":"Error","reason":"Invalid format for Tags: created_by=mcp. Tags should be a comma-separated list (e.g. tag1,tag2,tag3). Each tag can consist of the following characters: Alphanumeric (aA-zZ, 0-9), underscore (_) and white-spaces."}
- (/home/ncarboni/Source/assisted-service-mcp/service_client/assisted_service_api.py:295)->create_cluster

Summary by CodeRabbit

  • New Features

  • Added detailed logging throughout the application, including debug and info messages for key operations and API calls.

  • Introduced comprehensive error handling for all network and API interactions, with structured error logging.

  • Chores

  • Added an environment variable to control file logging, allowing logs to be directed only to standard error when desired.

  • Improved logging configuration for better flexibility in different environments.

  • Restricted container port exposure to localhost for enhanced security during local development.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Makefile (1)

14-14: Parameterize host binding for greater flexibility

Hard-coding 127.0.0.1 improves security, but it also limits scenarios where developers may legitimately want external access (e.g., running demos on a LAN). Expose the host binding as a Make variable so callers can override it without editing the file.

+HOST_BIND ?= 127.0.0.1
@@
-	podman run --rm -p 127.0.0.1:8000:8000 $(IMAGE_NAME):$(TAG)
+	podman run --rm -p $(HOST_BIND):8000:8000 $(IMAGE_NAME):$(TAG)

This keeps the default secure while remaining configurable via make run HOST_BIND=0.0.0.0.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85f077b and fb1a2cd.

📒 Files selected for processing (1)
  • Makefile (1 hunks)

Comment thread server.py
log.debug("Found offline token in request headers")
return token

log.error("No offline token found in environment or request headers")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unrelated to this PR, not having OCM offline token set shouldn't lead to RuntimeError.
Something seems off here.

@eranco74
Copy link
Copy Markdown
Collaborator

eranco74 commented Jul 6, 2025

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 6, 2025
@carbonin carbonin merged commit 65e6b73 into openshift-assisted:master Jul 7, 2025
9 checks passed
@carbonin carbonin deleted the logging-and-error-handling branch July 7, 2025 11:58
@coderabbitai coderabbitai Bot mentioned this pull request Oct 16, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants