Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uptime to the servicez debug page #2385

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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