3
3
4
4
package types
5
5
6
- // HTTP2ErrorStats is the report about http2 error during testing.
7
- type HTTP2ErrorStats struct {
8
- // ConnectionErrors represents connection level errors.
9
- ConnectionErrors map [string ]int32 `json:"connectionErrors,omitempty"`
10
- // StreamErrors represents stream level errors.
11
- StreamErrors map [string ]int32 `json:"streamErrors,omitempty"`
12
- }
13
-
14
- // NewHTTP2ErrorStats returns new instance of HTTP2ErrorStats.
15
- func NewHTTP2ErrorStats () * HTTP2ErrorStats {
16
- return & HTTP2ErrorStats {
17
- ConnectionErrors : make (map [string ]int32 , 10 ),
18
- StreamErrors : make (map [string ]int32 , 10 ),
19
- }
20
- }
21
-
22
- // ResponseErrorStats is the report about errors.
23
- type ResponseErrorStats struct {
24
- // UnknownErrors is all unknown errors.
25
- UnknownErrors []string `json:"unknownErrors"`
26
- // NetErrors is to track errors from net.
27
- NetErrors map [string ]int32 `json:"netErrors"`
28
- // ResponseCodes records request number grouped by response
29
- // code between 400 and 600.
30
- ResponseCodes map [int ]int32 `json:"responseCodes"`
31
- // HTTP2Errors records http2 related errors.
32
- HTTP2Errors HTTP2ErrorStats `json:"http2Errors"`
33
- }
34
-
35
- // NewResponseErrorStats returns empty ResponseErrorStats.
36
- func NewResponseErrorStats () * ResponseErrorStats {
37
- return & ResponseErrorStats {
38
- UnknownErrors : make ([]string , 0 , 1024 ),
39
- NetErrors : make (map [string ]int32 , 10 ),
40
- ResponseCodes : map [int ]int32 {},
41
- HTTP2Errors : * NewHTTP2ErrorStats (),
42
- }
43
- }
6
+ import "time"
44
7
45
- // Copy clones self.
46
- func (r * ResponseErrorStats ) Copy () ResponseErrorStats {
47
- res := NewResponseErrorStats ()
8
+ // ResponseErrorType is error type of response.
9
+ type ResponseErrorType string
48
10
49
- res .UnknownErrors = make ([]string , len (r .UnknownErrors ))
50
- copy (res .UnknownErrors , r .UnknownErrors )
51
- res .NetErrors = cloneMap (r .NetErrors )
52
- res .ResponseCodes = cloneMap (r .ResponseCodes )
53
- res .HTTP2Errors .ConnectionErrors = cloneMap (r .HTTP2Errors .ConnectionErrors )
54
- res .HTTP2Errors .StreamErrors = cloneMap (r .HTTP2Errors .StreamErrors )
55
- return * res
56
- }
11
+ const (
12
+ // ResponseErrorTypeUnknown indicates we don't have correct category for errors.
13
+ ResponseErrorTypeUnknown ResponseErrorType = "unknown"
14
+ // ResponseErrorTypeHTTP indicates that the response returns http code >= 400.
15
+ ResponseErrorTypeHTTP ResponseErrorType = "http"
16
+ // ResponseErrorTypeHTTP2Protocol indicates that error comes from http2 layer.
17
+ ResponseErrorTypeHTTP2Protocol ResponseErrorType = "http2-protocol"
18
+ // ResponseErrorTypeConnection indicates that error is related to connection.
19
+ // For instance, connection refused caused by server down.
20
+ ResponseErrorTypeConnection ResponseErrorType = "connection"
21
+ )
57
22
58
- // Merge merges two ResponseErrorStats.
59
- func (r * ResponseErrorStats ) Merge (from * ResponseErrorStats ) {
60
- r .UnknownErrors = append (r .UnknownErrors , from .UnknownErrors ... )
61
- mergeMap (r .NetErrors , from .NetErrors )
62
- mergeMap (r .ResponseCodes , from .ResponseCodes )
63
- mergeMap (r .HTTP2Errors .ConnectionErrors , from .HTTP2Errors .ConnectionErrors )
64
- mergeMap (r .HTTP2Errors .StreamErrors , from .HTTP2Errors .StreamErrors )
23
+ // ResponseError is the record about that error.
24
+ type ResponseError struct {
25
+ // Timestamp indicates when this error was received.
26
+ Timestamp time.Time `json:"timestamp"`
27
+ // Duration records timespan in seconds.
28
+ Duration float64 `json:"duration"`
29
+ // Type indicates that category to which the error belongs.
30
+ Type ResponseErrorType `json:"type"`
31
+ // Code only works when Type is http.
32
+ Code int `json:"code,omitempty"`
33
+ // Message shows error message for this error.
34
+ //
35
+ // NOTE: When Type is http, this field will be empty.
36
+ Message string `json:"message,omitempty"`
65
37
}
66
38
67
39
// ResponseStats is the report about benchmark result.
68
40
type ResponseStats struct {
69
- // ErrorStats means summary of errors.
70
- ErrorStats ResponseErrorStats
41
+ // Errors stores all the observed errors.
42
+ Errors [] ResponseError
71
43
// LatenciesByURL stores all the observed latencies for each request.
72
44
LatenciesByURL map [string ][]float64
73
45
// TotalReceivedBytes is total bytes read from apiserver.
@@ -79,8 +51,10 @@ type RunnerMetricReport struct {
79
51
Total int `json:"total"`
80
52
// Duration means the time of benchmark.
81
53
Duration string `json:"duration"`
82
- // ErrorStats means summary of errors.
83
- ErrorStats ResponseErrorStats `json:"errorStats"`
54
+ // Errors stores all the observed errors.
55
+ Errors []ResponseError `json:"errors,omitempty"`
56
+ // ErrorStats means summary of errors group by type.
57
+ ErrorStats map [string ]int32 `json:"errorStats,omitempty"`
84
58
// TotalReceivedBytes is total bytes read from apiserver.
85
59
TotalReceivedBytes int64 `json:"totalReceivedBytes"`
86
60
// LatenciesByURL stores all the observed latencies.
@@ -94,17 +68,3 @@ type RunnerMetricReport struct {
94
68
// TODO(weifu): build brand new struct for RunnerGroupsReport to include more
95
69
// information, like how many runner groups, service account and flow control.
96
70
type RunnerGroupsReport = RunnerMetricReport
97
-
98
- func mergeMap [K comparable , V int32 ](to , from map [K ]V ) {
99
- for key , value := range from {
100
- to [key ] += value
101
- }
102
- }
103
-
104
- func cloneMap [K comparable , V int32 ](src map [K ]V ) map [K ]V {
105
- res := map [K ]V {}
106
- for key , value := range src {
107
- res [key ] = value
108
- }
109
- return res
110
- }
0 commit comments