@@ -64,7 +64,7 @@ $(BUILD)/goversion-lint:
6464$(BUILD ) /fmt : $(BUILD ) /codegen # formatting must occur only after all other go-file-modifications are done
6565# $(BUILD)/copyright
6666# $(BUILD)/copyright: $(BUILD)/codegen # must add copyright to generated code, sometimes needs re-formatting
67- $(BUILD ) /codegen : $(BUILD ) /thrift $(BUILD ) /protoc
67+ $(BUILD ) /codegen : $(BUILD ) /thrift $(BUILD ) /protoc $( BUILD ) /metrics
6868$(BUILD ) /thrift : $(BUILD ) /go_mod_check
6969$(BUILD ) /protoc : $(BUILD ) /go_mod_check
7070$(BUILD ) /go_mod_check :
@@ -211,6 +211,12 @@ $(BIN)/protoc-gen-gogofast: go.mod go.work | $(BIN)
211211$(BIN ) /protoc-gen-yarpc-go : go.mod go.work | $(BIN )
212212 $(call go_mod_build_tool,go.uber.org/yarpc/encoding/protobuf/protoc-gen-yarpc-go)
213213
214+ $(BIN ) /metricsgen : internal/tools/go.mod go.work $(wildcard internal/tools/metricsgen/* ) | $(BIN )
215+ $(call go_build_tool,./metricsgen)
216+
217+ $(BIN ) /metricslint : internal/tools/go.mod go.work $(wildcard internal/tools/metricslint/* internal/tools/metricslint/cmd/* ) | $(BIN )
218+ $(call go_build_tool,./metricslint/cmd,metricslint)
219+
214220$(BUILD ) /go_mod_check : go.mod internal/tools/go.mod go.work
215221 $Q # generated == used is occasionally important for gomock / mock libs in general. this is not a definite problem if violated though.
216222 $Q ./scripts/check-gomod-version.sh github.com/golang/mock/gomock $(if $(verbose ) ,-v)
@@ -352,6 +358,10 @@ $(BUILD)/protoc: $(PROTO_FILES) $(STABLE_BIN)/$(PROTOC_VERSION_BIN) $(BIN)/proto
352358 fi
353359 $Q touch $@
354360
361+ $(BUILD ) /metrics : $(ALL_SRC ) $(BIN ) /metricsgen
362+ $Q $(BIN_PATH ) go generate -run=metricsgen ./...
363+ $Q touch $@
364+
355365# ====================================
356366# Rule-breaking targets intended ONLY for special cases with no good alternatives.
357367# ====================================
@@ -404,6 +414,11 @@ $(BUILD)/code-lint: $(LINT_SRC) $(BIN)/revive | $(BUILD)
404414 fi
405415 $Q touch $@
406416
417+ $(BUILD ) /metrics-lint : $(ALL_SRC ) $(BIN ) /metricslint | $(BUILD )
418+ $Q echo " linting metrics definitions..."
419+ $Q $(BIN_PATH ) $(BIN ) /metricslint -skip cadence_requests_per_tl,2 -skip cache_hit,2 -skip cache_full,2 -skip cache_miss,2 -skip cross_cluster_fetch_errors,2 ./...
420+ $Q touch $@
421+
407422$(BUILD ) /goversion-lint : go.work Dockerfile docker/github_actions/Dockerfile${DOCKERFILE_SUFFIX}
408423 $Q echo " checking go version..."
409424 $Q # intentionally using go.work toolchain, as GOTOOLCHAIN is user-overridable
@@ -458,7 +473,7 @@ endef
458473# useful to actually re-run to get output again.
459474# reuse the intermediates for simplicity and consistency.
460475lint : # # (Re)run the linter
461- $(call remake,proto-lint gomod-lint code-lint goversion-lint)
476+ $(call remake,proto-lint gomod-lint code-lint goversion-lint metrics-lint )
462477
463478# intentionally not re-making, it's a bit slow and it's clear when it's unnecessary
464479fmt : $(BUILD ) /fmt # # Run `gofmt` / organize imports / etc
@@ -544,14 +559,20 @@ bins: $(BINS) ## Build all binaries, and any fast codegen needed (does not refre
544559
545560tools : $(TOOLS )
546561
547- go-generate : $(BIN ) /mockgen $(BIN ) /enumer $(BIN ) /mockery $(BIN ) /gowrap # # Run `go generate` to regen mocks, enums, etc
562+ go-generate : $(BIN ) /mockgen $(BIN ) /enumer $(BIN ) /mockery $(BIN ) /gowrap $( BIN ) /metricsgen # # Run `go generate` to regen mocks, enums, etc
548563 $Q echo " running go generate ./..., this takes a minute or more..."
549564 $Q # add our bins to PATH so `go generate` can find them
550565 $Q $(BIN_PATH ) go generate $(if $(verbose ) ,-v) ./...
566+ $Q touch $(BUILD ) /metrics # whole-service go-generate also regenerates metrics
551567 $Q $(MAKE ) --no-print-directory fmt
552568# $Q echo "updating copyright headers"
553569# $Q $(MAKE) --no-print-directory copyright
554570
571+ metrics : $(BIN ) /metricsgen # # metrics-only code regen, much faster than go-generate
572+ $Q echo " re-generating metrics structs..."
573+ $Q $(MAKE ) $(BUILD ) /metrics
574+ $Q $(MAKE ) fmt # clean up imports
575+
555576release : # # Re-generate generated code and run tests
556577 $(MAKE ) --no-print-directory go-generate
557578 $(MAKE ) --no-print-directory test
@@ -577,7 +598,7 @@ tidy: ## `go mod tidy` all packages
577598clean : # # Clean build products and SQLite database
578599 rm -f $(BINS )
579600 rm -Rf $(BUILD )
580- rm * .db
601+ rm -f * .db
581602 $(if \
582603 $(wildcard $(STABLE_BIN ) /* ) , \
583604 $(warning usually-stable build tools still exist, delete the $(STABLE_BIN ) folder to rebuild them) ,)
0 commit comments