Skip to content

Commit 9bd16f2

Browse files
[history server][collector] Enable run with race condition checker (#4430)
* build: with -race when building go binary Signed-off-by: machichima <nary12321@gmail.com> * build: update makefile with race command Signed-off-by: machichima <nary12321@gmail.com> * build: add collector.race dockerfile Signed-off-by: machichima <nary12321@gmail.com> * docs: update docs Signed-off-by: machichima <nary12321@gmail.com> * fix: add GOOS and GOARCH back Signed-off-by: machichima <nary12321@gmail.com> * fix: set diff image name for race detector version Signed-off-by: machichima <nary12321@gmail.com> * build: add build-arg for enable race Signed-off-by: machichima <nary12321@gmail.com> * build: add -race to go test Signed-off-by: machichima <nary12321@gmail.com> * Trigger CI Signed-off-by: machichima <nary12321@gmail.com> * fix: set --platform linux/amd64 to run on linux Signed-off-by: machichima <nary12321@gmail.com> --------- Signed-off-by: machichima <nary12321@gmail.com> Co-authored-by: Future-Outlier <eric901201@gmail.com>
1 parent e012135 commit 9bd16f2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

historyserver/Dockerfile.collector

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM golang:1.25.1 AS builder
22

33
ARG GOPROXY=https://proxy.golang.org,direct
4+
ARG ENABLE_RACE=false
45
ENV GOPROXY=${GOPROXY}
56
WORKDIR /historyserver
67

@@ -18,7 +19,11 @@ COPY pkg/utils/ pkg/utils/
1819

1920
# Build the collector binary.
2021
COPY Makefile Makefile
21-
RUN make buildcollector GOOS=linux GOARCH=amd64
22+
RUN if [ "$ENABLE_RACE" = "true" ]; then \
23+
make buildcollector-race GOOS=linux GOARCH=amd64; \
24+
else \
25+
make buildcollector GOOS=linux GOARCH=amd64; \
26+
fi
2227

2328
FROM ubuntu:22.04
2429
RUN apt-get update && apt-get upgrade -y && rm -rf /var/cache/apt/ && apt-get install -y ca-certificates

historyserver/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ buildcollector: mod
5656
@echo "go build ..."
5757
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME_COLLECTOR) ./cmd/collector/main.go
5858

59+
.PHONY: buildcollector-race
60+
buildcollector-race: mod
61+
@echo ""
62+
@echo "go build with race detector..."
63+
CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -race -v $(GO_BUILD_FLAGS) -o $(BIN_DIR)/$(BINARY_NAME_COLLECTOR) ./cmd/collector/main.go
64+
5965
.PHONY: buildhistoryserver
6066
#build: mod alllint test
6167
buildhistoryserver: mod
@@ -87,6 +93,10 @@ else
8793
${ENGINE} build -t $(COLLECTOR_IMG) --build-arg GOPROXY=$(GOPROXY) -f Dockerfile.collector .
8894
endif
8995

96+
.PHONY: localimage-collector-race
97+
localimage-collector-race:
98+
${ENGINE} build --platform linux/amd64 -t $(COLLECTOR_IMG)-race --build-arg GOPROXY=$(GOPROXY) --build-arg ENABLE_RACE=true -f Dockerfile.collector .
99+
90100
.PHONY: localimage-historyserver
91101
localimage-historyserver:
92102
ifdef PLATFORM
@@ -105,7 +115,7 @@ endif
105115
# Run tests
106116
.PHONY: test
107117
test:
108-
go test -v ./pkg/... ./cmd/...
118+
go test -race -v ./pkg/... ./cmd/...
109119

110120
.PHONY: alllint
111121
alllint: todolist issuelint ## Run go lint against code.

historyserver/docs/set_up_collector.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ k9s
7676
# Build the collector image.
7777
make -C historyserver localimage-collector
7878

79+
# Or to build the collector image with race detector
80+
# make -C historyserver localimage-collector-race
81+
7982
# Check the built image.
8083
docker images | grep collector
8184
```
@@ -89,6 +92,9 @@ it.
8992
# Load the image into the kind cluster.
9093
kind load docker-image collector:v0.1.0
9194

95+
# Or to load the collector image with race detector
96+
# kind load docker-image collector:v0.1.0-race
97+
9298
# Check the loaded image.
9399
docker exec -it kind-control-plane crictl images | grep collector
94100
```

0 commit comments

Comments
 (0)