mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 06:01:50 +00:00
Add monitoring instrumentation for the remaining HTTP handlers in the apiserver.
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
@@ -83,39 +84,51 @@ func isWebsocketRequest(req *http.Request) bool {
|
||||
|
||||
// ServeHTTP processes watch requests.
|
||||
func (h *WatchHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
var verb string
|
||||
var apiResource string
|
||||
var httpCode int
|
||||
reqStart := time.Now()
|
||||
defer func() { monitor("watch", verb, apiResource, httpCode, reqStart) }()
|
||||
|
||||
if req.Method != "GET" {
|
||||
notFound(w, req)
|
||||
httpCode = http.StatusNotFound
|
||||
return
|
||||
}
|
||||
|
||||
requestInfo, err := h.apiRequestInfoResolver.GetAPIRequestInfo(req)
|
||||
if err != nil {
|
||||
notFound(w, req)
|
||||
httpCode = http.StatusNotFound
|
||||
return
|
||||
}
|
||||
verb = requestInfo.Verb
|
||||
ctx := api.WithNamespace(api.NewContext(), requestInfo.Namespace)
|
||||
|
||||
storage := h.storage[requestInfo.Resource]
|
||||
if storage == nil {
|
||||
notFound(w, req)
|
||||
httpCode = http.StatusNotFound
|
||||
return
|
||||
}
|
||||
apiResource = requestInfo.Resource
|
||||
watcher, ok := storage.(ResourceWatcher)
|
||||
if !ok {
|
||||
errorJSON(errors.NewMethodNotSupported(requestInfo.Resource, "watch"), h.codec, w)
|
||||
httpCode = errorJSON(errors.NewMethodNotSupported(requestInfo.Resource, "watch"), h.codec, w)
|
||||
return
|
||||
}
|
||||
|
||||
label, field, resourceVersion, err := getWatchParams(req.URL.Query())
|
||||
if err != nil {
|
||||
errorJSON(err, h.codec, w)
|
||||
httpCode = errorJSON(err, h.codec, w)
|
||||
return
|
||||
}
|
||||
watching, err := watcher.Watch(ctx, label, field, resourceVersion)
|
||||
if err != nil {
|
||||
errorJSON(err, h.codec, w)
|
||||
httpCode = errorJSON(err, h.codec, w)
|
||||
return
|
||||
}
|
||||
httpCode = http.StatusOK
|
||||
|
||||
// TODO: This is one watch per connection. We want to multiplex, so that
|
||||
// multiple watches of the same thing don't create two watches downstream.
|
||||
|
Reference in New Issue
Block a user