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

ui: react: Add runtime and build info page #2832

Merged
merged 7 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 32 additions & 0 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"math"
"net/http"
"os"
"runtime"
"strings"
"time"

Expand All @@ -19,6 +21,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/common/route"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/discovery/file"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/pkg/labels"
Expand Down Expand Up @@ -404,6 +407,15 @@ func runQuery(
router = router.WithPrefix(webRoutePrefix)
}

buildInfo := &v1.ThanosVersion{
Version: version.Version,
Revision: version.Revision,
Branch: version.Branch,
BuildUser: version.BuildUser,
BuildDate: version.BuildDate,
GoVersion: version.GoVersion,
}

ins := extpromhttp.NewInstrumentationMiddleware(reg)
// TODO(bplotka in PR #513 review): pass all flags, not only the flags needed by prefix rewriting.
ui.NewQueryUI(logger, reg, stores, webExternalPrefix, webPrefixHeaderName).Register(router, ins)
Expand All @@ -423,6 +435,8 @@ func runQuery(
flagsMap,
instantDefaultMaxSourceResolution,
maxConcurrentQueries,
runtimeInfo,
buildInfo,
onprem marked this conversation as resolved.
Show resolved Hide resolved
)

api.Register(router.WithPrefix("/api/v1"), tracer, logger, ins)
Expand Down Expand Up @@ -470,6 +484,24 @@ func runQuery(
return nil
}

func runtimeInfo() v1.RuntimeInfo {
cwd, err := os.Getwd()
if err != nil {
cwd = "<error retrieving current working directory>"
onprem marked this conversation as resolved.
Show resolved Hide resolved
}

status := v1.RuntimeInfo{
StartTime: time.Now().UTC(),
CWD: cwd,
onprem marked this conversation as resolved.
Show resolved Hide resolved
GoroutineCount: runtime.NumGoroutine(),
GOMAXPROCS: runtime.GOMAXPROCS(0),
GOGC: os.Getenv("GOGC"),
GODEBUG: os.Getenv("GODEBUG"),
}

return status
}

func removeDuplicateStoreSpecs(logger log.Logger, duplicatedStores prometheus.Counter, specs []query.StoreSpec) []query.StoreSpec {
set := make(map[string]query.StoreSpec)
for _, spec := range specs {
Expand Down
36 changes: 36 additions & 0 deletions pkg/query/api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ func (e *ApiError) Error() string {
return fmt.Sprintf("%s: %s", e.Typ, e.Err)
}

// ThanosVersion contains build information about Thanos.
type ThanosVersion struct {
onprem marked this conversation as resolved.
Show resolved Hide resolved
Version string `json:"version"`
Revision string `json:"revision"`
Branch string `json:"branch"`
BuildUser string `json:"buildUser"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
}

// RuntimeInfo contains runtime information about Thanos.
type RuntimeInfo struct {
StartTime time.Time `json:"startTime"`
CWD string `json:"CWD"`
GoroutineCount int `json:"goroutineCount"`
GOMAXPROCS int `json:"GOMAXPROCS"`
GOGC string `json:"GOGC"`
GODEBUG string `json:"GODEBUG"`
}

type response struct {
Status status `json:"status"`
Data interface{} `json:"data,omitempty"`
Expand Down Expand Up @@ -119,6 +139,8 @@ type API struct {
enableRulePartialResponse bool
replicaLabels []string
flagsMap map[string]string
runtimeInfo func() RuntimeInfo
buildInfo *ThanosVersion

storeSet *query.StoreSet
defaultInstantQueryMaxSourceResolution time.Duration
Expand All @@ -141,6 +163,8 @@ func NewAPI(
flagsMap map[string]string,
defaultInstantQueryMaxSourceResolution time.Duration,
maxConcurrentQueries int,
runtimeInfo func() RuntimeInfo,
buildInfo *ThanosVersion,
) *API {
return &API{
logger: logger,
Expand All @@ -157,6 +181,8 @@ func NewAPI(
flagsMap: flagsMap,
storeSet: storeSet,
defaultInstantQueryMaxSourceResolution: defaultInstantQueryMaxSourceResolution,
runtimeInfo: runtimeInfo,
buildInfo: buildInfo,

now: time.Now,
}
Expand Down Expand Up @@ -195,6 +221,8 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.
r.Post("/labels", instr("label_names", api.labelNames))

r.Get("/status/flags", instr("status_flags", api.flags))
r.Get("/status/runtimeinfo", instr("status_runtime", api.serveRuntimeInfo))
r.Get("/status/buildinfo", instr("status_build", api.serveBuildInfo))

r.Get("/stores", instr("stores", api.stores))

Expand Down Expand Up @@ -683,6 +711,14 @@ func (api *API) flags(r *http.Request) (interface{}, []error, *ApiError) {
return api.flagsMap, nil, nil
}

func (api *API) serveRuntimeInfo(r *http.Request) (interface{}, []error, *ApiError) {
return api.runtimeInfo(), nil, nil
}

func (api *API) serveBuildInfo(r *http.Request) (interface{}, []error, *ApiError) {
return api.buildInfo, nil, nil
}

// NewRulesHandler created handler compatible with HTTP /api/v1/rules https://prometheus.io/docs/prometheus/latest/querying/api/#rules
// which uses gRPC Unary Rules API.
func NewRulesHandler(client rules.UnaryClient, enablePartialResponse bool) func(*http.Request) (interface{}, []error, *ApiError) {
Expand Down
Loading