Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion pkg/kiali/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,28 @@ package kiali
const (
// DefaultRateInterval is the default rate interval for fetching error rates and metrics.
// This value is used when rateInterval is not explicitly provided in API calls.
DefaultRateInterval = "10m"
DefaultRateInterval = "10m"
DefaultGraphType = "versionedApp"
DefaultDuration = "30m"
DefaultStep = "15"
DefaultDirection = "outbound"
DefaultReporter = "source"
DefaultRequestProtocol = "http"
DefaultQuantiles = "0.5,0.95,0.99,0.999"
DefaultLimit = "100"
DefaultTail = "100"

// Default graph parameters
DefaultIncludeIdleEdges = "false"
DefaultInjectServiceNodes = "true"
DefaultBoxBy = "cluster,namespace,app"
DefaultAmbientTraffic = "none"
DefaultAppenders = "deadNode,istio,serviceEntry,meshCheck,workloadEntry,health"
DefaultRateGrpc = "requests"
DefaultRateHttp = "requests"
DefaultRateTcp = "sent"

// Default mesh status parameters
DefaultIncludeGateways = "false"
DefaultIncludeWaypoints = "false"
)
30 changes: 10 additions & 20 deletions pkg/kiali/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,16 @@ func (k *Kiali) Graph(ctx context.Context, namespaces []string, queryParams map[
return "", err
}
q := u.Query()
// Static graph parameters per requirements
// Defaults with optional overrides via queryParams
duration := DefaultRateInterval
graphType := "versionedApp"
if v, ok := queryParams["rateInterval"]; ok && strings.TrimSpace(v) != "" {
duration = strings.TrimSpace(v)
}
if v, ok := queryParams["graphType"]; ok && strings.TrimSpace(v) != "" {
graphType = strings.TrimSpace(v)
}
q.Set("duration", duration)
q.Set("graphType", graphType)
q.Set("includeIdleEdges", "false")
q.Set("injectServiceNodes", "true")
q.Set("boxBy", "cluster,namespace,app")
q.Set("ambientTraffic", "none")
q.Set("appenders", "deadNode,istio,serviceEntry,meshCheck,workloadEntry,health")
q.Set("rateGrpc", "requests")
q.Set("rateHttp", "requests")
q.Set("rateTcp", "sent")
q.Set("duration", queryParams["rateInterval"])
q.Set("graphType", queryParams["graphType"])
q.Set("includeIdleEdges", DefaultIncludeIdleEdges)
q.Set("injectServiceNodes", DefaultInjectServiceNodes)
q.Set("boxBy", DefaultBoxBy)
q.Set("ambientTraffic", DefaultAmbientTraffic)
q.Set("appenders", DefaultAppenders)
q.Set("rateGrpc", DefaultRateGrpc)
q.Set("rateHttp", DefaultRateHttp)
q.Set("rateTcp", DefaultRateTcp)
// Optional namespaces param
cleaned := make([]string, 0, len(namespaces))
for _, ns := range namespaces {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kiali/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func (k *Kiali) MeshStatus(ctx context.Context) (string, error) {
return "", err
}
q := u.Query()
q.Set("includeGateways", "false")
q.Set("includeWaypoints", "false")
q.Set("includeGateways", DefaultIncludeGateways)
q.Set("includeWaypoints", DefaultIncludeWaypoints)
u.RawQuery = q.Encode()
return k.executeRequest(ctx, http.MethodGet, u.String(), "", nil)
}
15 changes: 12 additions & 3 deletions pkg/mcp/testdata/toolsets-kiali-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"type": "object",
"properties": {
"graphType": {
"description": "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'. Default: 'versionedApp'",
"default": "versionedApp",
"description": "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'",
"type": "string"
},
"namespace": {
Expand All @@ -23,7 +24,8 @@
"type": "string"
},
"rateInterval": {
"description": "Rate interval for fetching (e.g., '10m', '5m', '1h'). Default: '10m'",
"default": "10m",
"description": "Rate interval for fetching (e.g., '10m', '5m', '1h').",
"type": "string"
}
}
Expand All @@ -47,26 +49,31 @@
"type": "string"
},
"direction": {
"default": "outbound",
"description": "Traffic direction: 'inbound' or 'outbound'. Optional, defaults to 'outbound'",
"type": "string"
},
"duration": {
"description": "Time range to get metrics for (optional string - if provided, gets metrics; if empty, get default 1800s).",
"default": "30m",
"description": "Time range to get metrics for (optional string - if provided, gets metrics (e.g., '1m', '5m', '1h'); if empty, get default 30m).",
"type": "string"
},
"namespace": {
"description": "Namespace to get resources from",
"type": "string"
},
"quantiles": {
"default": "0.5,0.95,0.99,0.999",
"description": "Comma-separated list of quantiles for histogram metrics (e.g., '0.5,0.95,0.99'). Optional",
"type": "string"
},
"rateInterval": {
"default": "10m",
"description": "Rate interval for metrics (e.g., '1m', '5m'). Optional, defaults to '10m'",
"type": "string"
},
"reporter": {
"default": "source",
"description": "Metrics reporter: 'source', 'destination', or 'both'. Optional, defaults to 'source'",
"type": "string"
},
Expand All @@ -87,6 +94,7 @@
"type": "string"
},
"step": {
"default": "15",
"description": "Step between data points in seconds (e.g., '15'). Optional, defaults to 15 seconds",
"type": "string"
}
Expand Down Expand Up @@ -152,6 +160,7 @@
"type": "string"
},
"limit": {
"default": "100",
"description": "Maximum number of traces to return (default: 100, only used when traceId is not provided)",
"minimum": 1,
"type": "integer"
Expand Down
16 changes: 8 additions & 8 deletions pkg/toolsets/kiali/get_mesh_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ func initGetMeshGraph() []api.ServerTool {
},
"rateInterval": {
Type: "string",
Description: "Rate interval for fetching (e.g., '10m', '5m', '1h'). Default: '10m'",
Description: "Rate interval for fetching (e.g., '10m', '5m', '1h').",
Default: api.ToRawMessage(kialiclient.DefaultRateInterval),
},
"graphType": {
Type: "string",
Description: "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'. Default: 'versionedApp'",
Description: "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'",
Default: api.ToRawMessage(kialiclient.DefaultGraphType),
},
},
Required: []string{},
Expand Down Expand Up @@ -89,13 +91,11 @@ func getMeshGraphHandler(params api.ToolHandlerParams) (*api.ToolCallResult, err

// Extract optional query parameters
queryParams := make(map[string]string)
rateInterval := kialiclient.DefaultRateInterval // default
if v, ok := params.GetArguments()["rateInterval"].(string); ok && v != "" {
rateInterval = v
if err := setQueryParam(params, queryParams, "rateInterval", kialiclient.DefaultRateInterval); err != nil {
return api.NewToolCallResult("", err), nil
}
queryParams["rateInterval"] = rateInterval
if graphType, ok := params.GetArguments()["graphType"].(string); ok && graphType != "" {
queryParams["graphType"] = graphType
if err := setQueryParam(params, queryParams, "graphType", kialiclient.DefaultGraphType); err != nil {
return api.NewToolCallResult("", err), nil
}
k := params.NewKiali()
content, err := k.GetMeshGraph(params.Context, namespaces, queryParams)
Expand Down
33 changes: 18 additions & 15 deletions pkg/toolsets/kiali/get_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,27 @@ func initGetMetrics() []api.ServerTool {
},
"duration": {
Type: "string",
Description: "Time range to get metrics for (optional string - if provided, gets metrics; if empty, get default 1800s).",
Description: "Time range to get metrics for (optional string - if provided, gets metrics (e.g., '1m', '5m', '1h'); if empty, get default 30m).", Default: api.ToRawMessage(kialiclient.DefaultDuration),
},
"step": {
Type: "string",
Description: "Step between data points in seconds (e.g., '15'). Optional, defaults to 15 seconds",
Default: api.ToRawMessage(kialiclient.DefaultStep),
},
"rateInterval": {
Type: "string",
Description: "Rate interval for metrics (e.g., '1m', '5m'). Optional, defaults to '10m'",
Default: api.ToRawMessage(kialiclient.DefaultRateInterval),
},
"direction": {
Type: "string",
Description: "Traffic direction: 'inbound' or 'outbound'. Optional, defaults to 'outbound'",
Default: api.ToRawMessage(kialiclient.DefaultDirection),
},
"reporter": {
Type: "string",
Description: "Metrics reporter: 'source', 'destination', or 'both'. Optional, defaults to 'source'",
Default: api.ToRawMessage(kialiclient.DefaultReporter),
},
"requestProtocol": {
Type: "string",
Expand All @@ -82,6 +86,7 @@ func initGetMetrics() []api.ServerTool {
"quantiles": {
Type: "string",
Description: "Comma-separated list of quantiles for histogram metrics (e.g., '0.5,0.95,0.99'). Optional",
Default: api.ToRawMessage(kialiclient.DefaultQuantiles),
},
"byLabels": {
Type: "string",
Expand Down Expand Up @@ -129,28 +134,26 @@ func resourceMetricsHandler(params api.ToolHandlerParams) (*api.ToolCallResult,
}

queryParams := make(map[string]string)
if duration, ok := params.GetArguments()["duration"].(string); ok && duration != "" {
queryParams["duration"] = duration
if err := setQueryParam(params, queryParams, "duration", kialiclient.DefaultDuration); err != nil {
return api.NewToolCallResult("", err), nil
}
if step, ok := params.GetArguments()["step"].(string); ok && step != "" {
queryParams["step"] = step
if err := setQueryParam(params, queryParams, "step", kialiclient.DefaultStep); err != nil {
return api.NewToolCallResult("", err), nil
}
rateInterval := kialiclient.DefaultRateInterval // default
if v, ok := params.GetArguments()["rateInterval"].(string); ok && v != "" {
rateInterval = v
if err := setQueryParam(params, queryParams, "rateInterval", kialiclient.DefaultRateInterval); err != nil {
return api.NewToolCallResult("", err), nil
}
queryParams["rateInterval"] = rateInterval
if direction, ok := params.GetArguments()["direction"].(string); ok && direction != "" {
queryParams["direction"] = direction
if err := setQueryParam(params, queryParams, "direction", kialiclient.DefaultDirection); err != nil {
return api.NewToolCallResult("", err), nil
}
if reporter, ok := params.GetArguments()["reporter"].(string); ok && reporter != "" {
queryParams["reporter"] = reporter
if err := setQueryParam(params, queryParams, "reporter", kialiclient.DefaultReporter); err != nil {
return api.NewToolCallResult("", err), nil
}
if requestProtocol, ok := params.GetArguments()["requestProtocol"].(string); ok && requestProtocol != "" {
queryParams["requestProtocol"] = requestProtocol
}
if quantiles, ok := params.GetArguments()["quantiles"].(string); ok && quantiles != "" {
queryParams["quantiles"] = quantiles
if err := setQueryParam(params, queryParams, "quantiles", kialiclient.DefaultQuantiles); err != nil {
return api.NewToolCallResult("", err), nil
}
if byLabels, ok := params.GetArguments()["byLabels"].(string); ok && byLabels != "" {
queryParams["byLabels"] = byLabels
Expand Down
31 changes: 6 additions & 25 deletions pkg/toolsets/kiali/get_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func initGetTraces() []api.ServerTool {
Type: "integer",
Description: "Maximum number of traces to return (default: 100, only used when traceId is not provided)",
Minimum: ptr.To(float64(1)),
Default: api.ToRawMessage(kialiclient.DefaultLimit),
},
"minDuration": {
Type: "integer",
Expand Down Expand Up @@ -175,34 +176,14 @@ func TracesHandler(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
endMicros = strconv.FormatInt(endTime.UnixMicro(), 10)
}
queryParams["endMicros"] = endMicros
// Handle limit: convert integer to string if provided
if limit := params.GetArguments()["limit"]; limit != nil {
switch v := limit.(type) {
case float64:
queryParams["limit"] = fmt.Sprintf("%.0f", v)
case int:
queryParams["limit"] = fmt.Sprintf("%d", v)
case int64:
queryParams["limit"] = fmt.Sprintf("%d", v)
case string:
if v != "" {
queryParams["limit"] = v
}
}
if err := setQueryParam(params, queryParams, "limit", kialiclient.DefaultLimit); err != nil {
return api.NewToolCallResult("", err), nil
}

// Handle minDuration: convert integer to string if provided
if minDuration := params.GetArguments()["minDuration"]; minDuration != nil {
switch v := minDuration.(type) {
case float64:
queryParams["minDuration"] = fmt.Sprintf("%.0f", v)
case int:
queryParams["minDuration"] = fmt.Sprintf("%d", v)
case int64:
queryParams["minDuration"] = fmt.Sprintf("%d", v)
case string:
if v != "" {
queryParams["minDuration"] = v
}
if err := setQueryParam(params, queryParams, "minDuration", ""); err != nil {
return api.NewToolCallResult("", err), nil
}
}
if tags, ok := params.GetArguments()["tags"].(string); ok && tags != "" {
Expand Down
Loading