-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
176 lines (137 loc) · 6.7 KB
/
Makefile
File metadata and controls
176 lines (137 loc) · 6.7 KB
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
## Tool Binaries
LOCALBIN ?= $(shell pwd)/.bin
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.19.0
GOLANGCI_LINT_VERSION ?= v2.11.3
.PHONY: ginkgo
ginkgo:
go install github.com/onsi/ginkgo/v2/ginkgo
test: ginkgo
ginkgo -r --succinct --skip-package=tests/e2e,tests/e2e-blobs,bench --label-filter "!e2e"
test-concurrent: ginkgo
ginkgo -r -v --nodes=4 --skip-package=bench --label-filter "!e2e"
.PHONY: test-e2e
test-e2e: ginkgo
cd tests/e2e && docker-compose up -d && \
timeout 60 bash -c 'until curl -s http://localhost:3100/ready >/dev/null 2>&1; do sleep 2; done' && \
(ginkgo -v; TEST_EXIT_CODE=$$?; docker-compose down; exit $$TEST_EXIT_CODE)
.PHONY: e2e-services
e2e-services: ## Run e2e test services in foreground with automatic cleanup on exit
cd tests/e2e && \
trap 'docker-compose down -v && docker-compose rm -f' EXIT INT TERM && \
docker-compose up --remove-orphans
.PHONY: test-e2e-blobs
test-e2e-blobs: ginkgo
ginkgo -v --label-filter="e2e" ./tests/e2e-blobs/
.PHONY: bench
bench:
go test -run ^$$ -bench=. -benchtime=10s -timeout 30m github.com/flanksource/duty/bench
.PHONY: bench-alias
bench-alias:
go test -run ^$$ -bench=^BenchmarkInsertionForRowsWithAliases$$ -benchtime=10s -test.fullpath=true -timeout 30m github.com/flanksource/duty/bench -count=1 -v
fmt:
go fmt ./...
.PHONY: lint
lint: golangci-lint
$(GOLANGCI_LINT) run ./...
go vet ./...
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
# Generate OpenAPI schema
.PHONY: gen-schemas
gen-schemas:
cp go.mod hack/generate-schemas && \
cd hack/generate-schemas && \
go mod edit -module=github.com/flanksource/duty/hack/generate-schemas && \
go mod edit -replace=github.com/flanksource/duty=../../../duty && \
go mod tidy && \
go run .
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object paths="./types/..."
$(CONTROLLER_GEN) object paths="./logs/..."
$(CONTROLLER_GEN) object paths="./connection/..."
$(CONTROLLER_GEN) object paths="./models/..."
$(CONTROLLER_GEN) object paths="./shell/..."
$(CONTROLLER_GEN) object paths="./pubsub/..."
$(CONTROLLER_GEN) object paths="./dataquery/..."
$(CONTROLLER_GEN) object paths="./view/..."
$(CONTROLLER_GEN) object paths="./"
PATH=$(LOCALBIN):${PATH} go generate ./...
.PHONY: manifests
manifests: generate gen-schemas
$(LOCALBIN):
mkdir -p $(LOCALBIN)
update-schemas: download-openapi-schemas schema-definitions
schema-definitions:
cat schema/openapi/connection.schema.json | jq 'del(.["$$ref"], .["$$id"], .["$$schema"] )' > schema/openapi/connection.definitions.json
cat schema/openapi/scrape_config.spec.schema.json | jq 'del(.["$$ref"], .["$$id"], .["$$schema"] )' > schema/openapi/scrape_config.definitions.json
cat schema/openapi/notification.schema.json | jq 'del(.["$$ref"], .["$$id"], .["$$schema"] )' > schema/openapi/notification.definitions.json
cat schema/openapi/topology.spec.schema.json | jq 'del(.["$$ref"], .["$$id"], .["$$schema"] )' > schema/openapi/topology.definitions.json
cat schema/openapi/playbook-spec.schema.json | jq 'del(.["$$ref"], .["$$id"], .["$$schema"] )' > schema/openapi/playbook.definitions.json
download-openapi-schemas:
mkdir -p tmp
# Canary Checker
git clone --depth=1 git@github.com:flanksource/canary-checker.git tmp/canary-checker && cp tmp/canary-checker/config/schemas/* schema/openapi/
# create schemas for specs only
cat tmp/canary-checker/config/schemas/canary.schema.json | jq '.["$$ref"] = "#/$$defs/CanarySpec"' > schema/openapi/canary.spec.schema.json
cat tmp/canary-checker/config/schemas/component.schema.json | jq '.["$$ref"] = "#/$$defs/ComponentSpec"' > schema/openapi/component.spec.schema.json
cat tmp/canary-checker/config/schemas/topology.schema.json | jq '.["$$ref"] = "#/$$defs/TopologySpec"' > schema/openapi/topology.spec.schema.json
# Config DB
git clone --depth=1 git@github.com:flanksource/config-db.git tmp/config-db && cp tmp/config-db/config/schemas/* schema/openapi/
# APM-Hub
git clone --depth=1 git@github.com:flanksource/apm-hub.git tmp/apm-hub && cp tmp/apm-hub/config/schemas/* schema/openapi/
# Mission control
git clone --depth=1 git@github.com:flanksource/mission-control.git tmp/mission-control && cp tmp/mission-control/config/schemas/* schema/openapi/
# create schemas for specs only
cat tmp/config-db/config/schemas/scrape_config.schema.json | jq '.["$$ref"] = "#/definitions/ScraperSpec"' > schema/openapi/scrape_config.spec.schema.json
# Cleanup
rm -rf tmp
hack/migrate/go.mod: tidy
cp go.mod hack/migrate && \
cd hack/migrate && \
go mod edit -module=github.com/flanksource/duty/hack/migrate && \
go mod edit -require=github.com/flanksource/duty@v1.0.0 && \
go mod edit -replace=github.com/flanksource/duty=../../ && \
go mod tidy
.PHONY: migrate-test
migrate-test: hack/migrate/go.mod
cd hack/migrate && go run ./main.go
# test-migrate: delegates to the `test:migrate` Task (see Taskfile.yaml),
# which mirrors the `migrate` job in .github/workflows/test.yaml using an
# embedded postgres — applies base migrations from origin/main, then
# re-applies migrations from the current working tree against the same
# embedded database. No external DB required.
.PHONY: test-migrate
test-migrate:
task test:migrate
# test-bench: delegates to the `test:bench` Task (see Taskfile.yaml),
# which mirrors the benchmark workflow in .github/workflows/benchmark.yml.
# It compares the current working tree against a base revision, runs both
# `Other` and `RLS` suites, and writes benchstat artifacts under .bench/results/.
.PHONY: test-bench
test-bench:
task test:bench
cp-mission-control-openapi-schemas:
cp ../mission-control/config/schemas/*.json schema/openapi/
fmt_json:
ls fixtures/expectations/*.json | while read -r jf; do \
cat <<< $$(jq . $$jf) > $$jf; \
done;
fmt_sql:
ls views/*.sql | while read -r sqlf; do \
pg_format -s 2 -o $$sqlf $$sqlf; \
done;
tidy:
go mod tidy
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(LOCALBIN) $(GOLANGCI_LINT_VERSION)
clear_test_repos:
rm -rf tests/e2e/exec-checkout tests/e2e/shell-bin-dir shell/exec-checkout