promote /metrics to genericapiserver

This commit is contained in:
deads2k 2016-10-31 09:53:57 -04:00
parent f56cbfa8d5
commit 912e6741b9
7 changed files with 21 additions and 15 deletions

View File

@ -17,6 +17,7 @@ go_library(
"default_storage_factory_builder.go",
"doc.go",
"genericapiserver.go",
"healthz.go",
"hooks.go",
"resource_config.go",
"resource_encoding_config.go",
@ -48,6 +49,7 @@ go_library(
"//pkg/genericapiserver/options:go_default_library",
"//pkg/genericapiserver/routes:go_default_library",
"//pkg/genericapiserver/validation:go_default_library",
"//pkg/healthz:go_default_library",
"//pkg/registry/core/service/ipallocator:go_default_library",
"//pkg/registry/generic:go_default_library",
"//pkg/runtime:go_default_library",

View File

@ -81,6 +81,7 @@ type Config struct {
// allow downstream consumers to disable the index route
EnableIndex bool
EnableProfiling bool
EnableMetrics bool
EnableGarbageCollection bool
Version *version.Info
@ -524,6 +525,13 @@ func (s *GenericAPIServer) installAPI(c *Config) {
if c.EnableProfiling {
routes.Profiling{}.Install(s.HandlerContainer)
}
if c.EnableMetrics {
if c.EnableProfiling {
routes.MetricsWithReset{}.Install(s.HandlerContainer)
} else {
routes.DefaultMetrics{}.Install(s.HandlerContainer)
}
}
routes.Version{Version: c.Version}.Install(s.HandlerContainer)
s.HandlerContainer.Add(s.DynamicApisDiscovery())
}

View File

@ -15,6 +15,7 @@ go_library(
srcs = [
"doc.go",
"index.go",
"metrics.go",
"openapi.go",
"profiling.go",
"swagger.go",
@ -25,15 +26,18 @@ go_library(
deps = [
"//pkg/api/unversioned:go_default_library",
"//pkg/apiserver:go_default_library",
"//pkg/apiserver/metrics:go_default_library",
"//pkg/genericapiserver/mux:go_default_library",
"//pkg/genericapiserver/openapi:go_default_library",
"//pkg/genericapiserver/openapi/common:go_default_library",
"//pkg/genericapiserver/routes/data/swagger:go_default_library",
"//pkg/storage/etcd/metrics:go_default_library",
"//pkg/version:go_default_library",
"//vendor:github.com/elazarl/go-bindata-assetfs",
"//vendor:github.com/emicklei/go-restful",
"//vendor:github.com/emicklei/go-restful/swagger",
"//vendor:github.com/golang/glog",
"//vendor:github.com/prometheus/client_golang/prometheus",
],
)

View File

@ -30,6 +30,7 @@ import (
// DefaultMetrics installs the default prometheus metrics handler
type DefaultMetrics struct{}
// Install adds the DefaultMetrics handler
func (m DefaultMetrics) Install(c *mux.APIContainer) {
c.NonSwaggerRoutes.Handle("/metrics", prometheus.Handler())
}
@ -38,6 +39,7 @@ func (m DefaultMetrics) Install(c *mux.APIContainer) {
// which resets the metrics.
type MetricsWithReset struct{}
// Install adds the MetricsWithReset handler
func (m MetricsWithReset) Install(c *mux.APIContainer) {
defaultMetricsHandler := prometheus.Handler().ServeHTTP
c.NonSwaggerRoutes.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {

View File

@ -119,6 +119,9 @@ func (c *Config) Complete() completedConfig {
c.EndpointReconcilerConfig.Reconciler = NewMasterCountEndpointReconciler(c.GenericConfig.MasterCount, endpointClient)
}
// this has always been hardcoded true in the past
c.GenericConfig.EnableMetrics = true
return completedConfig{c}
}
@ -195,7 +198,6 @@ func (c completedConfig) New() (*Master, error) {
if c.Tunneler != nil {
m.installTunneler(c.Tunneler, coreclient.NewForConfigOrDie(c.GenericConfig.LoopbackClientConfig).Nodes())
}
m.InstallGeneralEndpoints(c.Config)
return m, nil
}
@ -227,16 +229,6 @@ func (m *Master) installTunneler(tunneler genericapiserver.Tunneler, nodeClient
}, func() float64 { return float64(tunneler.SecondsSinceSync()) })
}
// TODO this needs to be refactored so we have a way to add general health checks to genericapiserver
// TODO profiling should be generic
func (m *Master) InstallGeneralEndpoints(c *Config) {
if c.GenericConfig.EnableProfiling {
routes.MetricsWithReset{}.Install(m.GenericAPIServer.HandlerContainer)
} else {
routes.DefaultMetrics{}.Install(m.GenericAPIServer.HandlerContainer)
}
}
// InstallAPIs will install the APIs for the restStorageProviders if they are enabled.
func (m *Master) InstallAPIs(apiResourceConfigSource genericapiserver.APIResourceConfigSource, restOptionsGetter genericapiserver.RESTOptionsGetter, restStorageProviders ...genericapiserver.RESTStorageProvider) {
apiGroupsInfo := []genericapiserver.APIGroupInfo{}

View File

@ -15,15 +15,11 @@ go_library(
srcs = [
"doc.go",
"logs.go",
"metrics.go",
"ui.go",
],
tags = ["automanaged"],
deps = [
"//pkg/apiserver/metrics:go_default_library",
"//pkg/genericapiserver/mux:go_default_library",
"//pkg/storage/etcd/metrics:go_default_library",
"//vendor:github.com/emicklei/go-restful",
"//vendor:github.com/prometheus/client_golang/prometheus",
],
)

View File

@ -180,6 +180,7 @@ func startMasterOrDie(masterConfig *master.Config, incomingServer *httptest.Serv
if masterConfig == nil {
masterConfig = NewMasterConfig()
masterConfig.GenericConfig.EnableProfiling = true
masterConfig.GenericConfig.EnableMetrics = true
masterConfig.GenericConfig.EnableSwaggerSupport = true
masterConfig.GenericConfig.EnableOpenAPISupport = true
masterConfig.GenericConfig.OpenAPIConfig.Info = &spec.Info{
@ -451,6 +452,7 @@ func RunAMaster(masterConfig *master.Config) (*master.Master, *httptest.Server)
if masterConfig == nil {
masterConfig = NewMasterConfig()
masterConfig.GenericConfig.EnableProfiling = true
masterConfig.GenericConfig.EnableMetrics = true
}
return startMasterOrDie(masterConfig, nil, nil)
}