|
2 | 2 | import asyncio
|
3 | 3 | from typing import Any, Optional, Dict
|
4 | 4 | from dateutil.parser import parse as parse_date
|
| 5 | +import re |
5 | 6 |
|
6 | 7 | from drain import DrainExtractor
|
7 | 8 |
|
8 | 9 | import httpx
|
9 |
| -from mcp.server.fastmcp import FastMCP |
| 10 | +from fastmcp import FastMCP |
10 | 11 |
|
11 |
| -mcp = FastMCP("prow-mcp-server") |
| 12 | +mcp = FastMCP(name="prow-mcp-server", stateless_http=True, host="0.0.0.0", port=9000) |
12 | 13 |
|
13 | 14 | GCS_URL = "https://gcsweb-ci.apps.ci.l2s4.p1.openshiftapps.com/gcs/test-platform-results/logs"
|
14 | 15 |
|
15 | 16 | _drain_extractor: Optional['DrainExtractor'] = None
|
16 | 17 |
|
| 18 | +def extract_installation_info(log_content: str) -> Dict[str, Any]: |
| 19 | + """Extract installation information from build-log.txt.""" |
| 20 | + install_info = { |
| 21 | + "installer_version": None, |
| 22 | + "installer_commit": None, |
| 23 | + "release_image": None, |
| 24 | + "instance_types": {}, |
| 25 | + "install_duration": None, |
| 26 | + "architecture": None, |
| 27 | + "cluster_config": {}, |
| 28 | + "install_success": False |
| 29 | + } |
| 30 | + |
| 31 | + # Extract openshift-install version and commit (can be on separate lines) |
| 32 | + version_patterns = [ |
| 33 | + r'openshift-install v([^\s"]+)', |
| 34 | + r'"openshift-install v([^\s"]+)"' |
| 35 | + ] |
| 36 | + |
| 37 | + for pattern in version_patterns: |
| 38 | + version_match = re.search(pattern, log_content) |
| 39 | + if version_match: |
| 40 | + install_info["installer_version"] = version_match.group(1) |
| 41 | + break |
| 42 | + |
| 43 | + # Extract commit (separate pattern) |
| 44 | + commit_patterns = [ |
| 45 | + r'built from commit ([a-f0-9]+)', |
| 46 | + r'"built from commit ([a-f0-9]+)"' |
| 47 | + ] |
| 48 | + |
| 49 | + for pattern in commit_patterns: |
| 50 | + commit_match = re.search(pattern, log_content) |
| 51 | + if commit_match: |
| 52 | + install_info["installer_commit"] = commit_match.group(1) |
| 53 | + break |
| 54 | + |
| 55 | + # Extract release image |
| 56 | + release_patterns = [ |
| 57 | + r'Installing from release ([^\s]+)', |
| 58 | + r'release image "([^"]+)"', |
| 59 | + r'RELEASE_IMAGE_LATEST for release image "([^"]+)"' |
| 60 | + ] |
| 61 | + for pattern in release_patterns: |
| 62 | + release_match = re.search(pattern, log_content) |
| 63 | + if release_match: |
| 64 | + install_info["release_image"] = release_match.group(1) |
| 65 | + break |
| 66 | + |
| 67 | + # Extract instance types from install-config.yaml section |
| 68 | + # Look for compute and controlPlane sections |
| 69 | + compute_type_pattern = r'compute:.*?type:\s*([^\s\n]+)' |
| 70 | + control_type_pattern = r'controlPlane:.*?type:\s*([^\s\n]+)' |
| 71 | + |
| 72 | + compute_match = re.search(compute_type_pattern, log_content, re.DOTALL) |
| 73 | + if compute_match: |
| 74 | + install_info["instance_types"]["compute"] = compute_match.group(1) |
| 75 | + |
| 76 | + control_match = re.search(control_type_pattern, log_content, re.DOTALL) |
| 77 | + if control_match: |
| 78 | + install_info["instance_types"]["control_plane"] = control_match.group(1) |
| 79 | + |
| 80 | + # Extract architecture |
| 81 | + arch_pattern = r'architecture:\s*([^\s\n]+)' |
| 82 | + arch_match = re.search(arch_pattern, log_content) |
| 83 | + if arch_match: |
| 84 | + install_info["architecture"] = arch_match.group(1) |
| 85 | + |
| 86 | + # Extract cluster configuration details |
| 87 | + # Replicas |
| 88 | + compute_replicas_pattern = r'compute:.*?replicas:\s*(\d+)' |
| 89 | + control_replicas_pattern = r'controlPlane:.*?replicas:\s*(\d+)' |
| 90 | + |
| 91 | + compute_replicas_match = re.search(compute_replicas_pattern, log_content, re.DOTALL) |
| 92 | + if compute_replicas_match: |
| 93 | + install_info["cluster_config"]["compute_replicas"] = int(compute_replicas_match.group(1)) |
| 94 | + |
| 95 | + control_replicas_match = re.search(control_replicas_pattern, log_content, re.DOTALL) |
| 96 | + if control_replicas_match: |
| 97 | + install_info["cluster_config"]["control_replicas"] = int(control_replicas_match.group(1)) |
| 98 | + |
| 99 | + # Network type |
| 100 | + network_pattern = r'networkType:\s*([^\s\n]+)' |
| 101 | + network_match = re.search(network_pattern, log_content) |
| 102 | + if network_match: |
| 103 | + install_info["cluster_config"]["network_type"] = network_match.group(1) |
| 104 | + |
| 105 | + # Platform and region |
| 106 | + platform_pattern = r'platform:\s*([^\s\n]+):' |
| 107 | + region_pattern = r'region:\s*([^\s\n]+)' |
| 108 | + |
| 109 | + platform_match = re.search(platform_pattern, log_content) |
| 110 | + if platform_match: |
| 111 | + install_info["cluster_config"]["platform"] = platform_match.group(1) |
| 112 | + |
| 113 | + region_match = re.search(region_pattern, log_content) |
| 114 | + if region_match: |
| 115 | + install_info["cluster_config"]["region"] = region_match.group(1) |
| 116 | + |
| 117 | + # Extract install duration (clean up quotes) |
| 118 | + duration_patterns = [ |
| 119 | + r'Time elapsed:\s*([^\n"]+)', |
| 120 | + r'Install complete!.*?Time elapsed:\s*([^\n"]+)' |
| 121 | + ] |
| 122 | + |
| 123 | + for pattern in duration_patterns: |
| 124 | + duration_match = re.search(pattern, log_content, re.DOTALL) |
| 125 | + if duration_match: |
| 126 | + duration = duration_match.group(1).strip().strip('"') |
| 127 | + install_info["install_duration"] = duration |
| 128 | + break |
| 129 | + |
| 130 | + # Check if installation was successful |
| 131 | + if "Install complete!" in log_content: |
| 132 | + install_info["install_success"] = True |
| 133 | + elif "level=error" in log_content or "FATAL" in log_content: |
| 134 | + install_info["install_success"] = False |
| 135 | + |
| 136 | + return install_info |
| 137 | + |
17 | 138 | async def make_request(
|
18 | 139 | url: str, method: str = "GET", data: dict[str, Any] = None
|
19 | 140 | ) -> dict[str, Any] | None:
|
@@ -64,10 +185,7 @@ async def get_job_metadata(job_name: str, build_id: str) -> dict:
|
64 | 185 | for arg in args:
|
65 | 186 | if arg.startswith("--target="):
|
66 | 187 | test_name=arg.replace("--target=","")
|
67 |
| - |
68 |
| - |
69 |
| - |
70 |
| - |
| 188 | + |
71 | 189 | return {"status": status, "build_id": build_id, "job_name": job_name, "test_name": test_name}
|
72 | 190 |
|
73 | 191 | except Exception as e:
|
@@ -247,5 +365,6 @@ async def get_install_logs(job_name: str, build_id: str, test_name: str):
|
247 | 365 | # print(result)
|
248 | 366 |
|
249 | 367 | if __name__ == "__main__":
|
250 |
| -# asyncio.run(main()) |
251 |
| - mcp.run(transport=os.environ.get("MCP_TRANSPORT", "stdio")) |
| 368 | + # mcp.streamable_http_app() |
| 369 | + mcp.run(transport="streamable-http", host="0.0.0.0", port=9000) |
| 370 | + |
0 commit comments