Skip to content

Conversation

@filinvadim
Copy link

@filinvadim filinvadim commented Sep 21, 2025

Checklist

  • 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.
  • 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 filinvadim marked this pull request as ready for review September 21, 2025 16:36
@filinvadim filinvadim changed the title Add build tag nometrics and centralize Prometheus imports #5179: Add build tag nometrics and centralize Prometheus imports Sep 21, 2025
Introduced a nometrics build tag with two alternative implementations: a no-op stub when metrics are disabled and the full Prometheus-backed implementation when enabled. 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.
This makes it possible to build and run the project without pulling in Prometheus (via -tags nometrics), while keeping metrics fully functional by default and isolating Prometheus-specific code in a single place.
@filinvadim
Copy link
Author

filinvadim commented Sep 22, 2025

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
Copy link
Author

filinvadim commented Sep 22, 2025

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

@gacevicljubisa
Copy link
Member

@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?

@filinvadim
Copy link
Author

filinvadim commented Sep 23, 2025

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants