Skip to content

Commit

Permalink
Add uptime to the servicez debug page (#2385)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Jan 22, 2021
1 parent 5194f3f commit 8f75efd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 24 additions & 9 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,31 @@ import (
"bytes"
"fmt"
"runtime"
"time"
)

const (
buildDev = "dev"
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 = "<NOT PROPERLY GENERATED>"
// GitHash variable will be replaced at link time after `make` has been run.
GitHash = "<NOT PROPERLY GENERATED>"

// 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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 8f75efd

Please sign in to comment.