...
1
16
17 package metrics
18
19 import (
20 "fmt"
21
22 e2eperftype "k8s.io/kubernetes/test/e2e/perftype"
23 )
24
25
26 type APICall struct {
27 Resource string `json:"resource"`
28 Subresource string `json:"subresource"`
29 Verb string `json:"verb"`
30 Scope string `json:"scope"`
31 Latency LatencyMetric `json:"latency"`
32 Count int `json:"count"`
33 }
34
35
36 type APIResponsiveness struct {
37 APICalls []APICall `json:"apicalls"`
38 }
39
40
41 func (a *APIResponsiveness) SummaryKind() string {
42 return "APIResponsiveness"
43 }
44
45
46 func (a *APIResponsiveness) PrintHumanReadable() string {
47 return PrettyPrintJSON(a)
48 }
49
50
51 func (a *APIResponsiveness) PrintJSON() string {
52 return PrettyPrintJSON(APICallToPerfData(a))
53 }
54
55 func (a *APIResponsiveness) Len() int { return len(a.APICalls) }
56 func (a *APIResponsiveness) Swap(i, j int) {
57 a.APICalls[i], a.APICalls[j] = a.APICalls[j], a.APICalls[i]
58 }
59 func (a *APIResponsiveness) Less(i, j int) bool {
60 return a.APICalls[i].Latency.Perc99 < a.APICalls[j].Latency.Perc99
61 }
62
63
64
65 const currentAPICallMetricsVersion = "v1"
66
67
68 func APICallToPerfData(apicalls *APIResponsiveness) *e2eperftype.PerfData {
69 perfData := &e2eperftype.PerfData{Version: currentAPICallMetricsVersion}
70 for _, apicall := range apicalls.APICalls {
71 item := e2eperftype.DataItem{
72 Data: map[string]float64{
73 "Perc50": float64(apicall.Latency.Perc50) / 1000000,
74 "Perc90": float64(apicall.Latency.Perc90) / 1000000,
75 "Perc99": float64(apicall.Latency.Perc99) / 1000000,
76 },
77 Unit: "ms",
78 Labels: map[string]string{
79 "Verb": apicall.Verb,
80 "Resource": apicall.Resource,
81 "Subresource": apicall.Subresource,
82 "Scope": apicall.Scope,
83 "Count": fmt.Sprintf("%v", apicall.Count),
84 },
85 }
86 perfData.DataItems = append(perfData.DataItems, item)
87 }
88 return perfData
89 }
90
View as plain text