forked from openshift/telemeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
209 lines (164 loc) · 6.29 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
.PHONY: all build image check test-generate test-integration test-benchmark vendor dependencies manifests
SHELL=/usr/bin/env bash -o pipefail
GO_PKG=github.com/openshift/telemeter
REPO?=quay.io/openshift/telemeter
TAG?=$(shell git rev-parse --short HEAD)
PKGS=$(shell go list ./... | grep -v -E '/vendor/|/test/(?!e2e)')
GOLANG_FILES:=$(shell find . -name \*.go -print)
FIRST_GOPATH:=$(firstword $(subst :, ,$(shell go env GOPATH)))
GOLANGCI_LINT_BIN=$(FIRST_GOPATH)/bin/golangci-lint
GOLANGCI_LINT_VERSION=v1.18.0
EMBEDMD_BIN=$(FIRST_GOPATH)/bin/embedmd
THANOS_BIN=$(FIRST_GOPATH)/bin/thanos
UP_BIN=$(FIRST_GOPATH)/bin/up
MEMCACHED_BIN=_output/bin/memcached
PROMETHEUS_BIN=_output/bin/prometheus
GOJSONTOYAML_BIN=$(FIRST_GOPATH)/bin/gojsontoyaml
# We need jsonnet on CI; here we default to the user's installed jsonnet binary; if nothing is installed, then install go-jsonnet.
JSONNET_BIN=$(if $(shell which jsonnet 2>/dev/null),$(shell which jsonnet 2>/dev/null),$(FIRST_GOPATH)/bin/jsonnet)
JB_BIN=$(FIRST_GOPATH)/bin/jb
JSONNET_SRC=$(shell find ./jsonnet -type f)
BENCHMARK_RESULTS=$(shell find ./benchmark -type f -name '*.json')
BENCHMARK_GOAL?=5000
JSONNET_VENDOR=jsonnet/jsonnetfile.lock.json jsonnet/vendor
DOCS=$(shell grep -rlF [embedmd] docs)
GO_BUILD_RECIPE=GOOS=linux CGO_ENABLED=0 go build
CONTAINER_CMD:=docker run --rm \
-u="$(shell id -u):$(shell id -g)" \
-v "$(shell go env GOCACHE):/.cache/go-build" \
-v "$(PWD):/go/src/$(GO_PKG):Z" \
-w "/go/src/$(GO_PKG)" \
-e GO111MODULE=on \
quay.io/coreos/jsonnet-ci
.PHONY: all
all: build manifests $(DOCS)
.PHONY: clean
clean:
# Remove all files and directories ignored by git.
git clean -Xfd .
############
# Building #
############
.PHONY: build-in-docker
build-in-docker:
$(CONTAINER_CMD) $(MAKE) $(MFLAGS) build
.PHONY: build
build:
go build ./cmd/telemeter-client
go build ./cmd/telemeter-server
go build ./cmd/authorization-server
go build ./cmd/telemeter-benchmark
.PHONY: image
image: .hack-operator-image
.hack-operator-image: Dockerfile
# Create empty target file, for the sole purpose of recording when this target
# was last executed via the last-modification timestamp on the file. See
# https://www.gnu.org/software/make/manual/make.html#Empty-Targets
docker build -t $(REPO):$(TAG) .
touch $@
##############
# Generating #
##############
vendor:
go mod vendor
go mod tidy
go mod verify
.PHONY: generate
generate: $(DOCS) manifests
.PHONY: generate-in-docker
generate-in-docker:
$(CONTAINER_CMD) $(MAKE) $(MFLAGS) generate
$(JSONNET_VENDOR): jsonnet/jsonnetfile.json $(JB_BIN)
cd jsonnet && jb install
# Can't add test/timeseries.txt as a dependency, otherwise
# running make --always-make will try to regenerate the timeseries
# on CI, which will fail because there is no OpenShift cluster.
$(DOCS): $(JSONNET_SRC) $(EMBEDMD_BIN) docs/telemeter_query
$(EMBEDMD_BIN) -w $@
docs/telemeter_query: $(JSONNET_SRC)
query=""; \
for rule in $$(jsonnet metrics.json | jq -r '.[]'); do \
[ ! -z "$$query" ] && query="$$query or "; \
query="$$query$$rule"; \
done; \
echo "$$query" > $@
manifests: $(JSONNET_SRC) $(JSONNET_VENDOR) $(GOJSONTOYAML_BIN)
rm -rf manifests
mkdir -p manifests/{benchmark,client,server,prometheus}
$(JSONNET_BIN) jsonnet/benchmark.jsonnet -J jsonnet/vendor -m manifests/benchmark
$(JSONNET_BIN) jsonnet/client.jsonnet -J jsonnet/vendor -m manifests/client
$(JSONNET_BIN) jsonnet/prometheus.jsonnet -J jsonnet/vendor -m manifests/prometheus
@for f in $$(find manifests -type f); do\
cat $$f | $(GOJSONTOYAML_BIN) > $$f.yaml && rm $$f;\
done
benchmark.pdf: $(BENCHMARK_RESULTS)
find ./benchmark -type f -name '*.json' -print0 | xargs -l -0 python3 test/plot.py && gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$@ benchmark/*.pdf
##############
# Formatting #
##############
.PHONY: lint
lint: $(GOLANGCI_LINT_BIN)
# Check .golangci.yml for configuration
$(GOLANGCI_LINT_BIN) run -c .golangci.yml
.PHONY: format
format: go-fmt shellcheck
.PHONY: go-fmt
go-fmt:
go fmt $(PKGS)
.PHONY: shellcheck
shellcheck:
docker run -v "${PWD}:/mnt" koalaman/shellcheck:stable $(shell find . -type f -name "*.sh" -not -path "*vendor*")
###########
# Testing #
###########
.PHONY: test
test: test-unit test-integration test-benchmark
.PHONY: test-unit
test-unit:
go test -race -short $(PKGS) -count=1
# TODO(paulfantom): remove this target after removing it from Prow.
test-generate:
make --always-make && git diff --exit-code
test-integration: build $(THANOS_BIN) $(UP_BIN) $(MEMCACHED_BIN) $(PROMETHEUS_BIN)
PATH=$$PATH:$$(pwd)/_output/bin ./test/integration.sh
PATH=$$PATH:$$(pwd)/_output/bin ./test/integration-v2.sh
test-benchmark: build
./test/benchmark.sh "" "" $(BENCHMARK_GOAL) "" $(BENCHMARK_GOAL)
test/timeseries.txt:
oc port-forward -n openshift-monitoring prometheus-k8s-0 9090 > /dev/null & \
sleep 5 ; \
query="curl --fail --silent -G http://localhost:9090/federate"; \
for rule in $$(jsonnet metrics.json | jq -r '.[]'); do \
query="$$query $$(printf -- "--data-urlencode match[]=%s" $$rule)"; \
done; \
echo '# This file was generated using `make $@`.' > $@ ; \
$$query >> $@ ; \
jobs -p | xargs -r kill
############
# Binaries #
############
dependencies: $(JB_BIN) $(GOLANGCI_LINT_BIN)
$(THANOS_BIN):
GO111MODULE=off go get github.com/thanos-io/thanos
$(UP_BIN):
GO111MODULE=off go get github.com/observatorium/up
$(MEMCACHED_BIN):
mkdir -p _output/bin
@echo "Downloading Memcached"
curl -L https://www.archlinux.org/packages/extra/x86_64/memcached/download/ | tar --strip-components=2 -xJf - -C _output/bin usr/bin/memcached
$(PROMETHEUS_BIN):
mkdir -p _output/bin
@echo "Downloading Prometheus"
curl -L "https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.$$(go env GOOS)-$$(go env GOARCH).tar.gz" | tar --strip-components=1 -xzf - -C _output/bin
$(EMBEDMD_BIN):
GO111MODULE=off go get -u github.com/campoy/embedmd
$(GOBINDATA_BIN):
GO111MODULE=off go get -u github.com/jteeuwen/go-bindata/...
$(JB_BIN):
GO111MODULE=off go get -u github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
$(GOJSONTOYAML_BIN):
GO111MODULE=off go get -u github.com/brancz/gojsontoyaml
$(GOLANGCI_LINT_BIN):
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh \
| sed -e '/install -d/d' \
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)