Copilot commented on code in PR #1319:
URL: https://github.com/apache/dubbo-admin/pull/1319#discussion_r2314122132
##########
ai/internal/tools/mock_tools.go:
##########
@@ -0,0 +1,623 @@
+package tools
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/firebase/genkit/go/ai"
+ "github.com/firebase/genkit/go/genkit"
+)
+
+// ================================================
+// Prometheus Query Service Latency Tool
+// ================================================
+type ToolOutput interface {
+ Tool() string
+}
+
+type PrometheusServiceLatencyInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+ Quantile float64 `json:"quantile"
jsonschema:"required,description=Quantile to query (e.g., 0.99 or 0.95)"`
+}
+
+type PrometheusServiceLatencyOutput struct {
+ ToolName string `json:"toolName"`
+ Quantile float64 `json:"quantile"`
+ ValueMillis int `json:"valueMillis"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceLatencyOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceLatency(ctx *ai.ToolContext, input
PrometheusServiceLatencyInput) (PrometheusServiceLatencyOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_latency' called for service:
%s", input.ServiceName)
+
+ // Mock data based on the example in prompt
+ valueMillis := 3500
+ if input.ServiceName != "order-service" {
+ valueMillis = 850
+ }
+
+ return PrometheusServiceLatencyOutput{
+ ToolName: "prometheus_query_service_latency",
+ Quantile: input.Quantile,
+ ValueMillis: valueMillis,
+ Summary: fmt.Sprintf("服务 %s 在过去%d分钟内的 P%.0f 延迟为 %dms",
input.ServiceName, input.TimeRangeMinutes, input.Quantile*100, valueMillis),
+ }, nil
+}
+
+// ================================================
+// Prometheus Query Service Traffic Tool
+// ================================================
+
+type PrometheusServiceTrafficInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type PrometheusServiceTrafficOutput struct {
+ ToolName string `json:"toolName"`
+ RequestRateQPS float64 `json:"requestRateQPS"`
+ ErrorRatePercentage float64 `json:"errorRatePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceTrafficOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceTraffic(ctx *ai.ToolContext, input
PrometheusServiceTrafficInput) (PrometheusServiceTrafficOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_traffic' called for service:
%s", input.ServiceName)
+
+ return PrometheusServiceTrafficOutput{
+ ToolName: "prometheus_query_service_traffic",
+ RequestRateQPS: 250.0,
+ ErrorRatePercentage: 5.2,
+ Summary: fmt.Sprintf("服务 %s 的 QPS 为 250, 错误率为
5.2%%", input.ServiceName),
+ }, nil
+}
+
+// ================================================
+// Query Timeseries Database Tool
+// ================================================
+
+type QueryTimeseriesDatabaseInput struct {
+ PromqlQuery string `json:"promqlQuery"
jsonschema:"required,description=PromQL query to execute"`
+}
+
+type TimeseriesMetric struct {
+ Pod string `json:"pod"`
+}
+
+type TimeseriesValue struct {
+ Timestamp int64 `json:"timestamp"`
+ Value string `json:"value"`
+}
+
+type TimeseriesResult struct {
+ Metric TimeseriesMetric `json:"metric"`
+ Value TimeseriesValue `json:"value"`
+}
+
+type QueryTimeseriesDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ Query string `json:"query"`
+ Results []TimeseriesResult `json:"results"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryTimeseriesDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryTimeseriesDatabase(ctx *ai.ToolContext, input
QueryTimeseriesDatabaseInput) (QueryTimeseriesDatabaseOutput, error) {
+ log.Printf("Tool 'query_timeseries_database' called with query: %s",
input.PromqlQuery)
+
+ return QueryTimeseriesDatabaseOutput{
+ ToolName: "query_timeseries_database",
+ Query: input.PromqlQuery,
+ Results: []TimeseriesResult{
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-1"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.5"},
+ },
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-2"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.2"},
+ },
+ },
+ Summary: "查询返回了 2 个时间序列",
+ }, nil
+}
+
+// ================================================
+// Application Performance Profiling Tool
+// ================================================
+
+type ApplicationPerformanceProfilingInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to profile"`
+ PodName string `json:"podName"
jsonschema:"required,description=The specific pod name to profile"`
+ DurationSeconds int `json:"durationSeconds"
jsonschema:"required,description=Duration of profiling in seconds"`
+}
+
+type PerformanceHotspot struct {
+ CPUTimePercentage float64 `json:"cpuTimePercentage"`
+ StackTrace []string `json:"stackTrace"`
+}
+
+type ApplicationPerformanceProfilingOutput struct {
+ ToolName string `json:"toolName"`
+ Status string `json:"status"`
+ TotalSamples int `json:"totalSamples"`
+ Hotspots []PerformanceHotspot `json:"hotspots"`
+ Summary string `json:"summary"`
+}
+
+func (o ApplicationPerformanceProfilingOutput) Tool() string {
+ return o.ToolName
+}
+
+func applicationPerformanceProfiling(ctx *ai.ToolContext, input
ApplicationPerformanceProfilingInput) (ApplicationPerformanceProfilingOutput,
error) {
+ log.Printf("Tool 'application_performance_profiling' called for
service: %s, pod: %s", input.ServiceName, input.PodName)
+
+ return ApplicationPerformanceProfilingOutput{
+ ToolName: "application_performance_profiling",
+ Status: "completed",
+ TotalSamples: 10000,
+ Hotspots: []PerformanceHotspot{
+ {
+ CPUTimePercentage: 45.5,
+ StackTrace: []string{
+
"com.example.OrderService.processOrder()",
+ "com.example.DatabaseClient.query()",
+
"java.sql.PreparedStatement.executeQuery()",
+ },
+ },
+ },
+ Summary: "性能分析显示,45.5%的CPU时间消耗在数据库查询调用链上",
+ }, nil
+}
+
+// ================================================
+// JVM Performance Analysis Tool
+// ================================================
+
+type JVMPerformanceAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Java service to analyze"`
+ PodName string `json:"podName" jsonschema:"required,description=The
specific pod name to analyze"`
+}
+
+type JVMPerformanceAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ FullGcCountLastHour int `json:"fullGcCountLastHour"`
+ FullGcTimeAvgMillis int `json:"fullGcTimeAvgMillis"`
+ HeapUsagePercentage float64 `json:"heapUsagePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o JVMPerformanceAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func jvmPerformanceAnalysis(ctx *ai.ToolContext, input
JVMPerformanceAnalysisInput) (JVMPerformanceAnalysisOutput, error) {
+ log.Printf("Tool 'jvm_performance_analysis' called for service: %s,
pod: %s", input.ServiceName, input.PodName)
+
+ return JVMPerformanceAnalysisOutput{
+ ToolName: "jvm_performance_analysis",
+ FullGcCountLastHour: 15,
+ FullGcTimeAvgMillis: 1200,
+ HeapUsagePercentage: 85.5,
+ Summary: "GC activity is high, average Full GC time
is 1200ms",
+ }, nil
+}
+
+// ================================================
+// Trace Dependency View Tool
+// ================================================
+
+type TraceDependencyViewInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze
dependencies"`
+}
+
+type TraceDependencyViewOutput struct {
+ ToolName string `json:"toolName"`
+ UpstreamServices []string `json:"upstreamServices"`
+ DownstreamServices []string `json:"downstreamServices"`
+}
+
+func (o TraceDependencyViewOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceDependencyView(ctx *ai.ToolContext, input TraceDependencyViewInput)
(TraceDependencyViewOutput, error) {
+ log.Printf("Tool 'trace_dependency_view' called for service: %s",
input.ServiceName)
+
+ return TraceDependencyViewOutput{
+ ToolName: "trace_dependency_view",
+ UpstreamServices: []string{"api-gateway", "user-service"},
+ DownstreamServices: []string{"mysql-orders-db", "redis-cache",
"payment-service"},
+ }, nil
+}
+
+// ================================================
+// Trace Latency Analysis Tool
+// ================================================
+
+type TraceLatencyAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LatencyBottleneck struct {
+ DownstreamService string `json:"downstreamService"`
+ LatencyAvgMillis int `json:"latencyAvgMillis"`
+ ContributionPercentage float64 `json:"contributionPercentage"`
+}
+
+type TraceLatencyAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ TotalLatencyAvgMillis int `json:"totalLatencyAvgMillis"`
+ Bottlenecks []LatencyBottleneck `json:"bottlenecks"`
+ Summary string `json:"summary"`
+}
+
+func (o TraceLatencyAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceLatencyAnalysis(ctx *ai.ToolContext, input
TraceLatencyAnalysisInput) (TraceLatencyAnalysisOutput, error) {
+ log.Printf("Tool 'trace_latency_analysis' called for service: %s",
input.ServiceName)
+
+ return TraceLatencyAnalysisOutput{
+ ToolName: "trace_latency_analysis",
+ TotalLatencyAvgMillis: 3200,
+ Bottlenecks: []LatencyBottleneck{
+ {
+ DownstreamService: "mysql-orders-db",
+ LatencyAvgMillis: 3050,
+ ContributionPercentage: 95.3,
+ },
+ {
+ DownstreamService: "user-service",
+ LatencyAvgMillis: 150,
+ ContributionPercentage: 4.7,
+ },
+ },
+ Summary: "平均总延迟为 3200ms。瓶颈已定位,95.3% 的延迟来自对下游 'mysql-orders-db'
的调用",
+ }, nil
+}
+
+// ================================================
+// Database Connection Pool Analysis Tool
+// ================================================
+
+type DatabaseConnectionPoolAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+}
+
+type DatabaseConnectionPoolAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ MaxConnections int `json:"maxConnections"`
+ ActiveConnections int `json:"activeConnections"`
+ IdleConnections int `json:"idleConnections"`
+ PendingRequests int `json:"pendingRequests"`
+ Summary string `json:"summary"`
+}
+
+func (o DatabaseConnectionPoolAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func databaseConnectionPoolAnalysis(ctx *ai.ToolContext, input
DatabaseConnectionPoolAnalysisInput) (DatabaseConnectionPoolAnalysisOutput,
error) {
+ log.Printf("Tool 'database_connection_pool_analysis' called for
service: %s", input.ServiceName)
+
+ return DatabaseConnectionPoolAnalysisOutput{
+ ToolName: "database_connection_pool_analysis",
+ MaxConnections: 100,
+ ActiveConnections: 100,
+ IdleConnections: 0,
+ PendingRequests: 58,
+ Summary: "数据库连接池已完全耗尽 (100/100),当前有 58 个请求正在排队等待连接",
+ }, nil
+}
+
+// ================================================
+// Kubernetes Get Pod Resources Tool
+// ================================================
+
+type KubernetesGetPodResourcesInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Namespace string `json:"namespace"
jsonschema:"required,description=The namespace of the service"`
+}
+
+type PodResource struct {
+ PodName string `json:"podName"`
+ CPUUsageCores float64 `json:"cpuUsageCores"`
+ CPURequestCores float64 `json:"cpuRequestCores"`
+ CPULimitCores float64 `json:"cpuLimitCores"`
+ MemoryUsageMi int `json:"memoryUsageMi"`
+ MemoryRequestMi int `json:"memoryRequestMi"`
+ MemoryLimitMi int `json:"memoryLimitMi"`
+}
+
+type KubernetesGetPodResourcesOutput struct {
+ ToolName string `json:"toolName"`
+ Pods []PodResource `json:"pods"`
+ Summary string `json:"summary"`
+}
+
+func (o KubernetesGetPodResourcesOutput) Tool() string {
+ return o.ToolName
+}
+
+func kubernetesGetPodResources(ctx *ai.ToolContext, input
KubernetesGetPodResourcesInput) (KubernetesGetPodResourcesOutput, error) {
+ log.Printf("Tool 'kubernetes_get_pod_resources' called for service: %s
in namespace: %s", input.ServiceName, input.Namespace)
+
+ return KubernetesGetPodResourcesOutput{
+ ToolName: "kubernetes_get_pod_resources",
+ Pods: []PodResource{
+ {
+ PodName: "order-service-pod-1",
+ CPUUsageCores: 0.8,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1800,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ {
+ PodName: "order-service-pod-2",
+ CPUUsageCores: 0.9,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1950,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ },
+ Summary: "2 out of 2 pods are near their memory limits",
+ }, nil
+}
+
+// ================================================
+// Dubbo Service Status Tool
+// ================================================
+
+type DubboServiceStatusInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Dubbo service"`
+}
+
+type DubboProvider struct {
+ IP string `json:"ip"`
+ Port int `json:"port"`
+ Status string `json:"status"`
+}
+
+type DubboConsumer struct {
+ IP string `json:"ip"`
+ Application string `json:"application"`
+ Status string `json:"status"`
+}
+
+type DubboServiceStatusOutput struct {
+ ToolName string `json:"toolName"`
+ Providers []DubboProvider `json:"providers"`
+ Consumers []DubboConsumer `json:"consumers"`
+}
+
+func (o DubboServiceStatusOutput) Tool() string {
+ return o.ToolName
+}
+
+func dubboServiceStatus(ctx *ai.ToolContext, input DubboServiceStatusInput)
(DubboServiceStatusOutput, error) {
+ log.Printf("Tool 'dubbo_service_status' called for service: %s",
input.ServiceName)
+
+ return DubboServiceStatusOutput{
+ ToolName: "dubbo_service_status",
+ Providers: []DubboProvider{
+ {IP: "192.168.1.10", Port: 20880, Status: "healthy"},
+ {IP: "192.168.1.11", Port: 20880, Status: "healthy"},
+ },
+ Consumers: []DubboConsumer{
+ {IP: "192.168.1.20", Application: "web-frontend",
Status: "connected"},
+ {IP: "192.168.1.21", Application: "api-gateway",
Status: "connected"},
+ },
+ }, nil
+}
+
+// ================================================
+// Query Log Database Tool
+// ================================================
+
+type QueryLogDatabaseInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Keyword string `json:"keyword"
jsonschema:"required,description=Keyword to search for"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LogEntry struct {
+ Timestamp string `json:"timestamp"`
+ Level string `json:"level"`
+ Message string `json:"message"`
+}
+
+type QueryLogDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ TotalHits int `json:"totalHits"`
+ Logs []LogEntry `json:"logs"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryLogDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryLogDatabase(ctx *ai.ToolContext, input QueryLogDatabaseInput)
(QueryLogDatabaseOutput, error) {
+ log.Printf("Tool 'query_log_database' called for service: %s, keyword:
%s", input.ServiceName, input.Keyword)
+
+ return QueryLogDatabaseOutput{
+ ToolName: "query_log_database",
+ TotalHits: 152,
+ Logs: []LogEntry{
+ {
+ Timestamp: "2025-08-16T15:32:05Z",
+ Level: "WARN",
+ Message: "Timeout waiting for idle object in
database connection pool.",
+ },
+ {
+ Timestamp: "2025-08-16T15:32:08Z",
Review Comment:
The hardcoded timestamps reference August 2025, which may be confusing since
the current date context is September 2025. Consider using relative timestamps
or the current date range for more realistic mock data.
##########
ai/internal/tools/mock_tools.go:
##########
@@ -0,0 +1,623 @@
+package tools
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/firebase/genkit/go/ai"
+ "github.com/firebase/genkit/go/genkit"
+)
+
+// ================================================
+// Prometheus Query Service Latency Tool
+// ================================================
+type ToolOutput interface {
+ Tool() string
+}
+
+type PrometheusServiceLatencyInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+ Quantile float64 `json:"quantile"
jsonschema:"required,description=Quantile to query (e.g., 0.99 or 0.95)"`
+}
+
+type PrometheusServiceLatencyOutput struct {
+ ToolName string `json:"toolName"`
+ Quantile float64 `json:"quantile"`
+ ValueMillis int `json:"valueMillis"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceLatencyOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceLatency(ctx *ai.ToolContext, input
PrometheusServiceLatencyInput) (PrometheusServiceLatencyOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_latency' called for service:
%s", input.ServiceName)
+
+ // Mock data based on the example in prompt
+ valueMillis := 3500
+ if input.ServiceName != "order-service" {
+ valueMillis = 850
+ }
+
+ return PrometheusServiceLatencyOutput{
+ ToolName: "prometheus_query_service_latency",
+ Quantile: input.Quantile,
+ ValueMillis: valueMillis,
+ Summary: fmt.Sprintf("服务 %s 在过去%d分钟内的 P%.0f 延迟为 %dms",
input.ServiceName, input.TimeRangeMinutes, input.Quantile*100, valueMillis),
+ }, nil
+}
+
+// ================================================
+// Prometheus Query Service Traffic Tool
+// ================================================
+
+type PrometheusServiceTrafficInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type PrometheusServiceTrafficOutput struct {
+ ToolName string `json:"toolName"`
+ RequestRateQPS float64 `json:"requestRateQPS"`
+ ErrorRatePercentage float64 `json:"errorRatePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceTrafficOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceTraffic(ctx *ai.ToolContext, input
PrometheusServiceTrafficInput) (PrometheusServiceTrafficOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_traffic' called for service:
%s", input.ServiceName)
+
+ return PrometheusServiceTrafficOutput{
+ ToolName: "prometheus_query_service_traffic",
+ RequestRateQPS: 250.0,
+ ErrorRatePercentage: 5.2,
+ Summary: fmt.Sprintf("服务 %s 的 QPS 为 250, 错误率为
5.2%%", input.ServiceName),
+ }, nil
+}
+
+// ================================================
+// Query Timeseries Database Tool
+// ================================================
+
+type QueryTimeseriesDatabaseInput struct {
+ PromqlQuery string `json:"promqlQuery"
jsonschema:"required,description=PromQL query to execute"`
+}
+
+type TimeseriesMetric struct {
+ Pod string `json:"pod"`
+}
+
+type TimeseriesValue struct {
+ Timestamp int64 `json:"timestamp"`
+ Value string `json:"value"`
+}
+
+type TimeseriesResult struct {
+ Metric TimeseriesMetric `json:"metric"`
+ Value TimeseriesValue `json:"value"`
+}
+
+type QueryTimeseriesDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ Query string `json:"query"`
+ Results []TimeseriesResult `json:"results"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryTimeseriesDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryTimeseriesDatabase(ctx *ai.ToolContext, input
QueryTimeseriesDatabaseInput) (QueryTimeseriesDatabaseOutput, error) {
+ log.Printf("Tool 'query_timeseries_database' called with query: %s",
input.PromqlQuery)
+
+ return QueryTimeseriesDatabaseOutput{
+ ToolName: "query_timeseries_database",
+ Query: input.PromqlQuery,
+ Results: []TimeseriesResult{
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-1"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.5"},
+ },
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-2"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.2"},
+ },
+ },
+ Summary: "查询返回了 2 个时间序列",
+ }, nil
+}
+
+// ================================================
+// Application Performance Profiling Tool
+// ================================================
+
+type ApplicationPerformanceProfilingInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to profile"`
+ PodName string `json:"podName"
jsonschema:"required,description=The specific pod name to profile"`
+ DurationSeconds int `json:"durationSeconds"
jsonschema:"required,description=Duration of profiling in seconds"`
+}
+
+type PerformanceHotspot struct {
+ CPUTimePercentage float64 `json:"cpuTimePercentage"`
+ StackTrace []string `json:"stackTrace"`
+}
+
+type ApplicationPerformanceProfilingOutput struct {
+ ToolName string `json:"toolName"`
+ Status string `json:"status"`
+ TotalSamples int `json:"totalSamples"`
+ Hotspots []PerformanceHotspot `json:"hotspots"`
+ Summary string `json:"summary"`
+}
+
+func (o ApplicationPerformanceProfilingOutput) Tool() string {
+ return o.ToolName
+}
+
+func applicationPerformanceProfiling(ctx *ai.ToolContext, input
ApplicationPerformanceProfilingInput) (ApplicationPerformanceProfilingOutput,
error) {
+ log.Printf("Tool 'application_performance_profiling' called for
service: %s, pod: %s", input.ServiceName, input.PodName)
+
+ return ApplicationPerformanceProfilingOutput{
+ ToolName: "application_performance_profiling",
+ Status: "completed",
+ TotalSamples: 10000,
+ Hotspots: []PerformanceHotspot{
+ {
+ CPUTimePercentage: 45.5,
+ StackTrace: []string{
+
"com.example.OrderService.processOrder()",
+ "com.example.DatabaseClient.query()",
+
"java.sql.PreparedStatement.executeQuery()",
+ },
+ },
+ },
+ Summary: "性能分析显示,45.5%的CPU时间消耗在数据库查询调用链上",
+ }, nil
+}
+
+// ================================================
+// JVM Performance Analysis Tool
+// ================================================
+
+type JVMPerformanceAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Java service to analyze"`
+ PodName string `json:"podName" jsonschema:"required,description=The
specific pod name to analyze"`
+}
+
+type JVMPerformanceAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ FullGcCountLastHour int `json:"fullGcCountLastHour"`
+ FullGcTimeAvgMillis int `json:"fullGcTimeAvgMillis"`
+ HeapUsagePercentage float64 `json:"heapUsagePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o JVMPerformanceAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func jvmPerformanceAnalysis(ctx *ai.ToolContext, input
JVMPerformanceAnalysisInput) (JVMPerformanceAnalysisOutput, error) {
+ log.Printf("Tool 'jvm_performance_analysis' called for service: %s,
pod: %s", input.ServiceName, input.PodName)
+
+ return JVMPerformanceAnalysisOutput{
+ ToolName: "jvm_performance_analysis",
+ FullGcCountLastHour: 15,
+ FullGcTimeAvgMillis: 1200,
+ HeapUsagePercentage: 85.5,
+ Summary: "GC activity is high, average Full GC time
is 1200ms",
+ }, nil
+}
+
+// ================================================
+// Trace Dependency View Tool
+// ================================================
+
+type TraceDependencyViewInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze
dependencies"`
+}
+
+type TraceDependencyViewOutput struct {
+ ToolName string `json:"toolName"`
+ UpstreamServices []string `json:"upstreamServices"`
+ DownstreamServices []string `json:"downstreamServices"`
+}
+
+func (o TraceDependencyViewOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceDependencyView(ctx *ai.ToolContext, input TraceDependencyViewInput)
(TraceDependencyViewOutput, error) {
+ log.Printf("Tool 'trace_dependency_view' called for service: %s",
input.ServiceName)
+
+ return TraceDependencyViewOutput{
+ ToolName: "trace_dependency_view",
+ UpstreamServices: []string{"api-gateway", "user-service"},
+ DownstreamServices: []string{"mysql-orders-db", "redis-cache",
"payment-service"},
+ }, nil
+}
+
+// ================================================
+// Trace Latency Analysis Tool
+// ================================================
+
+type TraceLatencyAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LatencyBottleneck struct {
+ DownstreamService string `json:"downstreamService"`
+ LatencyAvgMillis int `json:"latencyAvgMillis"`
+ ContributionPercentage float64 `json:"contributionPercentage"`
+}
+
+type TraceLatencyAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ TotalLatencyAvgMillis int `json:"totalLatencyAvgMillis"`
+ Bottlenecks []LatencyBottleneck `json:"bottlenecks"`
+ Summary string `json:"summary"`
+}
+
+func (o TraceLatencyAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceLatencyAnalysis(ctx *ai.ToolContext, input
TraceLatencyAnalysisInput) (TraceLatencyAnalysisOutput, error) {
+ log.Printf("Tool 'trace_latency_analysis' called for service: %s",
input.ServiceName)
+
+ return TraceLatencyAnalysisOutput{
+ ToolName: "trace_latency_analysis",
+ TotalLatencyAvgMillis: 3200,
+ Bottlenecks: []LatencyBottleneck{
+ {
+ DownstreamService: "mysql-orders-db",
+ LatencyAvgMillis: 3050,
+ ContributionPercentage: 95.3,
+ },
+ {
+ DownstreamService: "user-service",
+ LatencyAvgMillis: 150,
+ ContributionPercentage: 4.7,
+ },
+ },
+ Summary: "平均总延迟为 3200ms。瓶颈已定位,95.3% 的延迟来自对下游 'mysql-orders-db'
的调用",
+ }, nil
+}
+
+// ================================================
+// Database Connection Pool Analysis Tool
+// ================================================
+
+type DatabaseConnectionPoolAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+}
+
+type DatabaseConnectionPoolAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ MaxConnections int `json:"maxConnections"`
+ ActiveConnections int `json:"activeConnections"`
+ IdleConnections int `json:"idleConnections"`
+ PendingRequests int `json:"pendingRequests"`
+ Summary string `json:"summary"`
+}
+
+func (o DatabaseConnectionPoolAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func databaseConnectionPoolAnalysis(ctx *ai.ToolContext, input
DatabaseConnectionPoolAnalysisInput) (DatabaseConnectionPoolAnalysisOutput,
error) {
+ log.Printf("Tool 'database_connection_pool_analysis' called for
service: %s", input.ServiceName)
+
+ return DatabaseConnectionPoolAnalysisOutput{
+ ToolName: "database_connection_pool_analysis",
+ MaxConnections: 100,
+ ActiveConnections: 100,
+ IdleConnections: 0,
+ PendingRequests: 58,
+ Summary: "数据库连接池已完全耗尽 (100/100),当前有 58 个请求正在排队等待连接",
+ }, nil
+}
+
+// ================================================
+// Kubernetes Get Pod Resources Tool
+// ================================================
+
+type KubernetesGetPodResourcesInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Namespace string `json:"namespace"
jsonschema:"required,description=The namespace of the service"`
+}
+
+type PodResource struct {
+ PodName string `json:"podName"`
+ CPUUsageCores float64 `json:"cpuUsageCores"`
+ CPURequestCores float64 `json:"cpuRequestCores"`
+ CPULimitCores float64 `json:"cpuLimitCores"`
+ MemoryUsageMi int `json:"memoryUsageMi"`
+ MemoryRequestMi int `json:"memoryRequestMi"`
+ MemoryLimitMi int `json:"memoryLimitMi"`
+}
+
+type KubernetesGetPodResourcesOutput struct {
+ ToolName string `json:"toolName"`
+ Pods []PodResource `json:"pods"`
+ Summary string `json:"summary"`
+}
+
+func (o KubernetesGetPodResourcesOutput) Tool() string {
+ return o.ToolName
+}
+
+func kubernetesGetPodResources(ctx *ai.ToolContext, input
KubernetesGetPodResourcesInput) (KubernetesGetPodResourcesOutput, error) {
+ log.Printf("Tool 'kubernetes_get_pod_resources' called for service: %s
in namespace: %s", input.ServiceName, input.Namespace)
+
+ return KubernetesGetPodResourcesOutput{
+ ToolName: "kubernetes_get_pod_resources",
+ Pods: []PodResource{
+ {
+ PodName: "order-service-pod-1",
+ CPUUsageCores: 0.8,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1800,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ {
+ PodName: "order-service-pod-2",
+ CPUUsageCores: 0.9,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1950,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ },
+ Summary: "2 out of 2 pods are near their memory limits",
+ }, nil
+}
+
+// ================================================
+// Dubbo Service Status Tool
+// ================================================
+
+type DubboServiceStatusInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Dubbo service"`
+}
+
+type DubboProvider struct {
+ IP string `json:"ip"`
+ Port int `json:"port"`
+ Status string `json:"status"`
+}
+
+type DubboConsumer struct {
+ IP string `json:"ip"`
+ Application string `json:"application"`
+ Status string `json:"status"`
+}
+
+type DubboServiceStatusOutput struct {
+ ToolName string `json:"toolName"`
+ Providers []DubboProvider `json:"providers"`
+ Consumers []DubboConsumer `json:"consumers"`
+}
+
+func (o DubboServiceStatusOutput) Tool() string {
+ return o.ToolName
+}
+
+func dubboServiceStatus(ctx *ai.ToolContext, input DubboServiceStatusInput)
(DubboServiceStatusOutput, error) {
+ log.Printf("Tool 'dubbo_service_status' called for service: %s",
input.ServiceName)
+
+ return DubboServiceStatusOutput{
+ ToolName: "dubbo_service_status",
+ Providers: []DubboProvider{
+ {IP: "192.168.1.10", Port: 20880, Status: "healthy"},
+ {IP: "192.168.1.11", Port: 20880, Status: "healthy"},
+ },
+ Consumers: []DubboConsumer{
+ {IP: "192.168.1.20", Application: "web-frontend",
Status: "connected"},
+ {IP: "192.168.1.21", Application: "api-gateway",
Status: "connected"},
+ },
+ }, nil
+}
+
+// ================================================
+// Query Log Database Tool
+// ================================================
+
+type QueryLogDatabaseInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Keyword string `json:"keyword"
jsonschema:"required,description=Keyword to search for"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LogEntry struct {
+ Timestamp string `json:"timestamp"`
+ Level string `json:"level"`
+ Message string `json:"message"`
+}
+
+type QueryLogDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ TotalHits int `json:"totalHits"`
+ Logs []LogEntry `json:"logs"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryLogDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryLogDatabase(ctx *ai.ToolContext, input QueryLogDatabaseInput)
(QueryLogDatabaseOutput, error) {
+ log.Printf("Tool 'query_log_database' called for service: %s, keyword:
%s", input.ServiceName, input.Keyword)
+
+ return QueryLogDatabaseOutput{
+ ToolName: "query_log_database",
+ TotalHits: 152,
+ Logs: []LogEntry{
+ {
+ Timestamp: "2025-08-16T15:32:05Z",
Review Comment:
The hardcoded timestamps reference August 2025, which may be confusing since
the current date context is September 2025. Consider using relative timestamps
or the current date range for more realistic mock data.
##########
ai/internal/tools/mock_tools.go:
##########
@@ -0,0 +1,623 @@
+package tools
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/firebase/genkit/go/ai"
+ "github.com/firebase/genkit/go/genkit"
+)
+
+// ================================================
+// Prometheus Query Service Latency Tool
+// ================================================
+type ToolOutput interface {
+ Tool() string
+}
+
+type PrometheusServiceLatencyInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+ Quantile float64 `json:"quantile"
jsonschema:"required,description=Quantile to query (e.g., 0.99 or 0.95)"`
+}
+
+type PrometheusServiceLatencyOutput struct {
+ ToolName string `json:"toolName"`
+ Quantile float64 `json:"quantile"`
+ ValueMillis int `json:"valueMillis"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceLatencyOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceLatency(ctx *ai.ToolContext, input
PrometheusServiceLatencyInput) (PrometheusServiceLatencyOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_latency' called for service:
%s", input.ServiceName)
+
+ // Mock data based on the example in prompt
+ valueMillis := 3500
+ if input.ServiceName != "order-service" {
+ valueMillis = 850
+ }
+
+ return PrometheusServiceLatencyOutput{
+ ToolName: "prometheus_query_service_latency",
+ Quantile: input.Quantile,
+ ValueMillis: valueMillis,
+ Summary: fmt.Sprintf("服务 %s 在过去%d分钟内的 P%.0f 延迟为 %dms",
input.ServiceName, input.TimeRangeMinutes, input.Quantile*100, valueMillis),
+ }, nil
+}
+
+// ================================================
+// Prometheus Query Service Traffic Tool
+// ================================================
+
+type PrometheusServiceTrafficInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type PrometheusServiceTrafficOutput struct {
+ ToolName string `json:"toolName"`
+ RequestRateQPS float64 `json:"requestRateQPS"`
+ ErrorRatePercentage float64 `json:"errorRatePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceTrafficOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceTraffic(ctx *ai.ToolContext, input
PrometheusServiceTrafficInput) (PrometheusServiceTrafficOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_traffic' called for service:
%s", input.ServiceName)
+
+ return PrometheusServiceTrafficOutput{
+ ToolName: "prometheus_query_service_traffic",
+ RequestRateQPS: 250.0,
+ ErrorRatePercentage: 5.2,
+ Summary: fmt.Sprintf("服务 %s 的 QPS 为 250, 错误率为
5.2%%", input.ServiceName),
+ }, nil
+}
+
+// ================================================
+// Query Timeseries Database Tool
+// ================================================
+
+type QueryTimeseriesDatabaseInput struct {
+ PromqlQuery string `json:"promqlQuery"
jsonschema:"required,description=PromQL query to execute"`
+}
+
+type TimeseriesMetric struct {
+ Pod string `json:"pod"`
+}
+
+type TimeseriesValue struct {
+ Timestamp int64 `json:"timestamp"`
+ Value string `json:"value"`
+}
+
+type TimeseriesResult struct {
+ Metric TimeseriesMetric `json:"metric"`
+ Value TimeseriesValue `json:"value"`
+}
+
+type QueryTimeseriesDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ Query string `json:"query"`
+ Results []TimeseriesResult `json:"results"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryTimeseriesDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryTimeseriesDatabase(ctx *ai.ToolContext, input
QueryTimeseriesDatabaseInput) (QueryTimeseriesDatabaseOutput, error) {
+ log.Printf("Tool 'query_timeseries_database' called with query: %s",
input.PromqlQuery)
+
+ return QueryTimeseriesDatabaseOutput{
+ ToolName: "query_timeseries_database",
+ Query: input.PromqlQuery,
+ Results: []TimeseriesResult{
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-1"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.5"},
+ },
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-2"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.2"},
+ },
+ },
+ Summary: "查询返回了 2 个时间序列",
+ }, nil
+}
+
+// ================================================
+// Application Performance Profiling Tool
+// ================================================
+
+type ApplicationPerformanceProfilingInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to profile"`
+ PodName string `json:"podName"
jsonschema:"required,description=The specific pod name to profile"`
+ DurationSeconds int `json:"durationSeconds"
jsonschema:"required,description=Duration of profiling in seconds"`
+}
+
+type PerformanceHotspot struct {
+ CPUTimePercentage float64 `json:"cpuTimePercentage"`
+ StackTrace []string `json:"stackTrace"`
+}
+
+type ApplicationPerformanceProfilingOutput struct {
+ ToolName string `json:"toolName"`
+ Status string `json:"status"`
+ TotalSamples int `json:"totalSamples"`
+ Hotspots []PerformanceHotspot `json:"hotspots"`
+ Summary string `json:"summary"`
+}
+
+func (o ApplicationPerformanceProfilingOutput) Tool() string {
+ return o.ToolName
+}
+
+func applicationPerformanceProfiling(ctx *ai.ToolContext, input
ApplicationPerformanceProfilingInput) (ApplicationPerformanceProfilingOutput,
error) {
+ log.Printf("Tool 'application_performance_profiling' called for
service: %s, pod: %s", input.ServiceName, input.PodName)
+
+ return ApplicationPerformanceProfilingOutput{
+ ToolName: "application_performance_profiling",
+ Status: "completed",
+ TotalSamples: 10000,
+ Hotspots: []PerformanceHotspot{
+ {
+ CPUTimePercentage: 45.5,
+ StackTrace: []string{
+
"com.example.OrderService.processOrder()",
+ "com.example.DatabaseClient.query()",
+
"java.sql.PreparedStatement.executeQuery()",
+ },
+ },
+ },
+ Summary: "性能分析显示,45.5%的CPU时间消耗在数据库查询调用链上",
+ }, nil
+}
+
+// ================================================
+// JVM Performance Analysis Tool
+// ================================================
+
+type JVMPerformanceAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Java service to analyze"`
+ PodName string `json:"podName" jsonschema:"required,description=The
specific pod name to analyze"`
+}
+
+type JVMPerformanceAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ FullGcCountLastHour int `json:"fullGcCountLastHour"`
+ FullGcTimeAvgMillis int `json:"fullGcTimeAvgMillis"`
+ HeapUsagePercentage float64 `json:"heapUsagePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o JVMPerformanceAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func jvmPerformanceAnalysis(ctx *ai.ToolContext, input
JVMPerformanceAnalysisInput) (JVMPerformanceAnalysisOutput, error) {
+ log.Printf("Tool 'jvm_performance_analysis' called for service: %s,
pod: %s", input.ServiceName, input.PodName)
+
+ return JVMPerformanceAnalysisOutput{
+ ToolName: "jvm_performance_analysis",
+ FullGcCountLastHour: 15,
+ FullGcTimeAvgMillis: 1200,
+ HeapUsagePercentage: 85.5,
+ Summary: "GC activity is high, average Full GC time
is 1200ms",
+ }, nil
+}
+
+// ================================================
+// Trace Dependency View Tool
+// ================================================
+
+type TraceDependencyViewInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze
dependencies"`
+}
+
+type TraceDependencyViewOutput struct {
+ ToolName string `json:"toolName"`
+ UpstreamServices []string `json:"upstreamServices"`
+ DownstreamServices []string `json:"downstreamServices"`
+}
+
+func (o TraceDependencyViewOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceDependencyView(ctx *ai.ToolContext, input TraceDependencyViewInput)
(TraceDependencyViewOutput, error) {
+ log.Printf("Tool 'trace_dependency_view' called for service: %s",
input.ServiceName)
+
+ return TraceDependencyViewOutput{
+ ToolName: "trace_dependency_view",
+ UpstreamServices: []string{"api-gateway", "user-service"},
+ DownstreamServices: []string{"mysql-orders-db", "redis-cache",
"payment-service"},
+ }, nil
+}
+
+// ================================================
+// Trace Latency Analysis Tool
+// ================================================
+
+type TraceLatencyAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LatencyBottleneck struct {
+ DownstreamService string `json:"downstreamService"`
+ LatencyAvgMillis int `json:"latencyAvgMillis"`
+ ContributionPercentage float64 `json:"contributionPercentage"`
+}
+
+type TraceLatencyAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ TotalLatencyAvgMillis int `json:"totalLatencyAvgMillis"`
+ Bottlenecks []LatencyBottleneck `json:"bottlenecks"`
+ Summary string `json:"summary"`
+}
+
+func (o TraceLatencyAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceLatencyAnalysis(ctx *ai.ToolContext, input
TraceLatencyAnalysisInput) (TraceLatencyAnalysisOutput, error) {
+ log.Printf("Tool 'trace_latency_analysis' called for service: %s",
input.ServiceName)
+
+ return TraceLatencyAnalysisOutput{
+ ToolName: "trace_latency_analysis",
+ TotalLatencyAvgMillis: 3200,
+ Bottlenecks: []LatencyBottleneck{
+ {
+ DownstreamService: "mysql-orders-db",
+ LatencyAvgMillis: 3050,
+ ContributionPercentage: 95.3,
+ },
+ {
+ DownstreamService: "user-service",
+ LatencyAvgMillis: 150,
+ ContributionPercentage: 4.7,
+ },
+ },
+ Summary: "平均总延迟为 3200ms。瓶颈已定位,95.3% 的延迟来自对下游 'mysql-orders-db'
的调用",
+ }, nil
+}
+
+// ================================================
+// Database Connection Pool Analysis Tool
+// ================================================
+
+type DatabaseConnectionPoolAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+}
+
+type DatabaseConnectionPoolAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ MaxConnections int `json:"maxConnections"`
+ ActiveConnections int `json:"activeConnections"`
+ IdleConnections int `json:"idleConnections"`
+ PendingRequests int `json:"pendingRequests"`
+ Summary string `json:"summary"`
+}
+
+func (o DatabaseConnectionPoolAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func databaseConnectionPoolAnalysis(ctx *ai.ToolContext, input
DatabaseConnectionPoolAnalysisInput) (DatabaseConnectionPoolAnalysisOutput,
error) {
+ log.Printf("Tool 'database_connection_pool_analysis' called for
service: %s", input.ServiceName)
+
+ return DatabaseConnectionPoolAnalysisOutput{
+ ToolName: "database_connection_pool_analysis",
+ MaxConnections: 100,
+ ActiveConnections: 100,
+ IdleConnections: 0,
+ PendingRequests: 58,
+ Summary: "数据库连接池已完全耗尽 (100/100),当前有 58 个请求正在排队等待连接",
+ }, nil
+}
+
+// ================================================
+// Kubernetes Get Pod Resources Tool
+// ================================================
+
+type KubernetesGetPodResourcesInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Namespace string `json:"namespace"
jsonschema:"required,description=The namespace of the service"`
+}
+
+type PodResource struct {
+ PodName string `json:"podName"`
+ CPUUsageCores float64 `json:"cpuUsageCores"`
+ CPURequestCores float64 `json:"cpuRequestCores"`
+ CPULimitCores float64 `json:"cpuLimitCores"`
+ MemoryUsageMi int `json:"memoryUsageMi"`
+ MemoryRequestMi int `json:"memoryRequestMi"`
+ MemoryLimitMi int `json:"memoryLimitMi"`
+}
+
+type KubernetesGetPodResourcesOutput struct {
+ ToolName string `json:"toolName"`
+ Pods []PodResource `json:"pods"`
+ Summary string `json:"summary"`
+}
+
+func (o KubernetesGetPodResourcesOutput) Tool() string {
+ return o.ToolName
+}
+
+func kubernetesGetPodResources(ctx *ai.ToolContext, input
KubernetesGetPodResourcesInput) (KubernetesGetPodResourcesOutput, error) {
+ log.Printf("Tool 'kubernetes_get_pod_resources' called for service: %s
in namespace: %s", input.ServiceName, input.Namespace)
+
+ return KubernetesGetPodResourcesOutput{
+ ToolName: "kubernetes_get_pod_resources",
+ Pods: []PodResource{
+ {
+ PodName: "order-service-pod-1",
+ CPUUsageCores: 0.8,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1800,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ {
+ PodName: "order-service-pod-2",
+ CPUUsageCores: 0.9,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1950,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ },
+ Summary: "2 out of 2 pods are near their memory limits",
+ }, nil
+}
+
+// ================================================
+// Dubbo Service Status Tool
+// ================================================
+
+type DubboServiceStatusInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Dubbo service"`
+}
+
+type DubboProvider struct {
+ IP string `json:"ip"`
+ Port int `json:"port"`
+ Status string `json:"status"`
+}
+
+type DubboConsumer struct {
+ IP string `json:"ip"`
+ Application string `json:"application"`
+ Status string `json:"status"`
+}
+
+type DubboServiceStatusOutput struct {
+ ToolName string `json:"toolName"`
+ Providers []DubboProvider `json:"providers"`
+ Consumers []DubboConsumer `json:"consumers"`
+}
+
+func (o DubboServiceStatusOutput) Tool() string {
+ return o.ToolName
+}
+
+func dubboServiceStatus(ctx *ai.ToolContext, input DubboServiceStatusInput)
(DubboServiceStatusOutput, error) {
+ log.Printf("Tool 'dubbo_service_status' called for service: %s",
input.ServiceName)
+
+ return DubboServiceStatusOutput{
+ ToolName: "dubbo_service_status",
+ Providers: []DubboProvider{
+ {IP: "192.168.1.10", Port: 20880, Status: "healthy"},
+ {IP: "192.168.1.11", Port: 20880, Status: "healthy"},
+ },
+ Consumers: []DubboConsumer{
+ {IP: "192.168.1.20", Application: "web-frontend",
Status: "connected"},
+ {IP: "192.168.1.21", Application: "api-gateway",
Status: "connected"},
+ },
+ }, nil
+}
+
+// ================================================
+// Query Log Database Tool
+// ================================================
+
+type QueryLogDatabaseInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Keyword string `json:"keyword"
jsonschema:"required,description=Keyword to search for"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LogEntry struct {
+ Timestamp string `json:"timestamp"`
+ Level string `json:"level"`
+ Message string `json:"message"`
+}
+
+type QueryLogDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ TotalHits int `json:"totalHits"`
+ Logs []LogEntry `json:"logs"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryLogDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryLogDatabase(ctx *ai.ToolContext, input QueryLogDatabaseInput)
(QueryLogDatabaseOutput, error) {
+ log.Printf("Tool 'query_log_database' called for service: %s, keyword:
%s", input.ServiceName, input.Keyword)
+
+ return QueryLogDatabaseOutput{
+ ToolName: "query_log_database",
+ TotalHits: 152,
+ Logs: []LogEntry{
+ {
+ Timestamp: "2025-08-16T15:32:05Z",
+ Level: "WARN",
+ Message: "Timeout waiting for idle object in
database connection pool.",
+ },
+ {
+ Timestamp: "2025-08-16T15:32:08Z",
+ Level: "WARN",
+ Message: "Timeout waiting for idle object in
database connection pool.",
+ },
+ },
+ Summary: fmt.Sprintf("在过去%d分钟内,发现 152 条关于 '%s' 的日志条目",
input.TimeRangeMinutes, input.Keyword),
+ }, nil
+}
+
+// ================================================
+// Search Archived Logs Tool
+// ================================================
+
+type SearchArchivedLogsInput struct {
+ FilePathPattern string `json:"filePathPattern"
jsonschema:"required,description=File path pattern to search"`
+ GrepKeyword string `json:"grepKeyword"
jsonschema:"required,description=Keyword to grep for"`
+}
+
+type MatchingLine struct {
+ FilePath string `json:"filePath"`
+ LineNumber int `json:"lineNumber"`
+ LineContent string `json:"lineContent"`
+}
+
+type SearchArchivedLogsOutput struct {
+ ToolName string `json:"toolName"`
+ FilesSearched int `json:"filesSearched"`
+ MatchingLines []MatchingLine `json:"matchingLines"`
+ Summary string `json:"summary"`
+}
+
+func (o SearchArchivedLogsOutput) Tool() string {
+ return o.ToolName
+}
+
+func searchArchivedLogs(ctx *ai.ToolContext, input SearchArchivedLogsInput)
(SearchArchivedLogsOutput, error) {
+ log.Printf("Tool 'search_archived_logs' called with pattern: %s,
keyword: %s", input.FilePathPattern, input.GrepKeyword)
+
+ return SearchArchivedLogsOutput{
+ ToolName: "search_archived_logs",
+ FilesSearched: 5,
+ MatchingLines: []MatchingLine{
+ {
+ FilePath:
"/logs/mysql-orders-db/slow-query-2025-08-16.log.gz",
+ LineNumber: 1024,
+ LineContent: "Query_time: 25.3s | SELECT
COUNT(id), SUM(price) FROM orders WHERE user_id = 'VIP_USER_123';",
Review Comment:
The hardcoded timestamps in mock data reference dates from August 2025. For
consistency and to avoid confusion, consider using relative timestamps or
current date ranges.
##########
ai/internal/tools/mock_tools.go:
##########
@@ -0,0 +1,623 @@
+package tools
+
+import (
+ "fmt"
+ "log"
+
+ "github.com/firebase/genkit/go/ai"
+ "github.com/firebase/genkit/go/genkit"
+)
+
+// ================================================
+// Prometheus Query Service Latency Tool
+// ================================================
+type ToolOutput interface {
+ Tool() string
+}
+
+type PrometheusServiceLatencyInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+ Quantile float64 `json:"quantile"
jsonschema:"required,description=Quantile to query (e.g., 0.99 or 0.95)"`
+}
+
+type PrometheusServiceLatencyOutput struct {
+ ToolName string `json:"toolName"`
+ Quantile float64 `json:"quantile"`
+ ValueMillis int `json:"valueMillis"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceLatencyOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceLatency(ctx *ai.ToolContext, input
PrometheusServiceLatencyInput) (PrometheusServiceLatencyOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_latency' called for service:
%s", input.ServiceName)
+
+ // Mock data based on the example in prompt
+ valueMillis := 3500
+ if input.ServiceName != "order-service" {
+ valueMillis = 850
+ }
+
+ return PrometheusServiceLatencyOutput{
+ ToolName: "prometheus_query_service_latency",
+ Quantile: input.Quantile,
+ ValueMillis: valueMillis,
+ Summary: fmt.Sprintf("服务 %s 在过去%d分钟内的 P%.0f 延迟为 %dms",
input.ServiceName, input.TimeRangeMinutes, input.Quantile*100, valueMillis),
+ }, nil
+}
+
+// ================================================
+// Prometheus Query Service Traffic Tool
+// ================================================
+
+type PrometheusServiceTrafficInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to query"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type PrometheusServiceTrafficOutput struct {
+ ToolName string `json:"toolName"`
+ RequestRateQPS float64 `json:"requestRateQPS"`
+ ErrorRatePercentage float64 `json:"errorRatePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o PrometheusServiceTrafficOutput) Tool() string {
+ return o.ToolName
+}
+
+func prometheusQueryServiceTraffic(ctx *ai.ToolContext, input
PrometheusServiceTrafficInput) (PrometheusServiceTrafficOutput, error) {
+ log.Printf("Tool 'prometheus_query_service_traffic' called for service:
%s", input.ServiceName)
+
+ return PrometheusServiceTrafficOutput{
+ ToolName: "prometheus_query_service_traffic",
+ RequestRateQPS: 250.0,
+ ErrorRatePercentage: 5.2,
+ Summary: fmt.Sprintf("服务 %s 的 QPS 为 250, 错误率为
5.2%%", input.ServiceName),
+ }, nil
+}
+
+// ================================================
+// Query Timeseries Database Tool
+// ================================================
+
+type QueryTimeseriesDatabaseInput struct {
+ PromqlQuery string `json:"promqlQuery"
jsonschema:"required,description=PromQL query to execute"`
+}
+
+type TimeseriesMetric struct {
+ Pod string `json:"pod"`
+}
+
+type TimeseriesValue struct {
+ Timestamp int64 `json:"timestamp"`
+ Value string `json:"value"`
+}
+
+type TimeseriesResult struct {
+ Metric TimeseriesMetric `json:"metric"`
+ Value TimeseriesValue `json:"value"`
+}
+
+type QueryTimeseriesDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ Query string `json:"query"`
+ Results []TimeseriesResult `json:"results"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryTimeseriesDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryTimeseriesDatabase(ctx *ai.ToolContext, input
QueryTimeseriesDatabaseInput) (QueryTimeseriesDatabaseOutput, error) {
+ log.Printf("Tool 'query_timeseries_database' called with query: %s",
input.PromqlQuery)
+
+ return QueryTimeseriesDatabaseOutput{
+ ToolName: "query_timeseries_database",
+ Query: input.PromqlQuery,
+ Results: []TimeseriesResult{
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-1"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.5"},
+ },
+ {
+ Metric: TimeseriesMetric{Pod:
"order-service-pod-2"},
+ Value: TimeseriesValue{Timestamp: 1692192000,
Value: "3.2"},
+ },
+ },
+ Summary: "查询返回了 2 个时间序列",
+ }, nil
+}
+
+// ================================================
+// Application Performance Profiling Tool
+// ================================================
+
+type ApplicationPerformanceProfilingInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to profile"`
+ PodName string `json:"podName"
jsonschema:"required,description=The specific pod name to profile"`
+ DurationSeconds int `json:"durationSeconds"
jsonschema:"required,description=Duration of profiling in seconds"`
+}
+
+type PerformanceHotspot struct {
+ CPUTimePercentage float64 `json:"cpuTimePercentage"`
+ StackTrace []string `json:"stackTrace"`
+}
+
+type ApplicationPerformanceProfilingOutput struct {
+ ToolName string `json:"toolName"`
+ Status string `json:"status"`
+ TotalSamples int `json:"totalSamples"`
+ Hotspots []PerformanceHotspot `json:"hotspots"`
+ Summary string `json:"summary"`
+}
+
+func (o ApplicationPerformanceProfilingOutput) Tool() string {
+ return o.ToolName
+}
+
+func applicationPerformanceProfiling(ctx *ai.ToolContext, input
ApplicationPerformanceProfilingInput) (ApplicationPerformanceProfilingOutput,
error) {
+ log.Printf("Tool 'application_performance_profiling' called for
service: %s, pod: %s", input.ServiceName, input.PodName)
+
+ return ApplicationPerformanceProfilingOutput{
+ ToolName: "application_performance_profiling",
+ Status: "completed",
+ TotalSamples: 10000,
+ Hotspots: []PerformanceHotspot{
+ {
+ CPUTimePercentage: 45.5,
+ StackTrace: []string{
+
"com.example.OrderService.processOrder()",
+ "com.example.DatabaseClient.query()",
+
"java.sql.PreparedStatement.executeQuery()",
+ },
+ },
+ },
+ Summary: "性能分析显示,45.5%的CPU时间消耗在数据库查询调用链上",
+ }, nil
+}
+
+// ================================================
+// JVM Performance Analysis Tool
+// ================================================
+
+type JVMPerformanceAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Java service to analyze"`
+ PodName string `json:"podName" jsonschema:"required,description=The
specific pod name to analyze"`
+}
+
+type JVMPerformanceAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ FullGcCountLastHour int `json:"fullGcCountLastHour"`
+ FullGcTimeAvgMillis int `json:"fullGcTimeAvgMillis"`
+ HeapUsagePercentage float64 `json:"heapUsagePercentage"`
+ Summary string `json:"summary"`
+}
+
+func (o JVMPerformanceAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func jvmPerformanceAnalysis(ctx *ai.ToolContext, input
JVMPerformanceAnalysisInput) (JVMPerformanceAnalysisOutput, error) {
+ log.Printf("Tool 'jvm_performance_analysis' called for service: %s,
pod: %s", input.ServiceName, input.PodName)
+
+ return JVMPerformanceAnalysisOutput{
+ ToolName: "jvm_performance_analysis",
+ FullGcCountLastHour: 15,
+ FullGcTimeAvgMillis: 1200,
+ HeapUsagePercentage: 85.5,
+ Summary: "GC activity is high, average Full GC time
is 1200ms",
+ }, nil
+}
+
+// ================================================
+// Trace Dependency View Tool
+// ================================================
+
+type TraceDependencyViewInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze
dependencies"`
+}
+
+type TraceDependencyViewOutput struct {
+ ToolName string `json:"toolName"`
+ UpstreamServices []string `json:"upstreamServices"`
+ DownstreamServices []string `json:"downstreamServices"`
+}
+
+func (o TraceDependencyViewOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceDependencyView(ctx *ai.ToolContext, input TraceDependencyViewInput)
(TraceDependencyViewOutput, error) {
+ log.Printf("Tool 'trace_dependency_view' called for service: %s",
input.ServiceName)
+
+ return TraceDependencyViewOutput{
+ ToolName: "trace_dependency_view",
+ UpstreamServices: []string{"api-gateway", "user-service"},
+ DownstreamServices: []string{"mysql-orders-db", "redis-cache",
"payment-service"},
+ }, nil
+}
+
+// ================================================
+// Trace Latency Analysis Tool
+// ================================================
+
+type TraceLatencyAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LatencyBottleneck struct {
+ DownstreamService string `json:"downstreamService"`
+ LatencyAvgMillis int `json:"latencyAvgMillis"`
+ ContributionPercentage float64 `json:"contributionPercentage"`
+}
+
+type TraceLatencyAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ TotalLatencyAvgMillis int `json:"totalLatencyAvgMillis"`
+ Bottlenecks []LatencyBottleneck `json:"bottlenecks"`
+ Summary string `json:"summary"`
+}
+
+func (o TraceLatencyAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func traceLatencyAnalysis(ctx *ai.ToolContext, input
TraceLatencyAnalysisInput) (TraceLatencyAnalysisOutput, error) {
+ log.Printf("Tool 'trace_latency_analysis' called for service: %s",
input.ServiceName)
+
+ return TraceLatencyAnalysisOutput{
+ ToolName: "trace_latency_analysis",
+ TotalLatencyAvgMillis: 3200,
+ Bottlenecks: []LatencyBottleneck{
+ {
+ DownstreamService: "mysql-orders-db",
+ LatencyAvgMillis: 3050,
+ ContributionPercentage: 95.3,
+ },
+ {
+ DownstreamService: "user-service",
+ LatencyAvgMillis: 150,
+ ContributionPercentage: 4.7,
+ },
+ },
+ Summary: "平均总延迟为 3200ms。瓶颈已定位,95.3% 的延迟来自对下游 'mysql-orders-db'
的调用",
+ }, nil
+}
+
+// ================================================
+// Database Connection Pool Analysis Tool
+// ================================================
+
+type DatabaseConnectionPoolAnalysisInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service to analyze"`
+}
+
+type DatabaseConnectionPoolAnalysisOutput struct {
+ ToolName string `json:"toolName"`
+ MaxConnections int `json:"maxConnections"`
+ ActiveConnections int `json:"activeConnections"`
+ IdleConnections int `json:"idleConnections"`
+ PendingRequests int `json:"pendingRequests"`
+ Summary string `json:"summary"`
+}
+
+func (o DatabaseConnectionPoolAnalysisOutput) Tool() string {
+ return o.ToolName
+}
+
+func databaseConnectionPoolAnalysis(ctx *ai.ToolContext, input
DatabaseConnectionPoolAnalysisInput) (DatabaseConnectionPoolAnalysisOutput,
error) {
+ log.Printf("Tool 'database_connection_pool_analysis' called for
service: %s", input.ServiceName)
+
+ return DatabaseConnectionPoolAnalysisOutput{
+ ToolName: "database_connection_pool_analysis",
+ MaxConnections: 100,
+ ActiveConnections: 100,
+ IdleConnections: 0,
+ PendingRequests: 58,
+ Summary: "数据库连接池已完全耗尽 (100/100),当前有 58 个请求正在排队等待连接",
+ }, nil
+}
+
+// ================================================
+// Kubernetes Get Pod Resources Tool
+// ================================================
+
+type KubernetesGetPodResourcesInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Namespace string `json:"namespace"
jsonschema:"required,description=The namespace of the service"`
+}
+
+type PodResource struct {
+ PodName string `json:"podName"`
+ CPUUsageCores float64 `json:"cpuUsageCores"`
+ CPURequestCores float64 `json:"cpuRequestCores"`
+ CPULimitCores float64 `json:"cpuLimitCores"`
+ MemoryUsageMi int `json:"memoryUsageMi"`
+ MemoryRequestMi int `json:"memoryRequestMi"`
+ MemoryLimitMi int `json:"memoryLimitMi"`
+}
+
+type KubernetesGetPodResourcesOutput struct {
+ ToolName string `json:"toolName"`
+ Pods []PodResource `json:"pods"`
+ Summary string `json:"summary"`
+}
+
+func (o KubernetesGetPodResourcesOutput) Tool() string {
+ return o.ToolName
+}
+
+func kubernetesGetPodResources(ctx *ai.ToolContext, input
KubernetesGetPodResourcesInput) (KubernetesGetPodResourcesOutput, error) {
+ log.Printf("Tool 'kubernetes_get_pod_resources' called for service: %s
in namespace: %s", input.ServiceName, input.Namespace)
+
+ return KubernetesGetPodResourcesOutput{
+ ToolName: "kubernetes_get_pod_resources",
+ Pods: []PodResource{
+ {
+ PodName: "order-service-pod-1",
+ CPUUsageCores: 0.8,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1800,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ {
+ PodName: "order-service-pod-2",
+ CPUUsageCores: 0.9,
+ CPURequestCores: 0.5,
+ CPULimitCores: 1.0,
+ MemoryUsageMi: 1950,
+ MemoryRequestMi: 1024,
+ MemoryLimitMi: 2048,
+ },
+ },
+ Summary: "2 out of 2 pods are near their memory limits",
+ }, nil
+}
+
+// ================================================
+// Dubbo Service Status Tool
+// ================================================
+
+type DubboServiceStatusInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the Dubbo service"`
+}
+
+type DubboProvider struct {
+ IP string `json:"ip"`
+ Port int `json:"port"`
+ Status string `json:"status"`
+}
+
+type DubboConsumer struct {
+ IP string `json:"ip"`
+ Application string `json:"application"`
+ Status string `json:"status"`
+}
+
+type DubboServiceStatusOutput struct {
+ ToolName string `json:"toolName"`
+ Providers []DubboProvider `json:"providers"`
+ Consumers []DubboConsumer `json:"consumers"`
+}
+
+func (o DubboServiceStatusOutput) Tool() string {
+ return o.ToolName
+}
+
+func dubboServiceStatus(ctx *ai.ToolContext, input DubboServiceStatusInput)
(DubboServiceStatusOutput, error) {
+ log.Printf("Tool 'dubbo_service_status' called for service: %s",
input.ServiceName)
+
+ return DubboServiceStatusOutput{
+ ToolName: "dubbo_service_status",
+ Providers: []DubboProvider{
+ {IP: "192.168.1.10", Port: 20880, Status: "healthy"},
+ {IP: "192.168.1.11", Port: 20880, Status: "healthy"},
+ },
+ Consumers: []DubboConsumer{
+ {IP: "192.168.1.20", Application: "web-frontend",
Status: "connected"},
+ {IP: "192.168.1.21", Application: "api-gateway",
Status: "connected"},
+ },
+ }, nil
+}
+
+// ================================================
+// Query Log Database Tool
+// ================================================
+
+type QueryLogDatabaseInput struct {
+ ServiceName string `json:"serviceName"
jsonschema:"required,description=The name of the service"`
+ Keyword string `json:"keyword"
jsonschema:"required,description=Keyword to search for"`
+ TimeRangeMinutes int `json:"timeRangeMinutes"
jsonschema:"required,description=Time range in minutes"`
+}
+
+type LogEntry struct {
+ Timestamp string `json:"timestamp"`
+ Level string `json:"level"`
+ Message string `json:"message"`
+}
+
+type QueryLogDatabaseOutput struct {
+ ToolName string `json:"toolName"`
+ TotalHits int `json:"totalHits"`
+ Logs []LogEntry `json:"logs"`
+ Summary string `json:"summary"`
+}
+
+func (o QueryLogDatabaseOutput) Tool() string {
+ return o.ToolName
+}
+
+func queryLogDatabase(ctx *ai.ToolContext, input QueryLogDatabaseInput)
(QueryLogDatabaseOutput, error) {
+ log.Printf("Tool 'query_log_database' called for service: %s, keyword:
%s", input.ServiceName, input.Keyword)
+
+ return QueryLogDatabaseOutput{
+ ToolName: "query_log_database",
+ TotalHits: 152,
+ Logs: []LogEntry{
+ {
+ Timestamp: "2025-08-16T15:32:05Z",
+ Level: "WARN",
+ Message: "Timeout waiting for idle object in
database connection pool.",
+ },
+ {
+ Timestamp: "2025-08-16T15:32:08Z",
+ Level: "WARN",
+ Message: "Timeout waiting for idle object in
database connection pool.",
+ },
+ },
+ Summary: fmt.Sprintf("在过去%d分钟内,发现 152 条关于 '%s' 的日志条目",
input.TimeRangeMinutes, input.Keyword),
+ }, nil
+}
+
+// ================================================
+// Search Archived Logs Tool
+// ================================================
+
+type SearchArchivedLogsInput struct {
+ FilePathPattern string `json:"filePathPattern"
jsonschema:"required,description=File path pattern to search"`
+ GrepKeyword string `json:"grepKeyword"
jsonschema:"required,description=Keyword to grep for"`
+}
+
+type MatchingLine struct {
+ FilePath string `json:"filePath"`
+ LineNumber int `json:"lineNumber"`
+ LineContent string `json:"lineContent"`
+}
+
+type SearchArchivedLogsOutput struct {
+ ToolName string `json:"toolName"`
+ FilesSearched int `json:"filesSearched"`
+ MatchingLines []MatchingLine `json:"matchingLines"`
+ Summary string `json:"summary"`
+}
+
+func (o SearchArchivedLogsOutput) Tool() string {
+ return o.ToolName
+}
+
+func searchArchivedLogs(ctx *ai.ToolContext, input SearchArchivedLogsInput)
(SearchArchivedLogsOutput, error) {
+ log.Printf("Tool 'search_archived_logs' called with pattern: %s,
keyword: %s", input.FilePathPattern, input.GrepKeyword)
+
+ return SearchArchivedLogsOutput{
+ ToolName: "search_archived_logs",
+ FilesSearched: 5,
+ MatchingLines: []MatchingLine{
+ {
+ FilePath:
"/logs/mysql-orders-db/slow-query-2025-08-16.log.gz",
+ LineNumber: 1024,
+ LineContent: "Query_time: 25.3s | SELECT
COUNT(id), SUM(price) FROM orders WHERE user_id = 'VIP_USER_123';",
+ },
+ {
+ FilePath:
"/logs/mysql-orders-db/slow-query-2025-08-16.log.gz",
+ LineNumber: 1029,
+ LineContent: "Query_time: 28.1s | SELECT
COUNT(id), SUM(price) FROM orders WHERE user_id = 'VIP_USER_456';",
Review Comment:
The hardcoded timestamps in mock data reference dates from August 2025. For
consistency and to avoid confusion, consider using relative timestamps or
current date ranges.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]