-
Notifications
You must be signed in to change notification settings - Fork 474
/
dashboards.go
83 lines (76 loc) · 2.16 KB
/
dashboards.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package models
import (
"fmt"
"sort"
"github.com/kiali/k-charted/kubernetes/v1alpha1"
kmodel "github.com/kiali/k-charted/model"
"github.com/kiali/kiali/status"
)
// ConvertAggregations converts a k8s aggregations (from MonitoringDashboard k8s resource) into this models aggregations
// Results are sorted by DisplayName
func ConvertAggregations(from v1alpha1.MonitoringDashboardSpec) []kmodel.Aggregation {
uniqueAggs := make(map[string]kmodel.Aggregation)
for _, item := range from.Items {
for _, agg := range item.Chart.Aggregations {
uniqueAggs[agg.DisplayName] = kmodel.Aggregation{Label: agg.Label, DisplayName: agg.DisplayName}
}
}
aggs := []kmodel.Aggregation{}
for _, agg := range uniqueAggs {
aggs = append(aggs, agg)
}
sort.Slice(aggs, func(i, j int) bool {
return aggs[i].DisplayName < aggs[j].DisplayName
})
return aggs
}
func buildIstioAggregations(local, remote string) []kmodel.Aggregation {
appLabel := "app"
verLabel := "version"
if status.IstioSupportsCanonical() {
appLabel = "canonical_service"
verLabel = "canonical_revision"
}
aggs := []kmodel.Aggregation{
{
Label: fmt.Sprintf("%s_%s", local, verLabel),
DisplayName: "Local version",
},
}
if remote == "destination" {
aggs = append(aggs, kmodel.Aggregation{
Label: "destination_service_name",
DisplayName: "Remote service",
})
}
aggs = append(aggs, []kmodel.Aggregation{
{
Label: fmt.Sprintf("%s_%s", remote, appLabel),
DisplayName: "Remote app",
},
{
Label: fmt.Sprintf("%s_%s", remote, verLabel),
DisplayName: "Remote version",
},
{
Label: "response_code",
DisplayName: "Response code",
},
{
Label: "grpc_response_status",
DisplayName: "GRPC status",
},
{
Label: "response_flags",
DisplayName: "Response flags",
},
}...)
return aggs
}
// PrepareIstioDashboard prepares the Istio dashboard title and aggregations dynamically for input values
func PrepareIstioDashboard(direction, local, remote string) kmodel.MonitoringDashboard {
return kmodel.MonitoringDashboard{
Title: fmt.Sprintf("%s Metrics", direction),
Aggregations: buildIstioAggregations(local, remote),
}
}