Skip to content

Commit 93c69c0

Browse files
authored
Introduce hashicorp/go-metrics compatibility (#760)
* Introduce hashicorp/go-metrics compatibility Compatability is attained with build tags Using tag armonmetrics or no tag at all will result in the library utilizing github.com/armon/go-metrics for metrics emission (like it has historically done) Using tag hashicorpmetrics will result in the library utilizing the updated github.com/hashicorp/go-metrics for metrics emission. * Update README.md * Bump versions of memberlist and go-metrics to pull in go-metrics compat package
1 parent 0a77f05 commit 93c69c0

File tree

13 files changed

+92
-14
lines changed

13 files changed

+92
-14
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,29 @@ Tests can be run by typing `make test`.
126126

127127
If you make any changes to the code, run `make format` in order to automatically
128128
format the code according to Go [standards](https://golang.org/doc/effective_go.html#formatting).
129+
130+
131+
## Metrics Emission and Compatibility
132+
133+
This library can emit metrics using either `github.com/armon/go-metrics` or `github.com/hashicorp/go-metrics`. Choosing between the libraries is controlled via build tags.
134+
135+
**Build Tags**
136+
* `armonmetrics` - Using this tag will cause metrics to be routed to `armon/go-metrics`
137+
* `hashicorpmetrics` - Using this tag will cause all metrics to be routed to `hashicorp/go-metrics`
138+
139+
If no build tag is specified, the default behavior is to use `armon/go-metrics`.
140+
141+
**Deprecating `armon/go-metrics`**
142+
143+
Emitting metrics to `armon/go-metrics` is officially deprecated. Usage of `armon/go-metrics` will remain the default until mid-2025 with opt-in support continuing to the end of 2025.
144+
145+
**Migration**
146+
To migrate an application currently using the older `armon/go-metrics` to instead use `hashicorp/go-metrics` the following should be done.
147+
148+
1. Upgrade libraries using `armon/go-metrics` to consume `hashicorp/go-metrics/compat` instead. This should involve only changing import statements. All repositories in the `hashicorp` namespace
149+
2. Update an applications library dependencies to those that have the compatibility layer configured.
150+
3. Update the application to use `hashicorp/go-metrics` for configuring metrics export instead of `armon/go-metrics`
151+
* Replace all application imports of `github.com/armon/go-metrics` with `github.com/hashicorp/go-metrics`
152+
* Instrument your build system to build with the `hashicorpmetrics` tag.
153+
154+
Eventually once the default behavior changes to use `hashicorp/go-metrics` by default (mid-2025), you can drop the `hashicorpmetrics` build tag.

cmd/serf/command/agent/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"syscall"
1717
"time"
1818

19-
"github.com/armon/go-metrics"
19+
"github.com/hashicorp/go-metrics/compat"
2020
gsyslog "github.com/hashicorp/go-syslog"
2121
"github.com/hashicorp/logutils"
2222
"github.com/hashicorp/memberlist"

cmd/serf/command/agent/invoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/armon/circbuf"
18-
"github.com/armon/go-metrics"
18+
"github.com/hashicorp/go-metrics/compat"
1919
"github.com/hashicorp/serf/serf"
2020
)
2121

cmd/serf/command/agent/ipc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
"sync/atomic"
3838
"time"
3939

40-
"github.com/armon/go-metrics"
40+
"github.com/hashicorp/go-metrics/compat"
4141
"github.com/hashicorp/go-msgpack/v2/codec"
4242
"github.com/hashicorp/logutils"
4343
"github.com/hashicorp/serf/coordinate"

coordinate/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/armon/go-metrics"
13+
"github.com/hashicorp/go-metrics/compat"
1414
)
1515

1616
// Client manages the estimated network coordinate for a given node, and adjusts

coordinate/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package coordinate
55

66
import (
7-
"github.com/armon/go-metrics"
7+
"github.com/hashicorp/go-metrics/compat"
88
)
99

1010
// Config is used to set the parameters of the Vivaldi-based coordinate mapping

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ go 1.19
44

55
require (
66
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
7-
github.com/armon/go-metrics v0.4.1
7+
github.com/hashicorp/go-metrics v0.5.4
88
github.com/hashicorp/go-msgpack/v2 v2.1.2
99
github.com/hashicorp/go-syslog v1.0.0
1010
github.com/hashicorp/logutils v1.0.0
1111
github.com/hashicorp/mdns v1.0.5
12-
github.com/hashicorp/memberlist v0.5.1
12+
github.com/hashicorp/memberlist v0.5.2
1313
github.com/mitchellh/cli v1.1.5
1414
github.com/mitchellh/mapstructure v1.5.0
1515
github.com/ryanuber/columnize v2.1.2+incompatible
@@ -19,6 +19,7 @@ require (
1919
github.com/Masterminds/goutils v1.1.1 // indirect
2020
github.com/Masterminds/semver/v3 v3.1.1 // indirect
2121
github.com/Masterminds/sprig/v3 v3.2.1 // indirect
22+
github.com/armon/go-metrics v0.4.1 // indirect
2223
github.com/armon/go-radix v1.0.0 // indirect
2324
github.com/bgentry/speakeasy v0.1.0 // indirect
2425
github.com/fatih/color v1.9.0 // indirect

go.sum

Lines changed: 53 additions & 2 deletions
Large diffs are not rendered by default.

serf/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"os"
1010
"time"
1111

12-
"github.com/armon/go-metrics"
12+
"github.com/hashicorp/go-metrics/compat"
1313
"github.com/hashicorp/memberlist"
1414
)
1515

serf/delegate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"bytes"
88
"fmt"
99

10-
"github.com/armon/go-metrics"
10+
"github.com/hashicorp/go-metrics/compat"
1111
"github.com/hashicorp/go-msgpack/v2/codec"
1212
"github.com/hashicorp/memberlist"
1313
)

serf/ping_delegate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"bytes"
88
"time"
99

10-
"github.com/armon/go-metrics"
10+
"github.com/hashicorp/go-metrics/compat"
1111
"github.com/hashicorp/go-msgpack/v2/codec"
1212
"github.com/hashicorp/memberlist"
1313
"github.com/hashicorp/serf/coordinate"

serf/serf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"sync/atomic"
2020
"time"
2121

22-
"github.com/armon/go-metrics"
22+
"github.com/hashicorp/go-metrics/compat"
2323
"github.com/hashicorp/go-msgpack/v2/codec"
2424
"github.com/hashicorp/memberlist"
2525
"github.com/hashicorp/serf/coordinate"

serf/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"strings"
1515
"time"
1616

17-
"github.com/armon/go-metrics"
17+
"github.com/hashicorp/go-metrics/compat"
1818
)
1919

2020
/*

0 commit comments

Comments
 (0)