mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
make api request verb can be overrided and make "GET" pod log request reported as "CONNECT" pod log request for metrics
This commit is contained in:
parent
bc35234269
commit
e49315f2db
@ -87,3 +87,14 @@ func (r *LogREST) Get(ctx genericapirequest.Context, name string, opts runtime.O
|
|||||||
func (r *LogREST) NewGetOptions() (runtime.Object, bool, string) {
|
func (r *LogREST) NewGetOptions() (runtime.Object, bool, string) {
|
||||||
return &api.PodLogOptions{}, false, ""
|
return &api.PodLogOptions{}, false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OverrideMetricsVerb override the GET verb to CONNECT for pod log resource
|
||||||
|
func (r *LogREST) OverrideMetricsVerb(oldVerb string) (newVerb string) {
|
||||||
|
newVerb = oldVerb
|
||||||
|
|
||||||
|
if oldVerb == "GET" {
|
||||||
|
newVerb = "CONNECT"
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -64,6 +64,12 @@ type action struct {
|
|||||||
AllNamespaces bool // true iff the action is namespaced but works on aggregate result for all namespaces
|
AllNamespaces bool // true iff the action is namespaced but works on aggregate result for all namespaces
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An interface to see if one storage supports override its default verb for monitoring
|
||||||
|
type StorageMetricsOverride interface {
|
||||||
|
// OverrideMetricsVerb gives a storage object an opportunity to override the verb reported to the metrics endpoint
|
||||||
|
OverrideMetricsVerb(oldVerb string) (newVerb string)
|
||||||
|
}
|
||||||
|
|
||||||
// An interface to see if an object supports swagger documentation as a method
|
// An interface to see if an object supports swagger documentation as a method
|
||||||
type documentable interface {
|
type documentable interface {
|
||||||
SwaggerDoc() map[string]string
|
SwaggerDoc() map[string]string
|
||||||
@ -593,6 +599,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
}
|
}
|
||||||
kind = fqParentKind.Kind
|
kind = fqParentKind.Kind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verbOverrider, needOverride := storage.(StorageMetricsOverride)
|
||||||
|
|
||||||
switch action.Verb {
|
switch action.Verb {
|
||||||
case "GET": // Get a resource.
|
case "GET": // Get a resource.
|
||||||
var handler restful.RouteFunction
|
var handler restful.RouteFunction
|
||||||
@ -601,7 +610,14 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||||||
} else {
|
} else {
|
||||||
handler = restfulGetResource(getter, exporter, reqScope)
|
handler = restfulGetResource(getter, exporter, reqScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if needOverride {
|
||||||
|
// need change the reported verb
|
||||||
|
handler = metrics.InstrumentRouteFunc(verbOverrider.OverrideMetricsVerb(action.Verb), resource, subresource, namespaceScope, handler)
|
||||||
|
} else {
|
||||||
handler = metrics.InstrumentRouteFunc(action.Verb, resource, subresource, namespaceScope, handler)
|
handler = metrics.InstrumentRouteFunc(action.Verb, resource, subresource, namespaceScope, handler)
|
||||||
|
}
|
||||||
|
|
||||||
if a.enableAPIResponseCompression {
|
if a.enableAPIResponseCompression {
|
||||||
handler = genericfilters.RestfulWithCompression(handler, a.group.Context)
|
handler = genericfilters.RestfulWithCompression(handler, a.group.Context)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user