Skip to content

Commit

Permalink
ui: add React UI from upstream Prometheus
Browse files Browse the repository at this point in the history
Signed-off-by: Adrien Fillon <[email protected]>
  • Loading branch information
adrien-f committed Feb 12, 2020
1 parent 573eff4 commit 19cf55b
Show file tree
Hide file tree
Showing 114 changed files with 23,774 additions and 121 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
exit
fi
taskset 2 make test-ci
taskset 2 make react-app-test
# Cross build is needed for publish_release but needs to be done outside of docker.
cross_build:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ website/public/
website/docs-pre-processed/
!website/data

# React build assets
pkg/ui/static/react

tmp/bin
examples/tmp/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ We use *breaking* word for marking changes that are not backward compatible (rel
- [#2030](https://github.com/thanos-io/thanos/pull/2030) Query: Add `thanos_proxy_store_empty_stream_responses_total` metric for number of empty responses from stores.
- [#2049](https://github.com/thanos-io/thanos/pull/2049) Tracing: Support sampling on Elastic APM with new sample_rate setting.
- [#2008](https://github.com/thanos-io/thanos/pull/2008) Querier, Receiver, Sidecar, Store: Add gRPC [health check](https://github.com/grpc/grpc/blob/master/doc/health-checking.md) endpoints.
- [#2121](https://github.com/thanos-io/thanos/pull/2121) ui: Add React UI from Prometheus upstream

### Changed

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Adding a large new feature or/and component to Thanos should be done by first cr
## Prerequisites

* It is strongly recommended that you use OSX or popular Linux distributions systems e.g. Ubuntu, Redhat, or OpenSUSE for development.
* You will need a working NodeJS environment and the Yarn package manager to compile the Web UI assets

## Components Naming

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.thanos-ci
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Available from https://hub.docker.com/r/circleci/golang/
FROM circleci/golang:1.13.6
FROM circleci/golang:1.13.6-node

ENV GOBIN=/go/bin

Expand Down
71 changes: 53 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ ALERTMANAGER ?= $(GOBIN)/alertmanager-$(ALERTMANAGER_VERSION)
MINIO_SERVER_VERSION ?= RELEASE.2018-10-06T00-15-16Z
MINIO_SERVER ?=$(GOBIN)/minio-$(MINIO_SERVER_VERSION)

REACT_APP_PATH = pkg/ui/react-app
REACT_APP_SOURCE_FILES = $(wildcard $(REACT_APP_PATH)/public/* $(REACT_APP_PATH)/src/* $(REACT_APP_PATH)/tsconfig.json)
REACT_APP_OUTPUT_DIR = pkg/ui/static/react
REACT_APP_NODE_MODULES_PATH = $(REACT_APP_PATH)/node_modules
REACT_APP_NPM_LICENSES_TARBALL = "npm_licenses.tar.bz2"

# fetch_go_bin_version downloads (go gets) the binary from specific version and installs it in $(GOBIN)/<bin>-<version>
# arguments:
# $(1): Install path. (e.g github.com/campoy/embedmd)
Expand All @@ -88,9 +94,9 @@ define fetch_go_bin_version

@echo ">> fetching $(1)@$(2) revision/version"
@if [ ! -d '$(TMP_GOPATH)/src/$(1)' ]; then \
GOPATH='$(TMP_GOPATH)' GO111MODULE='off' go get -d -u '$(1)/...'; \
GOPATH='$(TMP_GOPATH)' GO111MODULE='off' go get -d -u '$(1)/...'; \
else \
CDPATH='' cd -- '$(TMP_GOPATH)/src/$(1)' && git fetch; \
CDPATH='' cd -- '$(TMP_GOPATH)/src/$(1)' && git fetch; \
fi
@CDPATH='' cd -- '$(TMP_GOPATH)/src/$(1)' && git checkout -f -q '$(2)'
@echo ">> installing $(1)@$(2)"
Expand All @@ -103,34 +109,60 @@ endef
define require_clean_work_tree
@git update-index -q --ignore-submodules --refresh

@if ! git diff-files --quiet --ignore-submodules --; then \
echo >&2 "cannot $1: you have unstaged changes."; \
git diff-files --name-status -r --ignore-submodules -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi
@if ! git diff-files --quiet --ignore-submodules --; then \
echo >&2 "cannot $1: you have unstaged changes."; \
git diff-files --name-status -r --ignore-submodules -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi

@if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \
echo >&2 "cannot $1: your index contains uncommitted changes."; \
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi
@if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \
echo >&2 "cannot $1: your index contains uncommitted changes."; \
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi

endef

.PHONY: all
all: format build

$(REACT_APP_NODE_MODULES_PATH): $(REACT_APP_PATH)/package.json $(REACT_APP_PATH)/yarn.lock
cd $(REACT_APP_PATH) && yarn --frozen-lockfile

$(REACT_APP_OUTPUT_DIR): $(REACT_APP_NODE_MODULES_PATH) $(REACT_APP_SOURCE_FILES)
@echo ">> building React app"
@./scripts/build-react-app.sh

# assets repacks all static assets into go file for easier deploy.
.PHONY: assets
assets: $(GOBINDATA)
assets: $(GOBINDATA) $(REACT_APP_OUTPUT_DIR)
@echo ">> deleting asset file"
@rm pkg/ui/bindata.go || true
@echo ">> writing assets"
@$(GOBINDATA) $(bindata_flags) -pkg ui -o pkg/ui/bindata.go -ignore '(.*\.map|bootstrap\.js|bootstrap-theme\.css|bootstrap\.css)' pkg/ui/templates/... pkg/ui/static/...
@go fmt ./pkg/ui

.PHONY: react-app-lint
react-app-lint:
@echo ">> running React app linting"
cd $(REACT_APP_PATH) && yarn lint:ci

.PHONY: react-app-lint-fix
react-app-lint-fix:
@echo ">> running React app linting and fixing errors where possible"
cd $(REACT_APP_PATH) && yarn lint

.PHONY: react-app-test
react-app-test: | $(REACT_APP_NODE_MODULES_PATH) react-app-lint
@echo ">> running React app tests"
cd $(REACT_APP_PATH) && yarn test --no-watch --coverage

.PHONY: react-app-start
react-app-start: $(REACT_APP_NODE_MODULES_PATH)
@echo ">> running React app"
cd $(REACT_APP_PATH) && yarn start

# build builds Thanos binary using `promu`.
.PHONY: build
Expand Down Expand Up @@ -282,20 +314,23 @@ web: web-pre-process $(HUGO)
# TODO(bwplotka): Make it --gc
@cd $(WEB_DIR) && HUGO_ENV=production $(HUGO) --config hugo.yaml --minify -v -b $(WEBSITE_BASE_URL)

.PHONY: lint
.PHONY:lint
lint: go-lint react-app-lint

.PHONY: go-lint
# PROTIP:
# Add
# --cpu-profile-path string Path to CPU profile output file
# --mem-profile-path string Path to memory profile output file
#
# to debug big allocations during linting.
lint: check-git $(GOLANGCILINT) $(MISSPELL)
go-lint: check-git $(GOLANGCILINT) $(MISSPELL)
@echo ">> examining all of the Go files"
@go vet -stdmethods=false ./pkg/... ./cmd/... && go vet doc.go
@echo ">> linting all of the Go files GOGC=${GOGC}"
@$(GOLANGCILINT) run
@echo ">> detecting misspells"
@find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error
@find . -type f | grep -v vendor/ | grep -v pkg/ui/react-app/node_modules | grep -v pkg/ui/static | grep -vE '\./\..*' | xargs $(MISSPELL) -error
@echo ">> detecting white noise"
@find . -type f \( -name "*.md" -o -name "*.go" \) | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh
$(call require_clean_work_tree,"detected white noise")
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func runQuery(
ins := extpromhttp.NewInstrumentationMiddleware(reg)
ui.NewQueryUI(logger, reg, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins)

api := v1.NewAPI(logger, reg, engine, queryableCreator, enableAutodownsampling, enablePartialResponse, replicaLabels, instantDefaultMaxSourceResolution)
api := v1.NewAPI(logger, reg, stores, engine, queryableCreator, enableAutodownsampling, enablePartialResponse, replicaLabels, instantDefaultMaxSourceResolution)

api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger, ins)

Expand Down
15 changes: 15 additions & 0 deletions pkg/query/api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type API struct {
enablePartialResponse bool
replicaLabels []string
reg prometheus.Registerer
storeSet *query.StoreSet
defaultInstantQueryMaxSourceResolution time.Duration

now func() time.Time
Expand All @@ -116,6 +117,7 @@ type API struct {
func NewAPI(
logger log.Logger,
reg *prometheus.Registry,
storeSet *query.StoreSet,
qe *promql.Engine,
c query.QueryableCreator,
enableAutodownsampling bool,
Expand All @@ -131,6 +133,7 @@ func NewAPI(
enablePartialResponse: enablePartialResponse,
replicaLabels: replicaLabels,
reg: reg,
storeSet: storeSet,
defaultInstantQueryMaxSourceResolution: defaultInstantQueryMaxSourceResolution,

now: time.Now,
Expand Down Expand Up @@ -168,6 +171,8 @@ func (api *API) Register(r *route.Router, tracer opentracing.Tracer, logger log.

r.Get("/labels", instr("label_names", api.labelNames))
r.Post("/labels", instr("label_names", api.labelNames))

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

type queryData struct {
Expand All @@ -178,6 +183,8 @@ type queryData struct {
Warnings []error `json:"warnings,omitempty"`
}

type storesData map[string][]query.StoreStatus

func (api *API) parseEnableDedupParam(r *http.Request) (enableDeduplication bool, _ *ApiError) {
const dedupParam = "dedup"
enableDeduplication = true
Expand Down Expand Up @@ -626,3 +633,11 @@ func (api *API) labelNames(r *http.Request) (interface{}, []error, *ApiError) {

return names, warnings, nil
}

func (api *API) stores(r *http.Request) (interface{}, []error, *ApiError) {
statuses := make(storesData)
for _, status := range api.storeSet.GetStoreStatus() {
statuses[status.StoreType.String()] = append(statuses[status.StoreType.String()], status)
}
return statuses, nil, nil
}
14 changes: 7 additions & 7 deletions pkg/query/storeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ type StoreSpec interface {
}

type StoreStatus struct {
Name string
LastCheck time.Time
LastError error
LabelSets []storepb.LabelSet
StoreType component.StoreAPI
MinTime int64
MaxTime int64
Name string `json:"name"`
LastCheck time.Time `json:"last_check"`
LastError error `json:"last_error"`
LabelSets []storepb.LabelSet `json:"label_sets"`
StoreType component.StoreAPI `json:"store_type"`
MinTime int64 `json:"min_time"`
MaxTime int64 `json:"max_time"`
}

type grpcStoreSpec struct {
Expand Down
Loading

0 comments on commit 19cf55b

Please sign in to comment.