mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #23945 from smarterclayton/move_reset_metrics
Automatic merge from submit-queue 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). @wojtek-t
This commit is contained in:
commit
2b9637da6a
@ -46,7 +46,6 @@ import (
|
||||
|
||||
"github.com/emicklei/go-restful"
|
||||
"github.com/golang/glog"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -171,7 +170,6 @@ func (g *APIGroupVersion) newInstaller() *APIInstaller {
|
||||
func InstallSupport(mux Mux, ws *restful.WebService, checks ...healthz.HealthzChecker) {
|
||||
// TODO: convert healthz and metrics to restful and remove container arg
|
||||
healthz.InstallHandler(mux, checks...)
|
||||
mux.Handle("/metrics", prometheus.Handler())
|
||||
|
||||
// Set up a service to return the git code version.
|
||||
ws.Path("/version")
|
||||
|
@ -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
|
||||
|
@ -315,7 +315,7 @@ func VerifyPodStartupLatency(latency PodStartupLatency) error {
|
||||
// Resets latency metrics in apiserver.
|
||||
func ResetMetrics(c *client.Client) error {
|
||||
Logf("Resetting latency metrics in apiserver...")
|
||||
body, err := c.Get().AbsPath("/resetMetrics").DoRaw()
|
||||
body, err := c.Delete().AbsPath("/metrics").DoRaw()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user