Skip to content

Commit

Permalink
Merge pull request #2034 from mrueg/landingpage
Browse files Browse the repository at this point in the history
feat: Use exporter-toolkit landingpage
  • Loading branch information
k8s-ci-robot authored Mar 30, 2023
2 parents e58139d + 1529d94 commit 4efc9d1
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,24 @@ func buildTelemetryServer(registry prometheus.Gatherer) *http.ServeMux {

// Add metricsPath
mux.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorLog: promLogger{}}))

// Add index
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Kube-State-Metrics Metrics Server</title></head>
<body>
<h1>Kube-State-Metrics Metrics</h1>
<ul>
<li><a href='` + metricsPath + `'>metrics</a></li>
</ul>
</body>
</html>`))
})
landingConfig := web.LandingConfig{
Name: "kube-state-metrics",
Description: "Self-metrics for kube-state-metrics",
Version: version.Info(),
Links: []web.LandingLinks{
{
Address: metricsPath,
Text: "Metrics",
},
},
}
landingPage, err := web.NewLandingPage(landingConfig)
if err != nil {
klog.ErrorS(err, "failed to create landing page")
}
mux.Handle("/", landingPage)
return mux
}

Expand All @@ -402,19 +408,28 @@ func buildMetricsServer(m *metricshandler.MetricsHandler, durationObserver prome
w.WriteHeader(http.StatusOK)
w.Write([]byte(http.StatusText(http.StatusOK)))
})

// Add index
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Kube Metrics Server</title></head>
<body>
<h1>Kube Metrics</h1>
<ul>
<li><a href='` + metricsPath + `'>metrics</a></li>
<li><a href='` + healthzPath + `'>healthz</a></li>
</ul>
</body>
</html>`))
})
landingConfig := web.LandingConfig{
Name: "kube-state-metrics",
Description: "Metrics for Kubernetes' state",
Version: version.Info(),
Links: []web.LandingLinks{
{
Address: metricsPath,
Text: "Metrics",
},
{
Address: healthzPath,
Text: "Healthz",
},
},
}
landingPage, err := web.NewLandingPage(landingConfig)
if err != nil {
klog.ErrorS(err, "failed to create landing page")
}
mux.Handle("/", landingPage)
return mux
}

Expand Down

0 comments on commit 4efc9d1

Please sign in to comment.