forked from kubernetes-retired/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
98 lines (84 loc) · 3.04 KB
/
types.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"encoding/json"
"fmt"
"net/http"
"k8s.io/kubernetes/test/e2e/perftype"
node_perftype "k8s.io/kubernetes/test/e2e_node/perftype"
)
// DataPerBuild contains perf/time series data for a build.
type DataPerBuild struct {
Perf []perftype.DataItem `json:"perf,omitempty"`
Series []node_perftype.NodeTimeSeries `json:"series,omitempty"`
}
// DataPerNode contains perf/time series data for a node.
type DataPerNode map[string]*DataPerBuild
// DataPerTest contains perf/time series data for a test.
type DataPerTest struct {
Data map[string]DataPerNode `json:"data"`
Job string `json:"job"`
}
// TestToBuildData is a map from job name to DataPerTest.
type TestToBuildData map[string]*DataPerTest
// GetDataPerBuild creates a DataPerBuild structure for the given build using
// the specified job, test, and node if it does not exist, and then returns it.
func (b TestToBuildData) GetDataPerBuild(job, build, test, node string) *DataPerBuild {
if _, ok := b[test]; !ok {
b[test] = &DataPerTest{
Job: job,
Data: map[string]DataPerNode{},
}
}
if _, ok := b[test].Data[node]; !ok {
b[test].Data[node] = DataPerNode{}
}
if _, ok := b[test].Data[node][build]; !ok {
b[test].Data[node][build] = &DataPerBuild{}
}
return b[test].Data[node][build]
}
// ServeHTTP is the HTTP handler for serving TestToBuildData.
func (b TestToBuildData) ServeHTTP(res http.ResponseWriter, req *http.Request) {
data, err := json.Marshal(b)
if err != nil {
res.Header().Set("Content-type", "text/html")
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte(fmt.Sprintf("<h3>Internal Error</h3><p>%v", err)))
return
}
res.Header().Set("Content-type", "application/json")
res.WriteHeader(http.StatusOK)
res.Write(data)
}
// TestInfo contains the mapping from test name to test description.
type TestInfo struct {
// Info is a map from test name to test description.
// For example,
// "resource_0" -> "resource tracking for 0 pods per node [Benchmark]".
Info map[string]string `json:"info"`
}
// ServeHTTP is the HTTP handler for serving TestInfo.
func (b *TestInfo) ServeHTTP(res http.ResponseWriter, req *http.Request) {
data, err := json.Marshal(b)
if err != nil {
res.Header().Set("Content-type", "text/html")
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte(fmt.Sprintf("<h3>Internal Error</h3><p>%v", err)))
return
}
res.Header().Set("Content-type", "application/json")
res.WriteHeader(http.StatusOK)
res.Write(data)
}