Skip to content

Commit 9e3645d

Browse files
hhovsepyaljesusg
andauthored
feat(kiali): add aggregated health summary to mesh graph tool (containers#506)
* Added summary health for kiali_get_mesh_graph tool. Signed-off-by: Hayk Hovsepyan <[email protected]> * Comments approached Signed-off-by: Hayk Hovsepyan <[email protected]> * Approached comments Signed-off-by: Hayk Hovsepyan <[email protected]> * Added DefaultRateInterval value Signed-off-by: Hayk Hovsepyan <[email protected]> * Update pkg/kiali/get_mesh_graph.go Co-authored-by: Alberto Gutierrez <[email protected]> Signed-off-by: Hayk Hovsepyan <[email protected]> --------- Signed-off-by: Hayk Hovsepyan <[email protected]> Co-authored-by: Alberto Gutierrez <[email protected]>
1 parent 130e42c commit 9e3645d

File tree

11 files changed

+778
-26
lines changed

11 files changed

+778
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ In case multi-cluster support is enabled (default) and you have access to multip
352352
- `graphType` (`string`) - Type of graph to return: 'versionedApp', 'app', 'service', 'workload', 'mesh'. Default: 'versionedApp'
353353
- `namespace` (`string`) - Optional single namespace to include in the graph (alternative to namespaces)
354354
- `namespaces` (`string`) - Optional comma-separated list of namespaces to include in the graph
355-
- `rateInterval` (`string`) - Rate interval for fetching (e.g., '10m', '5m', '1h'). Default: '60s'
355+
- `rateInterval` (`string`) - Rate interval for fetching (e.g., '10m', '5m', '1h'). Default: '10m'
356356

357357
- **kiali_manage_istio_config** - Manages Istio configuration objects (Gateways, VirtualServices, etc.). Can list (objects and validations), get, create, patch, or delete objects
358358
- `action` (`string`) **(required)** - Action to perform: list, get, create, patch, or delete
@@ -374,7 +374,7 @@ In case multi-cluster support is enabled (default) and you have access to multip
374374
- `duration` (`string`) - Time range to get metrics for (optional string - if provided, gets metrics; if empty, get default 1800s).
375375
- `namespace` (`string`) **(required)** - Namespace to get resources from
376376
- `quantiles` (`string`) - Comma-separated list of quantiles for histogram metrics (e.g., '0.5,0.95,0.99'). Optional
377-
- `rateInterval` (`string`) - Rate interval for metrics (e.g., '1m', '5m'). Optional, defaults to '1m'
377+
- `rateInterval` (`string`) - Rate interval for metrics (e.g., '1m', '5m'). Optional, defaults to '10m'
378378
- `reporter` (`string`) - Metrics reporter: 'source', 'destination', or 'both'. Optional, defaults to 'source'
379379
- `requestProtocol` (`string`) - Filter by request protocol (e.g., 'http', 'grpc', 'tcp'). Optional
380380
- `resource_name` (`string`) **(required)** - Name of the resource to get details for (optional string - if provided, gets details; if empty, lists all).

pkg/kiali/defaults.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package kiali
2+
3+
// Default values for Kiali API parameters shared across this package.
4+
const (
5+
// DefaultRateInterval is the default rate interval for fetching error rates and metrics.
6+
// This value is used when rateInterval is not explicitly provided in API calls.
7+
DefaultRateInterval = "10m"
8+
)

pkg/kiali/get_mesh_graph.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ import (
77
"sync"
88
)
99

10+
// GetMeshGraphResponse contains the combined response from multiple Kiali API endpoints.
11+
// Note: Health data is fetched from Kiali's health API and used internally to compute
12+
// MeshHealthSummary, but the raw health data is not included in the response to reduce payload size.
13+
// MeshHealthSummary contains all the key aggregated metrics needed for mesh health overview.
1014
type GetMeshGraphResponse struct {
11-
Graph json.RawMessage `json:"graph,omitempty"`
12-
Health json.RawMessage `json:"health,omitempty"`
13-
MeshStatus json.RawMessage `json:"mesh_status,omitempty"`
14-
Namespaces json.RawMessage `json:"namespaces,omitempty"`
15-
Errors map[string]string `json:"errors,omitempty"`
15+
Graph json.RawMessage `json:"graph,omitempty"`
16+
MeshStatus json.RawMessage `json:"mesh_status,omitempty"`
17+
Namespaces json.RawMessage `json:"namespaces,omitempty"`
18+
MeshHealthSummary *MeshHealthSummary `json:"mesh_health_summary,omitempty"` // Aggregated summary computed from health data
19+
Errors map[string]string `json:"errors,omitempty"`
1620
}
1721

1822
// GetMeshGraph fetches multiple Kiali endpoints in parallel and returns a combined response.
1923
// Each field in the response corresponds to one API call result.
2024
// - graph: /api/namespaces/graph (optionally filtered by namespaces)
21-
// - health: /api/clusters/health (optionally filtered by namespaces and queryParams)
22-
// - status(mesh):/api/mesh/graph
25+
// - mesh_status: /api/mesh/graph
2326
// - namespaces: /api/namespaces
27+
// - mesh_health_summary: computed from /api/clusters/health (health data is fetched but not included in response)
2428
func (k *Kiali) GetMeshGraph(ctx context.Context, namespaces []string, queryParams map[string]string) (string, error) {
2529
cleaned := make([]string, 0, len(namespaces))
2630
for _, ns := range namespaces {
@@ -51,7 +55,7 @@ func (k *Kiali) GetMeshGraph(ctx context.Context, namespaces []string, queryPara
5155
resp.Graph = data
5256
}()
5357

54-
// Health
58+
// Health - compute MeshHealthSummary inside the goroutine
5559
go func() {
5660
defer wg.Done()
5761
data, err := k.getHealth(ctx, cleaned, queryParams)
@@ -61,7 +65,13 @@ func (k *Kiali) GetMeshGraph(ctx context.Context, namespaces []string, queryPara
6165
errorsMu.Unlock()
6266
return
6367
}
64-
resp.Health = data
68+
// Compute mesh health summary from health data
69+
if len(data) > 0 {
70+
summary := computeMeshHealthSummary(data, cleaned, queryParams)
71+
if summary != nil {
72+
resp.MeshHealthSummary = summary
73+
}
74+
}
6575
}()
6676

6777
// Mesh status

pkg/kiali/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (k *Kiali) Graph(ctx context.Context, namespaces []string, queryParams map[
1818
q := u.Query()
1919
// Static graph parameters per requirements
2020
// Defaults with optional overrides via queryParams
21-
duration := "60s"
21+
duration := DefaultRateInterval
2222
graphType := "versionedApp"
2323
if v, ok := queryParams["rateInterval"]; ok && strings.TrimSpace(v) != "" {
2424
duration = strings.TrimSpace(v)

pkg/kiali/health.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// - namespaces: comma-separated list of namespaces (optional, if empty returns health for all accessible namespaces)
1313
// - queryParams: optional query parameters map for filtering health data (e.g., "type", "rateInterval", "queryTime")
1414
// - type: health type - "app", "service", or "workload" (default: "app")
15-
// - rateInterval: rate interval for fetching error rate (default: "1m")
15+
// - rateInterval: rate interval for fetching error rate (default: DefaultRateInterval, which is "10m")
1616
// - queryTime: Unix timestamp for the prometheus query (optional)
1717
func (k *Kiali) Health(ctx context.Context, namespaces string, queryParams map[string]string) (string, error) {
1818
// Build query parameters
@@ -34,14 +34,18 @@ func (k *Kiali) Health(ctx context.Context, namespaces string, queryParams map[s
3434
}
3535
}
3636

37-
// Ensure health "type" aligns with graphType (versionedApp -> app)
37+
// Ensure health "type" aligns with graphType (versionedApp -> app, mesh -> app)
38+
// The Kiali health API only accepts "app", "service", or "workload" as valid types
3839
healthType := "app"
3940
if gt, ok := queryParams["graphType"]; ok && strings.TrimSpace(gt) != "" {
4041
v := strings.TrimSpace(gt)
4142
if strings.EqualFold(v, "versionedApp") {
4243
healthType = "app"
43-
} else {
44+
} else if v == "workload" || v == "service" {
4445
healthType = v
46+
} else {
47+
// For "mesh" or any other graphType, default to "app"
48+
healthType = "app"
4549
}
4650
}
4751
q.Set("type", healthType)

0 commit comments

Comments
 (0)