bee icon indicating copy to clipboard operation
bee copied to clipboard

#5179: Add build tag `nometrics` and centralize Prometheus imports

Open filinvadim opened this issue 4 months ago • 4 comments

Checklist

  • [x] I have read the coding guide.
  • [ ] My change requires a documentation update, and I have done it.
  • [ ] I have added tests to cover my changes.
  • [x] I have filled out the description and linked the related issues.

Description

Introduced a nometrics build tag to allow tinygo compilation. Removed scattered Prometheus imports across the codebase. Centralized all metric definitions and Prometheus types under pkg/metrics, with local aliases to ensure the rest of the project depends only on this package.

NO performance optimizations. NO functionality changed. Code refactorings only. Fully backwards-compatible: default builds behave exactly as before. No breaking changes for downstream users relying on metrics. Verified with go test ./... both with and without -tags nometrics

Open API Spec Version Changes (if applicable)

None

Motivation and Context (Optional)

This makes it possible to build and run the project without pulling in Prometheus (for tinygo compilation for example), while keeping metrics fully functional by default and isolating Prometheus-specific code in a single place.

Related Issue (Optional)

Use a build tag to toggle Prometheus/metrics

Screenshots (if appropriate):

filinvadim avatar Sep 21 '25 16:09 filinvadim

Linter failed to start.

Get "https://golangci-lint.run/jsonschema/golangci.v1.64.jsonschema.json": 

read tcp 10.1.0.240:44552->185.199.109.153:443: read: connection reset by peer

filinvadim avatar Sep 22 '25 13:09 filinvadim

Looks like flapping test.

--- FAIL: TestAgent (0.00s)
    --- FAIL: TestAgent/4_blocks_per_phase,_block_number_returns_every_other_block (12.74s)
        agent_test.go:153: expected call isWinnerCall, got revealCall

filinvadim avatar Sep 22 '25 13:09 filinvadim

@filinvadim To make this feature more accessible, I suggest adding support for it in the Makefile. Maybe to add BUILD_TAGS variable and update the binary target to support it:

.PHONY: binary
binary: export CGO_ENABLED=0
binary: dist FORCE
	$(GO) version
ifneq ($(BUILD_TAGS),)
	$(GO) build -trimpath -ldflags "$(LDFLAGS)" -tags "$(BUILD_TAGS)" -o dist/bee ./cmd/bee
else
	$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o dist/bee ./cmd/bee
endif

Also, I got an error: pkg/metrics/noop.go:147:20: undefined: ExporterOptions. If I resolved it right, the size diff beetween regular build is around 130Kb?

gacevicljubisa avatar Sep 23 '25 16:09 gacevicljubisa

@gacevicljubisa Thanks! Fixed missing ExporterOptions. Added Makefile command binary-nometrics. Decided to make it this way for the best backwards-compatibility. Size diff on linux/amd64 is 440kb.

filinvadim avatar Sep 23 '25 17:09 filinvadim