From 8f75efdf08242e4cf0915592eea0a45a6ca58e10 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Fri, 22 Jan 2021 08:41:15 -0800 Subject: [PATCH] Add uptime to the servicez debug page (#2385) Signed-off-by: Bogdan Drutu --- internal/version/version.go | 33 ++++++++++++++++++++++++--------- service/service.go | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/internal/version/version.go b/internal/version/version.go index 9e797c896c0..1413be74199 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" "runtime" + "time" ) const ( @@ -25,14 +26,23 @@ const ( buildRelease = "release" ) -// Version variable will be replaced at link time after `make` has been run. -var Version = "latest" +var ( + // Version variable will be replaced at link time after `make` has been run. + Version = "latest" -// GitHash variable will be replaced at link time after `make` has been run. -var GitHash = "" + // GitHash variable will be replaced at link time after `make` has been run. + GitHash = "" -// BuildType should be one of (dev, release). -var BuildType = buildDev + // BuildType should be one of (dev, release). + BuildType = buildDev + + // startTime + startTime time.Time +) + +func init() { + startTime = time.Now() +} // IsDevBuild returns true if this is a development (local) build. func IsDevBuild() bool { @@ -45,15 +55,20 @@ func IsReleaseBuild() bool { } // InfoVar is a singleton instance of the Info struct. -var InfoVar = Info([][2]string{ +var InfoVar = Info{ {"Version", Version}, {"GitHash", GitHash}, {"BuildType", BuildType}, - {"Goversion", runtime.Version()}, + {"GoVersion", runtime.Version()}, {"OS", runtime.GOOS}, {"Architecture", runtime.GOARCH}, // Add other valuable build-time information here. -}) +} + +// RuntimeVar returns the InfoVar plus runtime information like uptime. +func RuntimeVar() Info { + return append(InfoVar, [2]string{"StartTime", startTime.String()}, [2]string{"Uptime", time.Since(startTime).String()}) +} // Info has properties about the build and runtime. type Info [][2]string diff --git a/service/service.go b/service/service.go index d0ff423a199..6eff0286683 100644 --- a/service/service.go +++ b/service/service.go @@ -503,7 +503,7 @@ func (app *Application) handleServicezRequest(w http.ResponseWriter, r *http.Req ComponentEndpoint: extensionzPath, Link: true, }) - internal.WriteHTMLPropertiesTable(w, internal.PropertiesTableData{Name: "Build And Runtime", Properties: version.InfoVar}) + internal.WriteHTMLPropertiesTable(w, internal.PropertiesTableData{Name: "Build And Runtime", Properties: version.RuntimeVar()}) internal.WriteHTMLFooter(w) }