Skip to content

Commit 1529d94

Browse files
committed
feat: Use exporter-toolkit landingpage
Signed-off-by: Manuel Rüger <[email protected]>
1 parent b76e410 commit 1529d94

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

pkg/app/server.go

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -370,18 +370,24 @@ func buildTelemetryServer(registry prometheus.Gatherer) *http.ServeMux {
370370

371371
// Add metricsPath
372372
mux.Handle(metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorLog: promLogger{}}))
373+
373374
// Add index
374-
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
375-
w.Write([]byte(`<html>
376-
<head><title>Kube-State-Metrics Metrics Server</title></head>
377-
<body>
378-
<h1>Kube-State-Metrics Metrics</h1>
379-
<ul>
380-
<li><a href='` + metricsPath + `'>metrics</a></li>
381-
</ul>
382-
</body>
383-
</html>`))
384-
})
375+
landingConfig := web.LandingConfig{
376+
Name: "kube-state-metrics",
377+
Description: "Self-metrics for kube-state-metrics",
378+
Version: version.Info(),
379+
Links: []web.LandingLinks{
380+
{
381+
Address: metricsPath,
382+
Text: "Metrics",
383+
},
384+
},
385+
}
386+
landingPage, err := web.NewLandingPage(landingConfig)
387+
if err != nil {
388+
klog.ErrorS(err, "failed to create landing page")
389+
}
390+
mux.Handle("/", landingPage)
385391
return mux
386392
}
387393

@@ -402,19 +408,28 @@ func buildMetricsServer(m *metricshandler.MetricsHandler, durationObserver prome
402408
w.WriteHeader(http.StatusOK)
403409
w.Write([]byte(http.StatusText(http.StatusOK)))
404410
})
411+
405412
// Add index
406-
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
407-
w.Write([]byte(`<html>
408-
<head><title>Kube Metrics Server</title></head>
409-
<body>
410-
<h1>Kube Metrics</h1>
411-
<ul>
412-
<li><a href='` + metricsPath + `'>metrics</a></li>
413-
<li><a href='` + healthzPath + `'>healthz</a></li>
414-
</ul>
415-
</body>
416-
</html>`))
417-
})
413+
landingConfig := web.LandingConfig{
414+
Name: "kube-state-metrics",
415+
Description: "Metrics for Kubernetes' state",
416+
Version: version.Info(),
417+
Links: []web.LandingLinks{
418+
{
419+
Address: metricsPath,
420+
Text: "Metrics",
421+
},
422+
{
423+
Address: healthzPath,
424+
Text: "Healthz",
425+
},
426+
},
427+
}
428+
landingPage, err := web.NewLandingPage(landingConfig)
429+
if err != nil {
430+
klog.ErrorS(err, "failed to create landing page")
431+
}
432+
mux.Handle("/", landingPage)
418433
return mux
419434
}
420435

0 commit comments

Comments
 (0)