Skip to content

Commit 6ebbbdb

Browse files
aljesusgmanusa
andauthored
feat(kiali): Keep defaults in a file (#521)
* feat(kiali): Keep defaults in a file Signed-off-by: Alberto Gutierrez <aljesusg@gmail.com> * test(kiali): Keep defaults in a file --------- Signed-off-by: Alberto Gutierrez <aljesusg@gmail.com> Signed-off-by: Marc Nuri <marc@marcnuri.com> Co-authored-by: Marc Nuri <marc@marcnuri.com>
1 parent 2ed1329 commit 6ebbbdb

File tree

9 files changed

+509
-74
lines changed

9 files changed

+509
-74
lines changed

pkg/kiali/defaults.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,28 @@ package kiali
44
const (
55
// DefaultRateInterval is the default rate interval for fetching error rates and metrics.
66
// This value is used when rateInterval is not explicitly provided in API calls.
7-
DefaultRateInterval = "10m"
7+
DefaultRateInterval = "10m"
8+
DefaultGraphType = "versionedApp"
9+
DefaultDuration = "30m"
10+
DefaultStep = "15"
11+
DefaultDirection = "outbound"
12+
DefaultReporter = "source"
13+
DefaultRequestProtocol = "http"
14+
DefaultQuantiles = "0.5,0.95,0.99,0.999"
15+
DefaultLimit = "100"
16+
DefaultTail = "100"
17+
18+
// Default graph parameters
19+
DefaultIncludeIdleEdges = "false"
20+
DefaultInjectServiceNodes = "true"
21+
DefaultBoxBy = "cluster,namespace,app"
22+
DefaultAmbientTraffic = "none"
23+
DefaultAppenders = "deadNode,istio,serviceEntry,meshCheck,workloadEntry,health"
24+
DefaultRateGrpc = "requests"
25+
DefaultRateHttp = "requests"
26+
DefaultRateTcp = "sent"
27+
28+
// Default mesh status parameters
29+
DefaultIncludeGateways = "false"
30+
DefaultIncludeWaypoints = "false"
831
)

pkg/kiali/graph.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,16 @@ func (k *Kiali) Graph(ctx context.Context, namespaces []string, queryParams map[
1616
return "", err
1717
}
1818
q := u.Query()
19-
// Static graph parameters per requirements
20-
// Defaults with optional overrides via queryParams
21-
duration := DefaultRateInterval
22-
graphType := "versionedApp"
23-
if v, ok := queryParams["rateInterval"]; ok && strings.TrimSpace(v) != "" {
24-
duration = strings.TrimSpace(v)
25-
}
26-
if v, ok := queryParams["graphType"]; ok && strings.TrimSpace(v) != "" {
27-
graphType = strings.TrimSpace(v)
28-
}
29-
q.Set("duration", duration)
30-
q.Set("graphType", graphType)
31-
q.Set("includeIdleEdges", "false")
32-
q.Set("injectServiceNodes", "true")
33-
q.Set("boxBy", "cluster,namespace,app")
34-
q.Set("ambientTraffic", "none")
35-
q.Set("appenders", "deadNode,istio,serviceEntry,meshCheck,workloadEntry,health")
36-
q.Set("rateGrpc", "requests")
37-
q.Set("rateHttp", "requests")
38-
q.Set("rateTcp", "sent")
19+
q.Set("duration", queryParams["rateInterval"])
20+
q.Set("graphType", queryParams["graphType"])
21+
q.Set("includeIdleEdges", DefaultIncludeIdleEdges)
22+
q.Set("injectServiceNodes", DefaultInjectServiceNodes)
23+
q.Set("boxBy", DefaultBoxBy)
24+
q.Set("ambientTraffic", DefaultAmbientTraffic)
25+
q.Set("appenders", DefaultAppenders)
26+
q.Set("rateGrpc", DefaultRateGrpc)
27+
q.Set("rateHttp", DefaultRateHttp)
28+
q.Set("rateTcp", DefaultRateTcp)
3929
// Optional namespaces param
4030
cleaned := make([]string, 0, len(namespaces))
4131
for _, ns := range namespaces {

pkg/kiali/mesh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func (k *Kiali) MeshStatus(ctx context.Context) (string, error) {
1515
return "", err
1616
}
1717
q := u.Query()
18-
q.Set("includeGateways", "false")
19-
q.Set("includeWaypoints", "false")
18+
q.Set("includeGateways", DefaultIncludeGateways)
19+
q.Set("includeWaypoints", DefaultIncludeWaypoints)
2020
u.RawQuery = q.Encode()
2121
return k.executeRequest(ctx, http.MethodGet, u.String(), "", nil)
2222
}

pkg/mcp/testdata/toolsets-kiali-tools.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"type": "object",
1212
"properties": {
1313
"graphType": {
14-
"description": "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'. Default: 'versionedApp'",
14+
"default": "versionedApp",
15+
"description": "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'",
1516
"type": "string"
1617
},
1718
"namespace": {
@@ -23,7 +24,8 @@
2324
"type": "string"
2425
},
2526
"rateInterval": {
26-
"description": "Rate interval for fetching (e.g., '10m', '5m', '1h'). Default: '10m'",
27+
"default": "10m",
28+
"description": "Rate interval for fetching (e.g., '10m', '5m', '1h').",
2729
"type": "string"
2830
}
2931
}
@@ -47,26 +49,31 @@
4749
"type": "string"
4850
},
4951
"direction": {
52+
"default": "outbound",
5053
"description": "Traffic direction: 'inbound' or 'outbound'. Optional, defaults to 'outbound'",
5154
"type": "string"
5255
},
5356
"duration": {
54-
"description": "Time range to get metrics for (optional string - if provided, gets metrics; if empty, get default 1800s).",
57+
"default": "30m",
58+
"description": "Time range to get metrics for (optional string - if provided, gets metrics (e.g., '1m', '5m', '1h'); if empty, get default 30m).",
5559
"type": "string"
5660
},
5761
"namespace": {
5862
"description": "Namespace to get resources from",
5963
"type": "string"
6064
},
6165
"quantiles": {
66+
"default": "0.5,0.95,0.99,0.999",
6267
"description": "Comma-separated list of quantiles for histogram metrics (e.g., '0.5,0.95,0.99'). Optional",
6368
"type": "string"
6469
},
6570
"rateInterval": {
71+
"default": "10m",
6672
"description": "Rate interval for metrics (e.g., '1m', '5m'). Optional, defaults to '10m'",
6773
"type": "string"
6874
},
6975
"reporter": {
76+
"default": "source",
7077
"description": "Metrics reporter: 'source', 'destination', or 'both'. Optional, defaults to 'source'",
7178
"type": "string"
7279
},
@@ -87,6 +94,7 @@
8794
"type": "string"
8895
},
8996
"step": {
97+
"default": "15",
9098
"description": "Step between data points in seconds (e.g., '15'). Optional, defaults to 15 seconds",
9199
"type": "string"
92100
}
@@ -152,6 +160,7 @@
152160
"type": "string"
153161
},
154162
"limit": {
163+
"default": "100",
155164
"description": "Maximum number of traces to return (default: 100, only used when traceId is not provided)",
156165
"minimum": 1,
157166
"type": "integer"

pkg/toolsets/kiali/get_mesh_graph.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ func initGetMeshGraph() []api.ServerTool {
3030
},
3131
"rateInterval": {
3232
Type: "string",
33-
Description: "Rate interval for fetching (e.g., '10m', '5m', '1h'). Default: '10m'",
33+
Description: "Rate interval for fetching (e.g., '10m', '5m', '1h').",
34+
Default: api.ToRawMessage(kialiclient.DefaultRateInterval),
3435
},
3536
"graphType": {
3637
Type: "string",
37-
Description: "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'. Default: 'versionedApp'",
38+
Description: "Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'",
39+
Default: api.ToRawMessage(kialiclient.DefaultGraphType),
3840
},
3941
},
4042
Required: []string{},
@@ -89,13 +91,11 @@ func getMeshGraphHandler(params api.ToolHandlerParams) (*api.ToolCallResult, err
8991

9092
// Extract optional query parameters
9193
queryParams := make(map[string]string)
92-
rateInterval := kialiclient.DefaultRateInterval // default
93-
if v, ok := params.GetArguments()["rateInterval"].(string); ok && v != "" {
94-
rateInterval = v
94+
if err := setQueryParam(params, queryParams, "rateInterval", kialiclient.DefaultRateInterval); err != nil {
95+
return api.NewToolCallResult("", err), nil
9596
}
96-
queryParams["rateInterval"] = rateInterval
97-
if graphType, ok := params.GetArguments()["graphType"].(string); ok && graphType != "" {
98-
queryParams["graphType"] = graphType
97+
if err := setQueryParam(params, queryParams, "graphType", kialiclient.DefaultGraphType); err != nil {
98+
return api.NewToolCallResult("", err), nil
9999
}
100100
k := params.NewKiali()
101101
content, err := k.GetMeshGraph(params.Context, namespaces, queryParams)

pkg/toolsets/kiali/get_metrics.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,27 @@ func initGetMetrics() []api.ServerTool {
5757
},
5858
"duration": {
5959
Type: "string",
60-
Description: "Time range to get metrics for (optional string - if provided, gets metrics; if empty, get default 1800s).",
60+
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),
6161
},
6262
"step": {
6363
Type: "string",
6464
Description: "Step between data points in seconds (e.g., '15'). Optional, defaults to 15 seconds",
65+
Default: api.ToRawMessage(kialiclient.DefaultStep),
6566
},
6667
"rateInterval": {
6768
Type: "string",
6869
Description: "Rate interval for metrics (e.g., '1m', '5m'). Optional, defaults to '10m'",
70+
Default: api.ToRawMessage(kialiclient.DefaultRateInterval),
6971
},
7072
"direction": {
7173
Type: "string",
7274
Description: "Traffic direction: 'inbound' or 'outbound'. Optional, defaults to 'outbound'",
75+
Default: api.ToRawMessage(kialiclient.DefaultDirection),
7376
},
7477
"reporter": {
7578
Type: "string",
7679
Description: "Metrics reporter: 'source', 'destination', or 'both'. Optional, defaults to 'source'",
80+
Default: api.ToRawMessage(kialiclient.DefaultReporter),
7781
},
7882
"requestProtocol": {
7983
Type: "string",
@@ -82,6 +86,7 @@ func initGetMetrics() []api.ServerTool {
8286
"quantiles": {
8387
Type: "string",
8488
Description: "Comma-separated list of quantiles for histogram metrics (e.g., '0.5,0.95,0.99'). Optional",
89+
Default: api.ToRawMessage(kialiclient.DefaultQuantiles),
8590
},
8691
"byLabels": {
8792
Type: "string",
@@ -129,28 +134,26 @@ func resourceMetricsHandler(params api.ToolHandlerParams) (*api.ToolCallResult,
129134
}
130135

131136
queryParams := make(map[string]string)
132-
if duration, ok := params.GetArguments()["duration"].(string); ok && duration != "" {
133-
queryParams["duration"] = duration
137+
if err := setQueryParam(params, queryParams, "duration", kialiclient.DefaultDuration); err != nil {
138+
return api.NewToolCallResult("", err), nil
134139
}
135-
if step, ok := params.GetArguments()["step"].(string); ok && step != "" {
136-
queryParams["step"] = step
140+
if err := setQueryParam(params, queryParams, "step", kialiclient.DefaultStep); err != nil {
141+
return api.NewToolCallResult("", err), nil
137142
}
138-
rateInterval := kialiclient.DefaultRateInterval // default
139-
if v, ok := params.GetArguments()["rateInterval"].(string); ok && v != "" {
140-
rateInterval = v
143+
if err := setQueryParam(params, queryParams, "rateInterval", kialiclient.DefaultRateInterval); err != nil {
144+
return api.NewToolCallResult("", err), nil
141145
}
142-
queryParams["rateInterval"] = rateInterval
143-
if direction, ok := params.GetArguments()["direction"].(string); ok && direction != "" {
144-
queryParams["direction"] = direction
146+
if err := setQueryParam(params, queryParams, "direction", kialiclient.DefaultDirection); err != nil {
147+
return api.NewToolCallResult("", err), nil
145148
}
146-
if reporter, ok := params.GetArguments()["reporter"].(string); ok && reporter != "" {
147-
queryParams["reporter"] = reporter
149+
if err := setQueryParam(params, queryParams, "reporter", kialiclient.DefaultReporter); err != nil {
150+
return api.NewToolCallResult("", err), nil
148151
}
149152
if requestProtocol, ok := params.GetArguments()["requestProtocol"].(string); ok && requestProtocol != "" {
150153
queryParams["requestProtocol"] = requestProtocol
151154
}
152-
if quantiles, ok := params.GetArguments()["quantiles"].(string); ok && quantiles != "" {
153-
queryParams["quantiles"] = quantiles
155+
if err := setQueryParam(params, queryParams, "quantiles", kialiclient.DefaultQuantiles); err != nil {
156+
return api.NewToolCallResult("", err), nil
154157
}
155158
if byLabels, ok := params.GetArguments()["byLabels"].(string); ok && byLabels != "" {
156159
queryParams["byLabels"] = byLabels

pkg/toolsets/kiali/get_traces.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func initGetTraces() []api.ServerTool {
7979
Type: "integer",
8080
Description: "Maximum number of traces to return (default: 100, only used when traceId is not provided)",
8181
Minimum: ptr.To(float64(1)),
82+
Default: api.ToRawMessage(kialiclient.DefaultLimit),
8283
},
8384
"minDuration": {
8485
Type: "integer",
@@ -175,34 +176,14 @@ func TracesHandler(params api.ToolHandlerParams) (*api.ToolCallResult, error) {
175176
endMicros = strconv.FormatInt(endTime.UnixMicro(), 10)
176177
}
177178
queryParams["endMicros"] = endMicros
178-
// Handle limit: convert integer to string if provided
179-
if limit := params.GetArguments()["limit"]; limit != nil {
180-
switch v := limit.(type) {
181-
case float64:
182-
queryParams["limit"] = fmt.Sprintf("%.0f", v)
183-
case int:
184-
queryParams["limit"] = fmt.Sprintf("%d", v)
185-
case int64:
186-
queryParams["limit"] = fmt.Sprintf("%d", v)
187-
case string:
188-
if v != "" {
189-
queryParams["limit"] = v
190-
}
191-
}
179+
if err := setQueryParam(params, queryParams, "limit", kialiclient.DefaultLimit); err != nil {
180+
return api.NewToolCallResult("", err), nil
192181
}
182+
193183
// Handle minDuration: convert integer to string if provided
194184
if minDuration := params.GetArguments()["minDuration"]; minDuration != nil {
195-
switch v := minDuration.(type) {
196-
case float64:
197-
queryParams["minDuration"] = fmt.Sprintf("%.0f", v)
198-
case int:
199-
queryParams["minDuration"] = fmt.Sprintf("%d", v)
200-
case int64:
201-
queryParams["minDuration"] = fmt.Sprintf("%d", v)
202-
case string:
203-
if v != "" {
204-
queryParams["minDuration"] = v
205-
}
185+
if err := setQueryParam(params, queryParams, "minDuration", ""); err != nil {
186+
return api.NewToolCallResult("", err), nil
206187
}
207188
}
208189
if tags, ok := params.GetArguments()["tags"].(string); ok && tags != "" {

0 commit comments

Comments
 (0)