forked from thanos-io/promql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
122 lines (101 loc) · 4.75 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
include .bingo/Variables.mk
FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print)
MDOX_VALIDATE_CONFIG ?= .mdox.validate.yaml
# if macos, use gsed
SED ?= $(shell which gsed 2>/dev/null || which sed)
GOMODULES = $(shell go list ./...)
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-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
help: ## Displays help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-z0-9A-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
.PHONY: test
test: ## Runs all Go unit tests.
@echo ">> running unit tests (without cache)"
@rm -rf /tmp/engine-cache
@GORACE=atexit_sleep_ms=0 GOCACHE=/tmp/engine-cache go test -race -timeout=10m $(GOMODULES);
.PHONY: test-fast
test-fast: ## Runs all Go unit tests without race detector.
@echo ">> running unit tests without race detection (with cache)"
@go test -count=1 -timeout=10m $(GOMODULES);
.PHONY: test-stringlabels
test-stringlabels: ## Runs all Go unit tests with stringlabels flag.
@export GOCACHE=/tmp/cache
@echo ">> running unit tests with stringlabels flag (without cache)"
@rm -rf $(GOCACHE)
@go test -race --tags=stringlabels -timeout=10m $(GOMODULES);
.PHONY: fuzz
fuzz: ## Runs selected fuzzing tests
@export GOCACHE=/tmp/cache
@echo ">> running fuzz tests (without cache)"
@rm -rf $(GOCACHE)
@go test github.com/thanos-io/promql-engine/engine -run None -fuzz FuzzEnginePromQLSmithInstantQuery -fuzztime=2m -fuzzminimizetime 0x;
.PHONY: deps
deps: ## Ensures fresh go.mod and go.sum.
@go mod tidy
@go mod verify
.PHONY: docs
docs: ## Generates docs for all thanos commands, localise links, ensure GitHub format.
docs: $(MDOX)
@echo ">> generating docs"
PATH="${PATH}:$(GOBIN)" $(MDOX) fmt README.md
$(MAKE) white-noise-cleanup
.PHONY: check-docs
check-docs: ## Checks docs against discrepancy with flags, links, white noise.
check-docs: $(MDOX)
@echo ">> checking docs"
PATH="${PATH}:$(GOBIN)" $(MDOX) fmt -l --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) README.md
$(MAKE) white-noise-cleanup
$(call require_clean_work_tree,'run make docs and commit changes')
.PHONY: format
format: $(GOIMPORTS)
@echo ">> formatting go code"
@gofmt -s -w $(FILES_TO_FMT)
@$(GOIMPORTS) -w $(FILES_TO_FMT)
.PHONY:lint
lint: format deps $(GOLANGCI_LINT) $(FAILLINT) $(COPYRIGHT) docs
$(call require_clean_work_tree,'detected not clean work tree before running lint, previous job changed something?')
@echo ">> verifying modules being imported"
@# TODO(bwplotka): Add, Printf, DefaultRegisterer, NewGaugeFunc and MustRegister once exception are accepted.
@$(FAILLINT) -paths "errors=github.com/efficientgo/core/errors,\
fmt.{Errorf}=github.com/efficientgo/core/errors.{Wrap,Wrapf},\
github.com/prometheus/prometheus/pkg/testutils=github.com/efficientgo/core/testutil,\
github.com/stretchr/testify=github.com/efficientgo/core/testutil" $(GOMODULES)
@$(FAILLINT) -paths "fmt.{Print,Println,Errorf}" -ignore-tests $(GOMODULES)
@echo ">> linting all of the Go files GOGC=${GOGC}"
@$(GOLANGCI_LINT) run
@echo ">> ensuring Copyright headers"
@$(COPYRIGHT) $(shell find . -name "*.go")
$(call require_clean_work_tree,'detected files without copyright, run make lint and commit changes')
.PHONY: white-noise-cleanup
white-noise-cleanup: ## Cleans up white noise in docs.
white-noise-cleanup:
@echo ">> cleaning up white noise"
@find . -type f \( -name "*.md" \) | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh
benchmarks:
@mkdir -p benchmarks
.PHONY: bench-old
bench-old: benchmarks
@echo "Benchmarking old engine"
@go test ./... -bench 'BenchmarkRangeQuery/.*/old_engine' -run none -count 5 | sed -u 's/\/old_engine//' > benchmarks/old.out
@go test ./... -bench 'BenchmarkNativeHistograms/.*/old_engine' -run none -count 5 | sed -u 's/\/old_engine//' >> benchmarks/old.out
.PHONY: bench-new
bench-new: benchmarks
@echo "Benchmarking new engine"
@go test ./... -bench 'BenchmarkRangeQuery/.*/new_engine' -run none -count 5 | sed -u 's/\/new_engine//' > benchmarks/new.out
@go test ./... -bench 'BenchmarkNativeHistograms/.*/new_engine' -run none -count 5 | sed -u 's/\/new_engine//' >> benchmarks/new.out
.PHONY: benchmark
benchmark: bench-old bench-new
@benchstat benchmarks/old.out benchmarks/new.out