-
Notifications
You must be signed in to change notification settings - Fork 322
Add Chaibot client for ship-help MCP integration #5251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oramraz
wants to merge
13
commits into
openshift:main
Choose a base branch
from
oramraz:chaibot-ship-help-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1f6c8c2
Add Chaibot client for ship-help MCP integration
f050ac6
Add Chaibot Slack integration
2094aba
Fix HTTP error handling: check status code before JSON parsing
c39d4df
Fix URL extraction: trim trailing punctuation
bd0c707
Guard against nil result to prevent panic in Slack formatting
933b554
Avoid out-of-range panic after block-count mismatch
6481fea
Fix misleading documentation: clarify implementation status
25bc02c
Clarify Chaibot activation: flags vs environment variables
b6d28ef
Fix compilation: change Slack response format to string
9d9c82d
Fail fast when --enable-triage has missing config or env vars
02dc2c1
Add Accept header for MCP protocol compliance
3053fa6
Add MCP session protocol scaffolding
e536144
Fix MCP protocol: complete working implementation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| # Chaibot - Ship-Help MCP Integration | ||
|
|
||
| This package provides test failure analysis using Chai Bot (ship-help MCP) for automatic Slack triage. | ||
|
|
||
| ## Overview | ||
|
|
||
| Chaibot monitors Slack channels for Prow CI job failure URLs and automatically posts analysis using the Chai Bot service via ship-help MCP. | ||
|
|
||
| ## Files in This PR | ||
|
|
||
| - `pkg/chaibot/analyzer.go` - Ship-help MCP client implementation | ||
| - `pkg/chaibot/analyzer_test.go` - Unit tests | ||
| - `pkg/slack/events/chaibot/handler.go` - Slack event handler (monitors for Prow URLs) | ||
| - `pkg/slack/events/chaibot/handler_test.go` - Event handler tests | ||
| - `pkg/slack/events/router/router.go` - Updated to register Chaibot handler | ||
| - `cmd/slack-bot/main.go` - Updated with Chaibot initialization | ||
|
|
||
| **This PR provides the complete implementation.** The integration is ready to use once deployed. | ||
|
|
||
| ## How It Works | ||
|
|
||
| ### 1. Event Handler Pattern (Already Implemented) | ||
|
|
||
| Chaibot uses the existing event handler pattern in `openshift/ci-tools`: | ||
|
|
||
| **Implementation files:** | ||
| - `pkg/slack/events/chaibot/handler.go` - Monitors Slack messages for Prow URLs | ||
| - Registered in `pkg/slack/events/router/router.go` | ||
| - Initialized in `cmd/slack-bot/main.go` | ||
|
|
||
| **What the handler does:** | ||
| 1. Monitors configured Slack channels (e.g., `#opp-discussion`) | ||
| 2. Detects Prow CI job URLs in messages | ||
| 3. Calls `analyzer.AnalyzeFailure()` asynchronously | ||
| 4. Posts analysis results in a thread | ||
|
|
||
| ### 2. Initialization in cmd/slack-bot/main.go | ||
|
|
||
| **Already implemented in this PR:** | ||
|
|
||
| ```go | ||
| // Command-line flags (added) | ||
| --enable-triage // Enable Chaibot | ||
| --triage-config-path // Path to triage-config.yaml | ||
|
|
||
| // Initialization (added to main()) | ||
| if o.enableTriage && o.triageConfigPath != "" { | ||
| mcpURL := os.Getenv("SHIP_HELP_MCP_URL") | ||
| mcpToken := os.Getenv("SHIP_HELP_MCP_TOKEN") | ||
|
|
||
| // Create analyzer | ||
| chaibotAnalyzer = chaibot.NewAnalyzer(mcpURL, mcpToken, promptTemplate) | ||
|
|
||
| // Handler is registered in router.ForEvents() | ||
| } | ||
| ``` | ||
|
|
||
| ### 3. Event Router Registration | ||
|
|
||
| **Already implemented in pkg/slack/events/router/router.go:** | ||
|
|
||
| ```go | ||
| func ForEvents(client *slack.Client, chaibotAnalyzer *chaibot.Analyzer, chaibotChannels []string, ...) { | ||
| // ... existing handlers ... | ||
|
|
||
| if chaibotAnalyzer != nil && len(chaibotChannels) > 0 { | ||
| handlers = append(handlers, chaibothandler.Handler(client, chaibotAnalyzer, chaibotChannels)) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## NOT in This PR (Requires openshift/release Configuration) | ||
|
|
||
| The following configuration files are in **openshift/release#80559**, not this PR: | ||
|
|
||
| - `core-services/ci-chat-bot/triage-config.yaml` - Chaibot configuration | ||
| - `clusters/app.ci/ci-chat-bot/chaibot-configmap.yaml` - Kubernetes ConfigMap | ||
| - `clusters/app.ci/ci-chat-bot/ci-chat-bot.yaml` - Deployment with environment variables | ||
| - `core-services/ci-secret-bootstrap/chaibot-secret-config.yaml` - Ship-help token secret | ||
|
|
||
| ## Usage | ||
|
|
||
| Once both PRs are merged and deployed: | ||
|
|
||
| 1. **Post a Prow URL in a monitored channel:** | ||
| ``` | ||
| Job failed: https://prow.ci.openshift.org/view/gs/test-platform-results/logs/periodic-ci-stolostron-policy-collection-main-ocp4.22-interop-opp-aws/2066255424226594816 | ||
| ``` | ||
|
|
||
| 2. **Chaibot responds in a thread within 30-60 seconds** with: | ||
| - Which step(s) failed | ||
| - Root cause analysis (product bug, test issue, or infrastructure) | ||
| - Related Jira tickets | ||
| - Pass rate history | ||
| - Recommended fixes | ||
|
|
||
| ## Configuration | ||
|
|
||
| **Deployment configuration is in openshift/release#80559:** | ||
|
|
||
| - `core-services/ci-chat-bot/triage-config.yaml` - Main config: | ||
| - Monitored channels (e.g., `#opp-discussion`) | ||
| - Ship-help MCP endpoint | ||
| - Analysis prompt template | ||
| - Rate limiting settings | ||
|
|
||
| - `clusters/app.ci/ci-chat-bot/ci-chat-bot.yaml` - Deployment: | ||
| - Environment variables: `SHIP_HELP_MCP_URL`, `SHIP_HELP_MCP_TOKEN` | ||
| - ConfigMap mount: `/etc/triage-config/triage-config.yaml` | ||
|
|
||
| ## How to Enable Chaibot | ||
|
|
||
| Chaibot is enabled via **command-line flags** (not environment variables): | ||
|
|
||
| **Command-line flags (required):** | ||
| - `--enable-triage` - Enable Chaibot functionality | ||
| - `--triage-config-path=/etc/triage-config/triage-config.yaml` - Path to config file | ||
|
|
||
| **Environment variables (required):** | ||
| - `SHIP_HELP_MCP_URL` - Ship-help MCP endpoint | ||
| - `SHIP_HELP_MCP_TOKEN` - Authentication token (from Kubernetes secret) | ||
|
|
||
| **Example deployment command:** | ||
| ```yaml | ||
| # In clusters/app.ci/ci-chat-bot/ci-chat-bot.yaml | ||
| args: | ||
| - --enable-triage | ||
| - --triage-config-path=/etc/triage-config/triage-config.yaml | ||
| env: | ||
| - name: SHIP_HELP_MCP_URL | ||
| value: "https://ship-help-mcp-continuous-release-tooling--ship-help-bot.apps.gpc.ocp-hub.prod.psi.redhat.com/personas/ocp_ai_helpdesk/mcp" | ||
| - name: SHIP_HELP_MCP_TOKEN | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: cluster-secrets-chaibot-ship-help | ||
| key: ship-help-token | ||
| ``` | ||
|
|
||
| **Without these flags, Chaibot will NOT activate** - even if environment variables are set. | ||
|
|
||
| ## Related PRs | ||
|
|
||
| - **This PR (openshift/ci-tools#5251)** - Chaibot implementation (analyzer, handler, router, main.go) | ||
| - **openshift/release#80559** - Configuration and deployment (config files, secrets, ConfigMaps) | ||
| - Based on `/analyze-failure` skill by MPEX Integrity team | ||
| - Alternative to PR openshift/release#80476 (OpenAI approach) | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| User posts Prow URL in Slack | ||
| ↓ | ||
| Slack Event API → ci-chat-bot deployment | ||
| ↓ | ||
| pkg/slack/events/chaibot/handler.go | ||
| - Detects Prow URL | ||
| - Extracts job URL | ||
| ↓ | ||
| pkg/chaibot/analyzer.go | ||
| - Calls ship-help MCP (ask_persona tool) | ||
| - Sends prompt with job URL | ||
| ↓ | ||
| Ship-Help MCP (ocp_ai_helpdesk persona) | ||
| - Searches Jira, Sippy, Prow logs | ||
| - Analyzes failure | ||
| - Returns comprehensive analysis | ||
| ↓ | ||
| pkg/chaibot/analyzer.go | ||
| - Formats response as Slack Block Kit | ||
| ↓ | ||
| Slack API | ||
| - Posts analysis in thread | ||
| ``` | ||
|
|
||
| ## Cost Comparison | ||
|
|
||
| | Solution | Cost | Data Sources | | ||
| |----------|------|--------------| | ||
| | **Chaibot (ship-help MCP)** | $0/month | 9+ sources (Jira, Sippy, Prow, GitHub, etc.) | | ||
| | OpenAI GPT-4o (PR #80476) | ~$1,080/year | 3 sources (limited context) | | ||
|
|
||
| **Chaibot uses internal Red Hat infrastructure** - no external API costs. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.