This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
165 lines (124 loc) · 7.89 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
BASE_PATH = $(shell pwd)
BIN_PATH := $(BASE_PATH)/bin
export PATH := $(BIN_PATH):$(PATH)
help: ## Display this help message.
@echo "Please use \`make <target>\` where <target> is one of:"
@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | \
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}'
# `cut` is used to remove first `v` from `git describe` output
PMM_RELEASE_PATH ?= bin
PMM_RELEASE_VERSION ?= $(shell git describe --always --dirty | cut -b2-)
PMM_RELEASE_TIMESTAMP ?= $(shell date '+%s')
PMM_RELEASE_FULLCOMMIT ?= $(shell git rev-parse HEAD)
PMM_RELEASE_BRANCH ?= $(shell git describe --always --contains --all)
PMM_DEV_SERVER_PORT ?= 443
VERSION_FLAGS = -X 'github.com/percona/pmm/version.ProjectName=pmm-agent' \
-X 'github.com/percona/pmm/version.Version=$(PMM_RELEASE_VERSION)' \
-X 'github.com/percona/pmm/version.PMMVersion=$(PMM_RELEASE_VERSION)' \
-X 'github.com/percona/pmm/version.Timestamp=$(PMM_RELEASE_TIMESTAMP)' \
-X 'github.com/percona/pmm/version.FullCommit=$(PMM_RELEASE_FULLCOMMIT)' \
-X 'github.com/percona/pmm/version.Branch=$(PMM_RELEASE_BRANCH)'
release: ## Build static pmm-agent release binary (Linux only).
env CGO_ENABLED=1 go build -v -ldflags "-extldflags '-static' $(VERSION_FLAGS)" -tags 'osusergo netgo static_build' -o $(PMM_RELEASE_PATH)/pmm-agent
$(PMM_RELEASE_PATH)/pmm-agent --version
-ldd $(PMM_RELEASE_PATH)/pmm-agent
init: ## Installs development tools
rm -rf ./bin
cd tools && go generate -x -tags=tools
gen: ## Generate files.
go generate ./...
make format
# generate stub models for perfschema QAN agent; hidden from help as it is not generally useful
gen-init:
go build -modfile=tools/go.mod -o $(BIN_PATH)/reform-db gopkg.in/reform.v1/reform-db
mkdir tmp-mysql
$(BIN_PATH)/reform-db -db-driver=mysql -db-source='root:root-password@tcp(127.0.0.1:3306)/performance_schema' init tmp-mysql
install: ## Install pmm-agent binary.
go install -ldflags "$(VERSION_FLAGS)" ./...
install-race: ## Install pmm-agent binary with race detector.
go install -ldflags "$(VERSION_FLAGS)" -race ./...
# TODO https://jira.percona.com/browse/PMM-4681
# TEST_PARALLEL_PACKAGES ?= foo bar
# go test $(TEST_FLAGS) $(TEST_PARALLEL_PACKAGES) - without `-p 1`
TEST_PACKAGES ?= ./...
TEST_FLAGS ?= -timeout=60s
test: ## Run tests.
go test $(TEST_FLAGS) -p 1 $(TEST_PACKAGES)
test-race: ## Run tests with race detector.
go test $(TEST_FLAGS) -p 1 -race $(TEST_PACKAGES)
test-cover: ## Run tests and collect per-package coverage information.
go test $(TEST_FLAGS) -p 1 -coverprofile=cover.out -covermode=count $(TEST_PACKAGES)
test-crosscover: ## Run tests and collect cross-package coverage information.
go test $(TEST_FLAGS) -p 1 -coverprofile=crosscover.out -covermode=count -coverpkg=./... $(TEST_PACKAGES)
fuzz-slowlog-parser: ## Run fuzzer for agents/mysql/slowlog/parser package.
# go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
mkdir -p agents/mysql/slowlog/parser/corpus
cp agents/mysql/slowlog/parser/testdata/*.log agents/mysql/slowlog/parser/corpus/
cd agents/mysql/slowlog/parser && go-fuzz-build
cd agents/mysql/slowlog/parser && go-fuzz
fuzz-postgres-parser: ## Run fuzzer for agents/postgres/parser package.
# FIXME see https://github.com/AlekSi/go-fuzz/pull/1
# go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build
mkdir -p agents/postgres/parser/fuzzing/corpus
cp agents/postgres/parser/testdata/*.sql agents/postgres/parser/fuzzing/corpus/
cd agents/postgres/parser && go-fuzz-build
cd agents/postgres/parser && go-fuzz -workdir fuzzing
bench: ## Run benchmarks.
go test -bench=. -benchtime=1s -count=5 -cpu=1 -timeout=30m -failfast github.com/percona/pmm-agent/agents/mysql/slowlog/parser | tee slowlog_parser_new.bench
$(BIN_PATH)/benchstat slowlog_parser_old.bench slowlog_parser_new.bench
go test -bench=. -benchtime=1s -count=5 -cpu=1 -timeout=30m -failfast github.com/percona/pmm-agent/agents/postgres/parser | tee postgres_parser_new.bench
$(BIN_PATH)/benchstat postgres_parser_old.bench postgres_parser_new.bench
check: ## Run required checkers and linters.
go run .github/check-license.go
$(BIN_PATH)/golangci-lint run -c=.golangci-required.yml
$(BIN_PATH)/go-consistent -pedantic ./...
check-all: check ## Run golang ci linter to check new changes from main.
$(BIN_PATH)/golangci-lint run -c=.golangci.yml --new-from-rev=main
FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
format: ## Format source code.
$(BIN_PATH)/gofumpt -l -w $(FILES)
$(BIN_PATH)/goimports -local github.com/percona/pmm-agent -l -w $(FILES)
$(BIN_PATH)/gci write --Section Standard --Section Default --Section "Prefix(github.com/percona/pmm-agent)" $(FILES)
$(BIN_PATH)/goimports -local github.com/percona/pmm-agent -l -w $(FILES) # Temporary fix, gci has bug with sorting black imports.
RUN_FLAGS = --config-file=pmm-agent-dev.yaml
run: install _run ## Run pmm-agent.
run-race: install-race _run ## Run pmm-agent with race detector.
run-race-cover: install-race ## Run pmm-agent with race detector and collect coverage information.
go test -coverpkg="github.com/percona/pmm-agent/..." \
-tags maincover \
-ldflags "$(VERSION_FLAGS)" \
-race -c -o bin/pmm-agent.test
bin/pmm-agent.test -test.coverprofile=cover.out -test.run=TestMainCover -- $(RUN_FLAGS)
_run:
pmm-agent $(RUN_FLAGS)
ENV_UP_FLAGS ?= --force-recreate --renew-anon-volumes --remove-orphans
env-up: ## Start development environment.
# to make slowlog rotation tests work
rm -fr testdata
mkdir -p testdata/mysql/slowlogs
chmod -R 0777 testdata
docker-compose up $(ENV_UP_FLAGS)
env-down: ## Stop development environment.
docker-compose down --volumes --remove-orphans
setup-dev: install ## Run pmm-agent setup in development environment.
pmm-agent setup $(RUN_FLAGS) --server-insecure-tls --server-address=127.0.0.1:${PMM_DEV_SERVER_PORT} --server-username=admin --server-password=admin --paths-exporters_base=$(GOPATH)/bin --force
env-mysql: ## Run mysql client.
docker exec -ti pmm-agent_mysql mysql --host=127.0.0.1 --user=root --password=root-password
env-mongo: ## Run mongo client.
docker exec -ti pmm-agent_mongo mongo --username=root --password=root-password
env-psql: ## Run psql client.
docker exec -ti pmm-agent_postgres env PGPASSWORD=pmm-agent-password psql --username=pmm-agent
env-sysbench-prepare:
docker-compose exec --workdir=/sysbench/sysbench-tpcc sysbench ./tpcc.lua \
--db-driver=pgsql --pgsql-host=postgres --pgsql-user=pmm-agent --pgsql-password=pmm-agent-password --pgsql-db=pmm-agent \
--threads=1 --time=0 --report-interval=10 \
--tables=1 --scale=10 --use_fk=0 --enable_purge=yes prepare
env-sysbench-run:
docker-compose exec --workdir=/sysbench/sysbench-tpcc sysbench ./tpcc.lua \
--db-driver=pgsql --pgsql-host=postgres --pgsql-user=pmm-agent --pgsql-password=pmm-agent-password --pgsql-db=pmm-agent \
--threads=4 --time=0 --rate=10 --report-interval=10 --percentile=99 \
--tables=1 --scale=10 --use_fk=0 --enable_purge=yes run
ci-reviewdog: ## Runs reviewdog checks.
$(BIN_PATH)/golangci-lint run -c=.golangci-required.yml --out-format=line-number | $(BIN_PATH)/reviewdog -f=golangci-lint -level=error -reporter=github-pr-check
$(BIN_PATH)/golangci-lint run -c=.golangci.yml --out-format=line-number | $(BIN_PATH)/reviewdog -f=golangci-lint -level=error -reporter=github-pr-review
$(BIN_PATH)/go-consistent -pedantic -exclude "tests" ./... | $(BIN_PATH)/reviewdog -f=go-consistent -name='Required go-consistent checks' -reporter=github-pr-check