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