Copilot commented on code in PR #1319:
URL: https://github.com/apache/dubbo-admin/pull/1319#discussion_r2313485913
##########
ai/internal/schema/llm_schema.go:
##########
@@ -0,0 +1,102 @@
+package schema
+
+import (
+ "dubbo-admin-ai/internal/tools"
+ "encoding/json"
+ "fmt"
+)
+
+// 表示 LLM 的响应结构
+type ReActIn = ReActInput
+type ReActOut = string
+
+type ThinkIn = ReActInput
+type ThinkOut = ThinkAggregation
+
+type ActIn = ThinkOut
+type ActOut = []string
+
+type ReActInput struct {
+ UserInput string `json:"userInput"`
+ // 移除SessionID和SessionMemory,这些由Session管理
+}
+
+type Status string
+
+const (
+ Continued Status = "CONTINUED"
+ Finished Status = "FINISHED"
+ Pending Status = "PENDING"
+)
+
+type ToolRequest struct {
+ Thought string `json:"thought"`
+ ToolDesc tools.ToolDesc `json:"tool_desc"`
+}
+
+type ThinkAggregation struct {
+ ToolRequests []ToolRequest `json:"tool_requests"`
+ Status Status `json:"status"
jsonschema:"enum=CONTINUED,enum=FINISHED,enum=PENDING"`
+ Thought string `json:"thought"`
+ FinalAnswer string `json:"final_answer,omitempty"
jsonschema:"required=false"`
+}
+
+// ReActInput
+func (a ReActInput) String() string {
+ data, err := json.MarshalIndent(a, "", " ")
+ if err != nil {
+ return fmt.Sprintf("ReActInput{error: %v}", err)
+ }
+ return string(data)
+}
+
+// ToolRequest
+// HasAction 检查是否包含行动指令
+func (tr ToolRequest) HasAction() bool {
+ return tr.ToolDesc.ToolInput != nil && tr.ToolDesc.ToolName != ""
+}
+
+// ValidateToolDesc 验证行动指令的有效性
+func (tr ToolRequest) ValidateToolDesc() error {
+ if !tr.HasAction() {
+ return fmt.Errorf("no valid action found")
+ }
+
+ if tr.ToolDesc.ToolName == "" {
+ return fmt.Errorf("tool_name cannot be empty")
+ }
+
+ // 验证支持的工具名称
+ supportedTools, err := tools.AllMockToolNames()
+ if err != nil {
+ return fmt.Errorf("failed to get supported tools: %w", err)
+ }
+
+ if _, ok := supportedTools[tr.ToolDesc.ToolName]; !ok {
+ return fmt.Errorf("unsupported tool: %s", tr.ToolDesc.ToolName)
+ }
+
+ return nil
+}
+
+// String 实现 fmt.Stringer 接口,返回格式化的 JSON
+func (tr ToolRequest) String() string {
+ data, err := json.MarshalIndent(tr, "", " ")
+ if err != nil {
+ return fmt.Sprintf("ThinkAggregation{error: %v}", err)
Review Comment:
The error message incorrectly references 'ThinkAggregation' but this is the
String() method for ToolRequest. It should return 'ToolRequest{error: %v}'
instead.
```suggestion
return fmt.Sprintf("ToolRequest{error: %v}", err)
```
##########
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),
Review Comment:
This line is commented out but still contains the fmt.Sprintf call. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
Summary: fmt.Sprintf("服务 %s 的 QPS 为 250, 错误率为
5.2%%", input.ServiceName),
```
##########
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' 的调用",
Review Comment:
This line is commented out but still contains a string literal. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
Summary: "平均总延迟为 3200ms。瓶颈已定位,95.3% 的延迟来自对下游 'mysql-orders-db'
的调用",
```
##########
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",
Review Comment:
This line is commented out but still contains a string literal. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
```
##########
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),
Review Comment:
This line is commented out but still contains the fmt.Sprintf call. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
Summary: fmt.Sprintf("在过去%d分钟内,发现 152 条关于 '%s' 的日志条目",
input.TimeRangeMinutes, input.Keyword),
```
##########
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",
Review Comment:
This line is commented out but still contains a string literal. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
```
##########
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),
Review Comment:
This line is commented out but still contains the fmt.Sprintf call. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
Summary: fmt.Sprintf("服务 %s 在过去%d分钟内的 P%.0f 延迟为 %dms",
input.ServiceName, input.TimeRangeMinutes, input.Quantile*100, valueMillis),
```
##########
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 个时间序列",
Review Comment:
This line is commented out but still contains a string literal. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
Summary: "查询返回了 2 个时间序列",
```
##########
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时间消耗在数据库查询调用链上",
Review Comment:
This line is commented out but still contains a string literal. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
Summary: "性能分析显示,45.5%的CPU时间消耗在数据库查询调用链上",
```
##########
ai/internal/agent/flow.go:
##########
@@ -0,0 +1,157 @@
+package agent
+
+import (
+ "context"
+ "dubbo-admin-ai/config"
+ "dubbo-admin-ai/internal/schema"
+ "dubbo-admin-ai/internal/tools"
+ "errors"
+ "fmt"
+ "log"
+ "os"
+
+ "github.com/firebase/genkit/go/core/logger"
+
+ "github.com/firebase/genkit/go/ai"
+ "github.com/firebase/genkit/go/core"
+ "github.com/firebase/genkit/go/genkit"
+)
+
+// 公开的 Flow 变量,以便在编排器中调用
+var (
+ ReActFlow *core.Flow[schema.ReActIn, schema.ReActOut, struct{}]
+ ThinkingFlow *core.Flow[schema.ThinkIn, *schema.ThinkOut, struct{}]
+ ActFlow *core.Flow[*schema.ActIn, schema.ActOut, struct{}]
+
+ ThinkPrompt *ai.Prompt
+)
+
+var g *genkit.Genkit
+
+func InitFlows(registry *genkit.Genkit) error {
+ if registry == nil {
+ return fmt.Errorf("registry is nil")
+ }
+ g = registry
+
+ data, err := os.ReadFile(config.PROMPT_DIR_PATH + "/agentSystem.prompt")
+ if err != nil {
+ return fmt.Errorf("failed to read agentSystem prompt: %w", err)
+ }
+ systemPromptText := string(data)
+
+ mockTools, err := tools.AllMockToolRef()
+ if err != nil {
+ log.Fatalf("failed to get mock mock_tools: %v", err)
+ }
+ ThinkPrompt, err = genkit.DefinePrompt(g, "agentThinking",
+ ai.WithSystem(systemPromptText),
+ ai.WithInputType(schema.ThinkIn{}),
+ ai.WithOutputType(schema.ThinkOut{}),
+ ai.WithPrompt("{{userInput}}"),
+ ai.WithTools(mockTools...),
+ ai.WithToolChoice(ai.ToolChoiceNone),
+ )
+
+ if err != nil {
+ return fmt.Errorf("failed to define agentThink prompt: %w", err)
+ }
+
+ ReActFlow = genkit.DefineFlow(g, "reAct", reAct)
+ ThinkingFlow = genkit.DefineFlow(g, "thinking", thinking)
+ ActFlow = genkit.DefineFlow(g, "act", act)
+
+ return nil
+}
+
+// Flow 的核心函数实现 `fn` (不对外导出)
+// ----------------------------------------------------------------------------
+// 1. agentOrchestrator: 总指挥/编排器的核心逻辑
+// ----------------------------------------------------------------------------
+func reAct(ctx context.Context, reActInput schema.ReActIn) (reActOut
schema.ReActOut, err error) {
+ //TODO: 输入数据意图解析
+
+ thinkingInput := reActInput
+ // 主协调循环 (Reconciliation Loop)
+ for range 5 { // 设置最大循环次数
Review Comment:
The magic number 5 should be defined as a named constant to improve code
readability and maintainability. Consider defining something like `const
maxReActIterations = 5`.
##########
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
个请求正在排队等待连接",
Review Comment:
This line is commented out but still contains a string literal. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
```
##########
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';",
+ },
+ },
+ // Summary: "在归档的日志文件中,发现了多条查询,搜索了 5 个文件,找到了 2 条匹配行",
Review Comment:
This line is commented out but still contains a string literal. Either
remove the entire line or uncomment it if the Summary field should be populated.
```suggestion
```
--
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]