Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.

Commit 485fc6f

Browse files
author
Martin Chodur
committed
chore: cmd/tsdb: Refactored Makefile to use Makefile.common and fix build issues
1 parent d298c5a commit 485fc6f

File tree

2 files changed

+148
-9
lines changed

2 files changed

+148
-9
lines changed

cmd/tsdb/Makefile

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1+
# Copyright 2018 The Prometheus Authors
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
include Makefile.common
15+
16+
STATICCHECK_IGNORE =
17+
TSDB_BIN = "./tsdb"
18+
NUM_METRICS ?= 1000
19+
PROJECT_DIR = "../.."
20+
TEST_DATA_DIR ?= "$(PROJECT_DIR)/testdata"
21+
TEST_DATASET ?= "20kseries.json"
22+
BENCH_DIR ?= "./benchout"
23+
24+
ifdef DEBUG
25+
bindata_flags = -debug
26+
endif
27+
28+
# Since tsdb client yet has no tests we can at least try to run benchmark
29+
test: bench
30+
131
build:
2-
@go build .
3-
4-
bench: build
32+
@$(GO) build .
33+
34+
bench: build
535
@echo ">> running benchmark"
6-
@./tsdb bench write --metrics=$(NUM_METRICS) testdata.1m
7-
@go tool pprof -svg ./tsdb benchout/cpu.prof > benchout/cpuprof.svg
8-
@go tool pprof --inuse_space -svg ./tsdb benchout/mem.prof > benchout/memprof.inuse.svg
9-
@go tool pprof --alloc_space -svg ./tsdb benchout/mem.prof > benchout/memprof.alloc.svg
10-
@go tool pprof -svg ./tsdb benchout/block.prof > benchout/blockprof.svg
11-
@go tool pprof -svg ./tsdb benchout/mutex.prof > benchout/mutexprof.svg
36+
@$(TSDB_BIN) bench write --metrics=$(NUM_METRICS) $(TEST_DATA_DIR)/$(TEST_DATASET)
37+
38+
bench-vizualization: bench
39+
@command -v dot >/dev/null 2>&1 || echo "You need to have Graphviz installed to genrate pprof vizualization."
40+
@$(GO) tool pprof -svg ./tsdb $(BENCH_DIR)/cpu.prof > $(BENCH_DIR)/cpuprof.svg
41+
@$(GO) tool pprof --inuse_space -svg ./tsdb $(BENCH_DIR)/mem.prof > $(BENCH_DIR)/memprof.inuse.svg
42+
@$(GO) tool pprof --alloc_space -svg ./tsdb $(BENCH_DIR)/mem.prof > $(BENCH_DIR)/memprof.alloc.svg
43+
@$(GO) tool pprof -svg ./tsdb $(BENCH_DIR)/block.prof > $(BENCH_DIR)/blockprof.svg
44+
@$(GO) tool pprof -svg ./tsdb $(BENCH_DIR)/mutex.prof > $(BENCH_DIR)/mutexprof.svg
45+
46+
clean:
47+
rm -f $(TSDB_BIN)
48+
rm -rf $(BENCH_DIR)
49+
50+
.PHONY: clean test

cmd/tsdb/Makefile.common

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Copyright 2018 The Prometheus Authors
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
15+
# A common Makefile that includes rules to be reused in different prometheus projects.
16+
# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
17+
18+
# Example usage :
19+
# Create the main Makefile in the root project directory.
20+
# include Makefile.common
21+
# customTarget:
22+
# @echo ">> Running customTarget"
23+
#
24+
25+
# Ensure GOBIN is not set during build so that promu is installed to the correct path
26+
unexport GOBIN
27+
28+
GO ?= go
29+
GOFMT ?= $(GO)fmt
30+
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
31+
PROMU := $(FIRST_GOPATH)/bin/promu
32+
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
33+
GOVENDOR := $(FIRST_GOPATH)/bin/govendor
34+
pkgs = ./...
35+
36+
PREFIX ?= $(shell pwd)
37+
BIN_DIR ?= $(shell pwd)
38+
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
39+
40+
all: style staticcheck unused build test
41+
42+
style:
43+
@echo ">> checking code style"
44+
! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
45+
46+
check_license:
47+
@echo ">> checking license header"
48+
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
49+
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
50+
done); \
51+
if [ -n "$${licRes}" ]; then \
52+
echo "license header checking failed:"; echo "$${licRes}"; \
53+
exit 1; \
54+
fi
55+
56+
test-short:
57+
@echo ">> running short tests"
58+
$(GO) test -short $(pkgs)
59+
60+
test:
61+
@echo ">> running all tests"
62+
$(GO) test -race $(pkgs)
63+
64+
format:
65+
@echo ">> formatting code"
66+
$(GO) fmt $(pkgs)
67+
68+
vet:
69+
@echo ">> vetting code"
70+
$(GO) vet $(pkgs)
71+
72+
staticcheck: $(STATICCHECK)
73+
@echo ">> running staticcheck"
74+
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
75+
76+
unused: $(GOVENDOR)
77+
@echo ">> running check for unused packages"
78+
@$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
79+
80+
build: promu
81+
@echo ">> building binaries"
82+
$(PROMU) build --prefix $(PREFIX)
83+
84+
tarball: promu
85+
@echo ">> building release tarball"
86+
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
87+
88+
docker:
89+
docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
90+
91+
promu:
92+
GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu
93+
94+
$(FIRST_GOPATH)/bin/staticcheck:
95+
GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
96+
97+
$(FIRST_GOPATH)/bin/govendor:
98+
GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
99+
100+
.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck govendor $(FIRST_GOPATH)/bin/govendor

0 commit comments

Comments
 (0)