Skip to content

Commit

Permalink
pkg/apiserver: refactor InstrumentRouteFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
s-urbaniak committed Apr 18, 2019
1 parent 15832a3 commit 34298a0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ import (

"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/util/logs"
"k8s.io/component-base/logs"

basecmd "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/cmd"
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
Expand Down
36 changes: 33 additions & 3 deletions pkg/apiserver/installer/cmhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ func (ch *CMHandlers) registerResourceHandlers(a *MetricsAPIInstaller, ws *restf
},
}

rootScopedHandler := metrics.InstrumentRouteFunc("LIST", "custom-metrics", "", "cluster", restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout))
rootScopedHandler := metrics.InstrumentRouteFunc(
"LIST",
a.group.GroupVersion.Group,
a.group.GroupVersion.Version,
reqScope.Resource.Resource,
reqScope.Subresource,
"cluster",
"custom-metrics",
restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout),
)

// install the root-scoped route
rootScopedRoute := ws.GET(rootScopedPath).To(rootScopedHandler).
Expand All @@ -151,7 +160,17 @@ func (ch *CMHandlers) registerResourceHandlers(a *MetricsAPIInstaller, ws *restf
SelfLinkPathPrefix: gpath.Join(a.prefix, "namespaces") + "/",
},
}
namespacedHandler := metrics.InstrumentRouteFunc("LIST", "custom-metrics-namespaced", "", "namespace", restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout))
namespacedHandler := metrics.InstrumentRouteFunc(
"LIST",
a.group.GroupVersion.Group,
a.group.GroupVersion.Version,
reqScope.Resource.Resource,
reqScope.Subresource,
"resource",
"custom-metrics",
restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout),
)

namespacedRoute := ws.GET(namespacedPath).To(namespacedHandler).
Doc(doc).
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
Expand All @@ -173,7 +192,18 @@ func (ch *CMHandlers) registerResourceHandlers(a *MetricsAPIInstaller, ws *restf
SelfLinkPathPrefix: gpath.Join(a.prefix, "namespaces") + "/",
},
}
namespaceSpecificHandler := metrics.InstrumentRouteFunc("LIST", "custom-metrics-for-namespace", "", "cluster", restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout))

namespaceSpecificHandler := metrics.InstrumentRouteFunc(
"LIST",
a.group.GroupVersion.Group,
a.group.GroupVersion.Version,
reqScope.Resource.Resource,
reqScope.Subresource,
"resource",
"custom-metrics",
restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout),
)

namespaceSpecificRoute := ws.GET(namespaceSpecificPath).To(namespaceSpecificHandler).
Doc(doc).
Param(ws.QueryParameter("pretty", "If 'true', then the output is pretty printed.")).
Expand Down
11 changes: 10 additions & 1 deletion pkg/apiserver/installer/emhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ func (ch *EMHandlers) registerResourceHandlers(a *MetricsAPIInstaller, ws *restf
},
}

externalMetricHandler := metrics.InstrumentRouteFunc("LIST", "external-metrics", "", "", restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout))
externalMetricHandler := metrics.InstrumentRouteFunc(
"LIST",
a.group.GroupVersion.Group,
a.group.GroupVersion.Version,
reqScope.Resource.Resource,
reqScope.Subresource,
"cluster",
"external-metrics",
restfulListResource(lister, nil, reqScope, false, a.minRequestTimeout),
)

externalMetricRoute := ws.GET(externalMetricPath).To(externalMetricHandler).
Doc(doc).
Expand Down
2 changes: 1 addition & 1 deletion test-adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/emicklei/go-restful"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/util/logs"
"k8s.io/component-base/logs"

basecmd "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/cmd"
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
Expand Down

0 comments on commit 34298a0

Please sign in to comment.