chore: import upstream snapshot with attribution
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""PostgreSQL Current Queries Tool."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from core.tool_framework.tool_decorator import tool
|
||||
from core.tool_framework.utils.sql_wrapper import call_db_tool_with_default_db_warning
|
||||
from integrations.postgresql import (
|
||||
get_current_queries,
|
||||
postgresql_extract_params,
|
||||
postgresql_is_available,
|
||||
resolve_postgresql_config,
|
||||
)
|
||||
|
||||
|
||||
@tool(
|
||||
name="get_postgresql_current_queries",
|
||||
description=(
|
||||
"Retrieve currently executing PostgreSQL queries above a specific duration threshold."
|
||||
),
|
||||
source="postgresql",
|
||||
surfaces=("investigation", "chat"),
|
||||
use_cases=[
|
||||
"Identifying long-running queries that may be causing performance issues",
|
||||
"Investigating database locks and blocking queries during incidents",
|
||||
"Finding resource-intensive queries correlating with alert timeframes",
|
||||
],
|
||||
is_available=postgresql_is_available,
|
||||
injected_params=("host",),
|
||||
extract_params=postgresql_extract_params,
|
||||
)
|
||||
def get_postgresql_current_queries(
|
||||
host: str,
|
||||
database: str | None = None,
|
||||
threshold_seconds: int = 1,
|
||||
port: int = 5432,
|
||||
) -> dict[str, Any]:
|
||||
"""Fetch currently running queries above the threshold (default 1 second)."""
|
||||
return call_db_tool_with_default_db_warning(
|
||||
database=database,
|
||||
default_db_name="postgres",
|
||||
config_resolver=resolve_postgresql_config,
|
||||
resolver_kwargs={"host": host, "port": port},
|
||||
db_caller=lambda config: get_current_queries(config, threshold_seconds=threshold_seconds),
|
||||
)
|
||||
@@ -0,0 +1,52 @@
|
||||
"""PostgreSQL Locks Tool."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from core.tool_framework.tool_decorator import tool
|
||||
from core.tool_framework.utils.sql_wrapper import call_db_tool_with_default_db_warning
|
||||
from integrations.postgresql import (
|
||||
get_lock_status,
|
||||
postgresql_extract_params,
|
||||
postgresql_is_available,
|
||||
resolve_postgresql_config,
|
||||
)
|
||||
|
||||
|
||||
@tool(
|
||||
name="get_postgresql_lock_status",
|
||||
description=(
|
||||
"Retrieve active PostgreSQL locks and blocking relationships, including"
|
||||
" blocked queries, their blockers, and a summary of lock types."
|
||||
),
|
||||
source="postgresql",
|
||||
surfaces=("investigation", "chat"),
|
||||
use_cases=[
|
||||
"Diagnosing query blocking chains during performance incidents",
|
||||
"Identifying deadlock-prone transactions or long-held locks",
|
||||
"Investigating sudden latency spikes caused by lock contention",
|
||||
],
|
||||
source_id="postgresql_pg_locks",
|
||||
evidence_type="query_stats",
|
||||
side_effect_level="read_only",
|
||||
examples=[
|
||||
"Check for blocked queries causing application timeouts.",
|
||||
"Find which query is blocking a deployment migration.",
|
||||
],
|
||||
anti_examples=["Use this tool for disk usage or slow query history analysis."],
|
||||
is_available=postgresql_is_available,
|
||||
injected_params=("host",),
|
||||
extract_params=postgresql_extract_params,
|
||||
)
|
||||
def get_postgresql_lock_status(
|
||||
host: str,
|
||||
database: str | None = None,
|
||||
port: int = 5432,
|
||||
) -> dict[str, Any]:
|
||||
"""Fetch active lock and blocking chain information from a PostgreSQL instance."""
|
||||
return call_db_tool_with_default_db_warning(
|
||||
database=database,
|
||||
default_db_name="postgres",
|
||||
config_resolver=resolve_postgresql_config,
|
||||
resolver_kwargs={"host": host, "port": port},
|
||||
db_caller=get_lock_status,
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
"""PostgreSQL Replication Status Tool."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from core.tool_framework.tool_decorator import tool
|
||||
from core.tool_framework.utils.sql_wrapper import call_db_tool_with_default_db_warning
|
||||
from integrations.postgresql import (
|
||||
get_replication_status,
|
||||
postgresql_extract_params,
|
||||
postgresql_is_available,
|
||||
resolve_postgresql_config,
|
||||
)
|
||||
|
||||
|
||||
@tool(
|
||||
name="get_postgresql_replication_status",
|
||||
description="Retrieve PostgreSQL replication status including replica lag, WAL positions, and streaming status.",
|
||||
source="postgresql",
|
||||
surfaces=("investigation", "chat"),
|
||||
use_cases=[
|
||||
"Investigating replication lag issues during database incidents",
|
||||
"Checking replica health and synchronization status",
|
||||
"Monitoring WAL streaming and replica connectivity problems",
|
||||
],
|
||||
is_available=postgresql_is_available,
|
||||
injected_params=("host",),
|
||||
extract_params=postgresql_extract_params,
|
||||
)
|
||||
def get_postgresql_replication_status(
|
||||
host: str,
|
||||
database: str | None = None,
|
||||
port: int = 5432,
|
||||
) -> dict[str, Any]:
|
||||
"""Fetch replication status from a PostgreSQL primary server."""
|
||||
return call_db_tool_with_default_db_warning(
|
||||
database=database,
|
||||
default_db_name="postgres",
|
||||
config_resolver=resolve_postgresql_config,
|
||||
resolver_kwargs={"host": host, "port": port},
|
||||
db_caller=get_replication_status,
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
"""PostgreSQL Server Status Tool."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from core.tool_framework.tool_decorator import tool
|
||||
from core.tool_framework.utils.sql_wrapper import call_db_tool_with_default_db_warning
|
||||
from integrations.postgresql import (
|
||||
get_server_status,
|
||||
postgresql_extract_params,
|
||||
postgresql_is_available,
|
||||
resolve_postgresql_config,
|
||||
)
|
||||
|
||||
|
||||
@tool(
|
||||
name="get_postgresql_server_status",
|
||||
description="Retrieve PostgreSQL server metrics including connections, transactions, cache hit ratio, and database statistics.",
|
||||
source="postgresql",
|
||||
surfaces=("investigation", "chat"),
|
||||
use_cases=[
|
||||
"Checking PostgreSQL server health during an incident",
|
||||
"Identifying connection saturation or exhaustion issues",
|
||||
"Reviewing transaction rates and cache efficiency metrics",
|
||||
],
|
||||
is_available=postgresql_is_available,
|
||||
injected_params=("host",),
|
||||
extract_params=postgresql_extract_params,
|
||||
)
|
||||
def get_postgresql_server_status(
|
||||
host: str,
|
||||
database: str | None = None,
|
||||
port: int = 5432,
|
||||
) -> dict[str, Any]:
|
||||
"""Fetch server status metrics from a PostgreSQL instance."""
|
||||
return call_db_tool_with_default_db_warning(
|
||||
database=database,
|
||||
default_db_name="postgres",
|
||||
config_resolver=resolve_postgresql_config,
|
||||
resolver_kwargs={"host": host, "port": port},
|
||||
db_caller=get_server_status,
|
||||
)
|
||||
@@ -0,0 +1,89 @@
|
||||
"""PostgreSQL Slow Queries Tool."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from core.tool_framework.tool_decorator import tool
|
||||
from core.tool_framework.utils.sql_wrapper import call_db_tool_with_default_db_warning
|
||||
from integrations.postgresql import (
|
||||
get_slow_queries,
|
||||
postgresql_extract_params,
|
||||
postgresql_is_available,
|
||||
resolve_postgresql_config,
|
||||
)
|
||||
|
||||
|
||||
class PostgreSQLSlowQueriesInput(BaseModel):
|
||||
host: str = Field(description="PostgreSQL host or endpoint name.")
|
||||
database: str | None = Field(
|
||||
default=None,
|
||||
description="Target database name. Defaults to integration database when omitted.",
|
||||
)
|
||||
threshold_ms: int = Field(
|
||||
default=1000,
|
||||
description="Minimum mean execution time (ms) for query inclusion.",
|
||||
)
|
||||
port: int = Field(default=5432, description="PostgreSQL TCP port.")
|
||||
|
||||
|
||||
class PostgreSQLSlowQueriesOutput(BaseModel):
|
||||
source: str = Field(description="Evidence source label.")
|
||||
available: bool = Field(description="Whether query stats were retrieved.")
|
||||
queries: list[dict[str, Any]] = Field(
|
||||
default_factory=list,
|
||||
description="Slow query rows ranked by mean execution time.",
|
||||
)
|
||||
total_queries: int = Field(default=0, description="Number of slow query rows returned.")
|
||||
threshold_ms: int | None = Field(default=None, description="Applied threshold in ms.")
|
||||
database: str | None = Field(default=None, description="Database queried for stats.")
|
||||
default_db_warning: str | None = Field(
|
||||
default=None,
|
||||
description="Warning emitted when the default database fallback is used.",
|
||||
)
|
||||
error: str | None = Field(default=None, description="Error details when query fails.")
|
||||
|
||||
|
||||
@tool(
|
||||
name="get_postgresql_slow_queries",
|
||||
description=(
|
||||
"Retrieve slow PostgreSQL queries from pg_stat_statements extension, ranked"
|
||||
" by mean execution time."
|
||||
),
|
||||
source="postgresql",
|
||||
surfaces=("investigation", "chat"),
|
||||
use_cases=[
|
||||
"Identifying slow queries that may be causing performance degradation",
|
||||
"Analyzing query execution patterns during incident timeframes",
|
||||
"Finding poorly optimized queries with high execution times or low cache hit rates",
|
||||
],
|
||||
source_id="postgresql_pg_stat_statements",
|
||||
evidence_type="query_stats",
|
||||
side_effect_level="read_only",
|
||||
examples=[
|
||||
"List slow queries above 1000ms to diagnose database latency spikes.",
|
||||
"Lower threshold to 200ms to inspect emerging query regressions.",
|
||||
],
|
||||
anti_examples=["Use this tool for pod restart loops or Kubernetes health checks."],
|
||||
input_model=PostgreSQLSlowQueriesInput,
|
||||
output_model=PostgreSQLSlowQueriesOutput,
|
||||
is_available=postgresql_is_available,
|
||||
injected_params=("host",),
|
||||
extract_params=postgresql_extract_params,
|
||||
)
|
||||
def get_postgresql_slow_queries(
|
||||
host: str,
|
||||
database: str | None = None,
|
||||
threshold_ms: int = 1000,
|
||||
port: int = 5432,
|
||||
) -> dict[str, Any]:
|
||||
"""Fetch slow query statistics above the threshold (default 1000ms mean time)."""
|
||||
return call_db_tool_with_default_db_warning(
|
||||
database=database,
|
||||
default_db_name="postgres",
|
||||
config_resolver=resolve_postgresql_config,
|
||||
resolver_kwargs={"host": host, "port": port},
|
||||
db_caller=lambda config: get_slow_queries(config, threshold_ms=threshold_ms),
|
||||
)
|
||||
@@ -0,0 +1,42 @@
|
||||
"""PostgreSQL Table Stats Tool."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from core.tool_framework.tool_decorator import tool
|
||||
from core.tool_framework.utils.sql_wrapper import call_db_tool_with_default_db_warning
|
||||
from integrations.postgresql import (
|
||||
get_table_stats,
|
||||
postgresql_extract_params,
|
||||
postgresql_is_available,
|
||||
resolve_postgresql_config,
|
||||
)
|
||||
|
||||
|
||||
@tool(
|
||||
name="get_postgresql_table_stats",
|
||||
description="Retrieve PostgreSQL table statistics including size, row counts, index usage, and maintenance info.",
|
||||
source="postgresql",
|
||||
surfaces=("investigation", "chat"),
|
||||
use_cases=[
|
||||
"Identifying large tables or rapid table growth during storage incidents",
|
||||
"Analyzing table scan patterns and index usage efficiency",
|
||||
"Checking table maintenance status like vacuum and analyze operations",
|
||||
],
|
||||
is_available=postgresql_is_available,
|
||||
injected_params=("host",),
|
||||
extract_params=postgresql_extract_params,
|
||||
)
|
||||
def get_postgresql_table_stats(
|
||||
host: str,
|
||||
database: str | None = None,
|
||||
schema_name: str = "public",
|
||||
port: int = 5432,
|
||||
) -> dict[str, Any]:
|
||||
"""Fetch table statistics for a specific schema (default 'public')."""
|
||||
return call_db_tool_with_default_db_warning(
|
||||
database=database,
|
||||
default_db_name="postgres",
|
||||
config_resolver=resolve_postgresql_config,
|
||||
resolver_kwargs={"host": host, "port": port},
|
||||
db_caller=lambda config: get_table_stats(config, schema_name=schema_name),
|
||||
)
|
||||
Reference in New Issue
Block a user