@@ -48,6 +48,7 @@ import (
48
48
"k8s.io/apimachinery/pkg/types"
49
49
"k8s.io/apimachinery/pkg/util/proxy"
50
50
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
51
+ "k8s.io/apimachinery/pkg/util/sets"
51
52
"k8s.io/apiserver/pkg/authentication/authenticator"
52
53
"k8s.io/apiserver/pkg/authorization/authorizer"
53
54
"k8s.io/apiserver/pkg/server/healthz"
@@ -90,7 +91,8 @@ type Server struct {
90
91
auth AuthInterface
91
92
host HostInterface
92
93
restfulCont containerInterface
93
- metricsBuckets map [string ]bool
94
+ metricsBuckets sets.String
95
+ metricsMethodBuckets sets.String
94
96
resourceAnalyzer stats.ResourceAnalyzer
95
97
redirectContainerStreaming bool
96
98
}
@@ -227,7 +229,8 @@ func NewServer(
227
229
resourceAnalyzer : resourceAnalyzer ,
228
230
auth : auth ,
229
231
restfulCont : & filteringContainer {Container : restful .NewContainer ()},
230
- metricsBuckets : make (map [string ]bool ),
232
+ metricsBuckets : sets .NewString (),
233
+ metricsMethodBuckets : sets .NewString ("OPTIONS" , "GET" , "HEAD" , "POST" , "PUT" , "DELETE" , "TRACE" , "CONNECT" ),
231
234
redirectContainerStreaming : redirectContainerStreaming ,
232
235
}
233
236
if auth != nil {
@@ -286,16 +289,24 @@ func (s *Server) InstallAuthFilter() {
286
289
// addMetricsBucketMatcher adds a regexp matcher and the relevant bucket to use when
287
290
// it matches. Please be aware this is not thread safe and should not be used dynamically
288
291
func (s * Server ) addMetricsBucketMatcher (bucket string ) {
289
- s .metricsBuckets [ bucket ] = true
292
+ s .metricsBuckets . Insert ( bucket )
290
293
}
291
294
292
295
// getMetricBucket find the appropriate metrics reporting bucket for the given path
293
296
func (s * Server ) getMetricBucket (path string ) string {
294
297
root := getURLRootPath (path )
295
- if s .metricsBuckets [ root ] == true {
298
+ if s .metricsBuckets . Has ( root ) {
296
299
return root
297
300
}
298
- return "Invalid path"
301
+ return "other"
302
+ }
303
+
304
+ // getMetricMethodBucket checks for unknown or invalid HTTP verbs
305
+ func (s * Server ) getMetricMethodBucket (method string ) string {
306
+ if s .metricsMethodBuckets .Has (method ) {
307
+ return method
308
+ }
309
+ return "other"
299
310
}
300
311
301
312
// InstallDefaultHandlers registers the default set of supported HTTP request
@@ -909,7 +920,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
909
920
serverType = "readwrite"
910
921
}
911
922
912
- method , path := req .Method , s .getMetricBucket (req .URL .Path )
923
+ method , path := s . getMetricMethodBucket ( req .Method ) , s .getMetricBucket (req .URL .Path )
913
924
914
925
longRunning := strconv .FormatBool (isLongRunningRequest (path ))
915
926
0 commit comments