diff --git a/.gitignore b/.gitignore index 151f9af088f..1c322725e58 100644 --- a/.gitignore +++ b/.gitignore @@ -216,3 +216,6 @@ public/app/plugins/**/dist/ # Go coverage files created with go test -cover -coverprogile=something.out ... *.out + +# Locally enabling the Go race detector until we can globally do so +.go-race-enabled-locally diff --git a/Makefile b/Makefile index 7af7862ea4f..702632957bf 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,10 @@ GO = go GO_VERSION = 1.22.3 GO_FILES ?= ./pkg/... ./pkg/apiserver/... ./pkg/apimachinery/... ./pkg/promlib/... SH_FILES ?= $(shell find ./scripts -name *.sh) +GO_RACE := $(shell [ -n "$(GO_BUILD_DEV)$(GO_RACE)" -o -e ".go-race-enabled-locally" ] && echo 1 ) GO_BUILD_FLAGS += $(if $(GO_BUILD_DEV),-dev) GO_BUILD_FLAGS += $(if $(GO_BUILD_TAGS),-build-tags=$(GO_BUILD_TAGS)) +GO_BUILD_FLAGS += $(if $(GO_RACE),-race) targets := $(shell echo '$(sources)' | tr "," " ") @@ -209,6 +211,11 @@ build: build-go build-js ## Build backend and frontend. run: $(BRA) ## Build and run web server on filesystem changes. $(BRA) run +.PHONY: run-go +run-go: ## Build and run web server immediately. + $(GO) run -race $(if $(GO_BUILD_TAGS),-build-tags=$(GO_BUILD_TAGS)) \ + ./pkg/cmd/grafana -- server -packaging=dev cfg:app_mode=development + .PHONY: run-frontend run-frontend: deps-js ## Fetch js dependencies and watch frontend for rebuild yarn start @@ -404,6 +411,18 @@ scripts/drone/TAGS: $(shell find scripts/drone -name '*.star') format-drone: buildifier --lint=fix -r scripts/drone +.PHONY: go-race-is-enabled +go-race-is-enabled: + @if [ -n "$(GO_RACE)" ]; then \ + echo "The Go race detector is enabled locally, yey!"; \ + else \ + echo "The Go race detector is NOT enabled locally, boo!"; \ + fi; + +.PHONY: enable-go-race +enable-go-race: + @touch .go-race-enabled-locally + .PHONY: help help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)