Skip to content

feat(rds): enhance error logs query functionality #2

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 70 additions & 24 deletions src/rds_openapi_mcp_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,6 @@ async def describe_db_instance_attribute(region_id: str, db_instance_id: str):
raise e


@mcp.tool()
def describe_error_logs(region_id: str, db_instance_id: str, start_time: datetime, end_time: datetime):
"""
Queries the error log of an instance.
Args:
region_id: db instance region(e.g. cn-hangzhou)
db_instance_id: db instance id(e.g. rm-xxx)
start_time: start time UTC TimeZone (e.g. 2023-01-01T00:00Z)
end_time: end time UTC TimeZone (e.g. 2023-01-01T00:00Z)
"""
client = get_rds_client(region_id)
try:
request = rds_20140815_models.DescribeErrorLogsRequest(
dbinstance_id=db_instance_id,
start_time=transform_to_iso_8601(start_time, "minutes"),
end_time=transform_to_iso_8601(end_time, "minutes"),
page_size=100,
)
response = client.describe_error_logs(request)
return response.to_map()
except Exception as e:
raise e


@mcp.tool()
async def describe_db_instance_performance(region_id: str, db_instance_id: str, db_type: str, perf_key: str, start_time: str, end_time: str):
"""
Expand Down Expand Up @@ -812,6 +788,76 @@ async def describe_slow_log_records(
raise OpenAPIError(f"Failed to query slow log records: {str(e)}")


@mcp.tool()
async def describe_error_logs(
region_id: str,
db_instance_id: str,
start_time: str,
end_time: str,
page_size: int = 30,
page_number: int = 1
) -> Dict[str, Any]:
"""
Query error logs of an RDS instance.

Args:
region_id (str): The region ID of the RDS instance.
db_instance_id (str): The ID of the RDS instance.
start_time (str): The start time of the query. Format: yyyy-MM-ddTHH:mmZ (UTC time).
end_time (str): The end time of the query. Format: yyyy-MM-ddTHH:mmZ (UTC time).
page_size (int): The number of records per page. Range: 30~100. Default: 30.
page_number (int): The page number. Default: 1.

Returns:
Dict[str, Any]: A dictionary containing error log information with the following structure:
{
"Items": {
"ErrorLog": [
{
"CreateTime": "2011-05-30T12:11:04Z",
"ErrorInfo": "Error log content"
}
]
},
"PageNumber": 1,
"PageRecordCount": 30,
"TotalRecordCount": 100,
"RequestId": "98504E07-BB0E-40FC-B152-E4882615812C"
}

Raises:
OpenAPIError: If the API call fails or returns an error.
"""
try:
client = get_rds_client(region_id)
request = rds_20140815_models.DescribeErrorLogsRequest(
dbinstance_id=db_instance_id,
start_time=start_time,
end_time=end_time,
page_size=page_size,
page_number=page_number
)
response = await client.describe_error_logs_async(request)
return {
"Items": {
"ErrorLog": [
{
"CreateTime": log.create_time,
"ErrorInfo": log.error_info
}
for log in response.body.items.error_log
]
},
"PageNumber": response.body.page_number,
"PageRecordCount": response.body.page_record_count,
"TotalRecordCount": response.body.total_record_count,
"RequestId": response.body.request_id
}
except Exception as e:
logger.error(f"Failed to describe error logs: {str(e)}")
raise OpenAPIError(f"Failed to describe error logs: {str(e)}")


@mcp.tool()
async def get_current_time() -> Dict[str, Any]:
"""Get the current time.
Expand Down