Move /resetMetrics to DELETE /metrics

Reduces the surface area of the API server slightly and allows
downstream components to have deleteable metrics. After this change
genericapiserver will *not* have metrics unless the caller defines it
(allows different apiserver implementations to make that choice on their
own).
This commit is contained in:
Clayton Coleman
2016-04-06 17:52:28 -04:00
parent ff1da7674d
commit 0f95b91f96
3 changed files with 16 additions and 8 deletions

View File

@@ -175,10 +175,17 @@ func New(c *Config) (*Master, error) {
return m, nil
}
func resetMetrics(w http.ResponseWriter, req *http.Request) {
apiservermetrics.Reset()
etcdmetrics.Reset()
io.WriteString(w, "metrics reset\n")
var defaultMetricsHandler = prometheus.Handler().ServeHTTP
// MetricsWithReset is a handler that resets metrics when DELETE is passed to the endpoint.
func MetricsWithReset(w http.ResponseWriter, req *http.Request) {
if req.Method == "DELETE" {
apiservermetrics.Reset()
etcdmetrics.Reset()
io.WriteString(w, "metrics reset\n")
return
}
defaultMetricsHandler(w, req)
}
func (m *Master) InstallAPIs(c *Config) {
@@ -220,8 +227,11 @@ func (m *Master) InstallAPIs(c *Config) {
// TODO(nikhiljindal): Refactor generic parts of support services (like /versions) to genericapiserver.
apiserver.InstallSupport(m.MuxHelper, m.RootWebService, healthzChecks...)
if c.EnableProfiling {
m.MuxHelper.HandleFunc("/resetMetrics", resetMetrics)
m.MuxHelper.HandleFunc("/metrics", MetricsWithReset)
} else {
m.MuxHelper.HandleFunc("/metrics", defaultMetricsHandler)
}
// Install root web services