@@ -44,6 +44,7 @@ import (
44
44
const (
45
45
sharedConcurrencyMetricsName = "apiserver_flowcontrol_request_concurrency_limit"
46
46
dispatchedRequestCountMetricsName = "apiserver_flowcontrol_dispatched_requests_total"
47
+ rejectedRequestCountMetricsName = "apiserver_flowcontrol_rejected_requests_total"
47
48
labelPriorityLevel = "priorityLevel"
48
49
timeout = time .Second * 10
49
50
)
@@ -122,13 +123,20 @@ func TestPriorityLevelIsolation(t *testing.T) {
122
123
123
124
time .Sleep (time .Second * 10 ) // running in background for a while
124
125
125
- reqCounts , err := getRequestCountOfPriorityLevel (loopbackClient )
126
+ allDispatchedReqCounts , rejectedReqCounts , err := getRequestCountOfPriorityLevel (loopbackClient )
126
127
if err != nil {
127
128
t .Error (err )
128
129
}
129
130
130
- noxu1RequestCount := reqCounts [priorityLevelNoxu1 .Name ]
131
- noxu2RequestCount := reqCounts [priorityLevelNoxu2 .Name ]
131
+ noxu1RequestCount := allDispatchedReqCounts [priorityLevelNoxu1 .Name ]
132
+ noxu2RequestCount := allDispatchedReqCounts [priorityLevelNoxu2 .Name ]
133
+
134
+ if rejectedReqCounts [priorityLevelNoxu1 .Name ] > 0 {
135
+ t .Errorf (`%v requests from the "elephant" stream were rejected unexpectedly` , rejectedReqCounts [priorityLevelNoxu2 .Name ])
136
+ }
137
+ if rejectedReqCounts [priorityLevelNoxu2 .Name ] > 0 {
138
+ t .Errorf (`%v requests from the "mouse" stream were rejected unexpectedly` , rejectedReqCounts [priorityLevelNoxu2 .Name ])
139
+ }
132
140
133
141
// Theoretically, the actual expected value of request counts upon the two priority-level should be
134
142
// the equal. We're deliberately lax to make flakes super rare.
@@ -192,10 +200,10 @@ func getSharedConcurrencyOfPriorityLevel(c clientset.Interface) (map[string]int,
192
200
}
193
201
}
194
202
195
- func getRequestCountOfPriorityLevel (c clientset.Interface ) (map [string ]int , error ) {
203
+ func getRequestCountOfPriorityLevel (c clientset.Interface ) (map [string ]int , map [ string ] int , error ) {
196
204
resp , err := getMetrics (c )
197
205
if err != nil {
198
- return nil , err
206
+ return nil , nil , err
199
207
}
200
208
201
209
dec := expfmt .NewDecoder (strings .NewReader (string (resp )), expfmt .FmtText )
@@ -204,20 +212,23 @@ func getRequestCountOfPriorityLevel(c clientset.Interface) (map[string]int, erro
204
212
Opts : & expfmt.DecodeOptions {},
205
213
}
206
214
207
- reqCounts := make (map [string ]int )
215
+ allReqCounts := make (map [string ]int )
216
+ rejectReqCounts := make (map [string ]int )
208
217
for {
209
218
var v model.Vector
210
219
if err := decoder .Decode (& v ); err != nil {
211
220
if err == io .EOF {
212
221
// Expected loop termination condition.
213
- return reqCounts , nil
222
+ return allReqCounts , rejectReqCounts , nil
214
223
}
215
- return nil , fmt .Errorf ("failed decoding metrics: %v" , err )
224
+ return nil , nil , fmt .Errorf ("failed decoding metrics: %v" , err )
216
225
}
217
226
for _ , metric := range v {
218
227
switch name := string (metric .Metric [model .MetricNameLabel ]); name {
219
228
case dispatchedRequestCountMetricsName :
220
- reqCounts [string (metric .Metric [labelPriorityLevel ])] = int (metric .Value )
229
+ allReqCounts [string (metric .Metric [labelPriorityLevel ])] = int (metric .Value )
230
+ case rejectedRequestCountMetricsName :
231
+ rejectReqCounts [string (metric .Metric [labelPriorityLevel ])] = int (metric .Value )
221
232
}
222
233
}
223
234
}
0 commit comments