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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user