Skip to content

Commit b4393f5

Browse files
committed
fix: add Makefile command; move ExporterOptions to shared type
1 parent 4ce3abb commit b4393f5

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ VERSION ?= "$(shell git describe --tags --abbrev=0 | cut -c2-)"
2020
COMMIT_HASH ?= "$(shell git describe --long --dirty --always --match "" || true)"
2121
CLEAN_COMMIT ?= "$(shell git describe --long --always --match "" || true)"
2222
COMMIT_TIME ?= "$(shell git show -s --format=%ct $(CLEAN_COMMIT) || true)"
23+
BUILD_TAGS ?=
2324
LDFLAGS ?= -s -w \
2425
-X github.com/ethersphere/bee/v2.version="$(VERSION)" \
2526
-X github.com/ethersphere/bee/v2.commitHash="$(COMMIT_HASH)" \
@@ -31,11 +32,14 @@ LDFLAGS ?= -s -w \
3132
.PHONY: all
3233
all: build lint test-race binary
3334

34-
.PHONY: binary
35+
.PHONY: binary binary-nometrics
3536
binary: export CGO_ENABLED=0
3637
binary: dist FORCE
3738
$(GO) version
38-
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o dist/bee ./cmd/bee
39+
$(GO) build -trimpath -ldflags "$(LDFLAGS)" -tags "$(BUILD_TAGS)" -o dist/bee ./cmd/bee
40+
41+
binary-nometrics:
42+
$(MAKE) binary BUILD_TAGS=nometrics
3943

4044
dist:
4145
mkdir $@

pkg/metrics/exporter/exporter.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,16 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !nometrics
6+
// +build !nometrics
7+
58
package exporter
69

710
import (
811
exporter "contrib.go.opencensus.io/exporter/prometheus"
912
"github.com/prometheus/client_golang/prometheus"
1013
)
1114

12-
type MetricsSourcer interface {
13-
MustRegister(...prometheus.Collector)
14-
Register(prometheus.Collector) error
15-
Unregister(prometheus.Collector) bool
16-
}
17-
18-
// The goroutine leak `go.opencensus.io/stats/view.(*worker).start` appears solely because of
19-
// importing the `exporter.Options` type from `go.opencensus.io` package
20-
// (either directly or transitively).
21-
type ExporterOptions struct {
22-
Namespace string
23-
Registry MetricsSourcer
24-
}
25-
2615
func NewExporter(o ExporterOptions) error {
2716
r, _ := o.Registry.(*prometheus.Registry)
2817
opts := exporter.Options{

pkg/metrics/exporter/noop.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2020 The Swarm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build nometrics
6+
// +build nometrics
7+
8+
package exporter
9+
10+
func NewExporter(o ExporterOptions) error {
11+
return nil
12+
}

pkg/metrics/exporter/types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2020 The Swarm Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package exporter
6+
7+
import (
8+
"github.com/prometheus/client_golang/prometheus"
9+
)
10+
11+
type MetricsSourcer interface {
12+
MustRegister(...prometheus.Collector)
13+
Register(prometheus.Collector) error
14+
Unregister(prometheus.Collector) bool
15+
}
16+
17+
type ExporterOptions struct {
18+
Namespace string
19+
Registry MetricsSourcer
20+
}

pkg/metrics/noop.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ func NewRegistry() MetricsRegistererGatherer {
144144
return &registryNoop{}
145145
}
146146

147-
func NewExporter(o ExporterOptions) error {
148-
return nil
149-
}
150-
151147
func MustRegister(_ ...Collector) {
152148
// pass
153149
}

0 commit comments

Comments
 (0)