Skip to content

Commit 2df46fe

Browse files
authored
Introduce hashicorp/go-metrics compatibility (#315)
* 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 Using tag hashicorpmetrics will result in the library utilizing the updated github.com/hashicorp/go-metrics for metrics emission.
1 parent 5af4428 commit 2df46fe

13 files changed

+193
-35
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,28 @@ convergence rate.
7171

7272
For details on all of these extensions, please read our paper "[Lifeguard : SWIM-ing with Situational Awareness](https://arxiv.org/abs/1707.00788)", along with the memberlist source. We welcome any questions related
7373
to the protocol on our issue tracker.
74+
75+
## Metrics Emission and Compatibility
76+
77+
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.
78+
79+
**Build Tags**
80+
* `armonmetrics` - Using this tag will cause metrics to be routed to `armon/go-metrics`
81+
* `hashicorpmetrics` - Using this tag will cause all metrics to be routed to `hashicorp/go-metrics`
82+
83+
If no build tag is specified, the default behavior is to use `armon/go-metrics`.
84+
85+
**Deprecating `armon/go-metrics`**
86+
87+
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.
88+
89+
**Migration**
90+
To migrate an application currently using the older `armon/go-metrics` to instead use `hashicorp/go-metrics` the following should be done.
91+
92+
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
93+
2. Update an applications library dependencies to those that have the compatibility layer configured.
94+
3. Update the application to use `hashicorp/go-metrics` for configuring metrics export instead of `armon/go-metrics`
95+
* Replace all application imports of `github.com/armon/go-metrics` with `github.com/hashicorp/go-metrics`
96+
* Instrument your build system to build with the `hashicorpmetrics` tag.
97+
98+
Eventually once the default behavior changes to use `hashicorp/go-metrics` by default (mid-2025), you can drop the `hashicorpmetrics` build tag.

awareness.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/armon/go-metrics"
10+
"github.com/hashicorp/go-metrics/compat"
1111
)
1212

1313
// awareness manages a simple metric for tracking the estimated health of the

config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"strings"
1313
"time"
1414

15-
"github.com/armon/go-metrics"
15+
"github.com/hashicorp/go-metrics/compat"
1616
"github.com/hashicorp/go-multierror"
1717
)
1818

go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@ module github.com/hashicorp/memberlist
33
go 1.20
44

55
require (
6-
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da
76
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c
7+
github.com/hashicorp/go-metrics v0.5.4
88
github.com/hashicorp/go-msgpack/v2 v2.1.1
99
github.com/hashicorp/go-multierror v1.0.0
1010
github.com/hashicorp/go-sockaddr v1.0.0
1111
github.com/miekg/dns v1.1.26
1212
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529
13-
github.com/stretchr/testify v1.2.2
13+
github.com/stretchr/testify v1.4.0
1414
)
1515

1616
require (
17+
github.com/armon/go-metrics v0.4.1 // indirect
1718
github.com/davecgh/go-spew v1.1.1 // indirect
1819
github.com/hashicorp/errwrap v1.0.0 // indirect
1920
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
2021
github.com/hashicorp/golang-lru v0.5.0 // indirect
21-
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect
2222
github.com/pmezard/go-difflib v1.0.0 // indirect
2323
golang.org/x/crypto v0.14.0 // indirect
2424
golang.org/x/net v0.16.0 // indirect
2525
golang.org/x/sys v0.13.0 // indirect
26+
gopkg.in/yaml.v2 v2.4.0 // indirect
2627
)

go.sum

+141-6
Large diffs are not rendered by default.

internal/retry/retry.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
//
66
// A sample retry operation looks like this:
77
//
8-
// func TestX(t *testing.T) {
9-
// retry.Run(t, func(r *retry.R) {
10-
// if err := foo(); err != nil {
11-
// r.Fatal("f: ", err)
12-
// }
13-
// })
14-
// }
15-
//
8+
// func TestX(t *testing.T) {
9+
// retry.Run(t, func(r *retry.R) {
10+
// if err := foo(); err != nil {
11+
// r.Fatal("f: ", err)
12+
// }
13+
// })
14+
// }
1615
package retry
1716

1817
import (

memberlist.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"sync/atomic"
3131
"time"
3232

33-
"github.com/armon/go-metrics"
33+
"github.com/hashicorp/go-metrics/compat"
3434
"github.com/hashicorp/go-multierror"
3535
"github.com/hashicorp/go-sockaddr"
3636
"github.com/miekg/dns"

net.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"sync/atomic"
1616
"time"
1717

18-
"github.com/armon/go-metrics"
18+
"github.com/hashicorp/go-metrics/compat"
1919
"github.com/hashicorp/go-msgpack/v2/codec"
2020
)
2121

net_transport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"sync/atomic"
1414
"time"
1515

16-
"github.com/armon/go-metrics"
16+
"github.com/hashicorp/go-metrics/compat"
1717
sockaddr "github.com/hashicorp/go-sockaddr"
1818
)
1919

queue.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ type Broadcast interface {
134134
// You shoud ensure that Invalidates() checks the same uniqueness as the
135135
// example below:
136136
//
137-
// func (b *foo) Invalidates(other Broadcast) bool {
138-
// nb, ok := other.(NamedBroadcast)
139-
// if !ok {
140-
// return false
141-
// }
142-
// return b.Name() == nb.Name()
143-
// }
137+
// func (b *foo) Invalidates(other Broadcast) bool {
138+
// nb, ok := other.(NamedBroadcast)
139+
// if !ok {
140+
// return false
141+
// }
142+
// return b.Name() == nb.Name()
143+
// }
144144
//
145145
// Invalidates() isn't currently used for NamedBroadcasts, but that may change
146146
// in the future.

security.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import (
1313
)
1414

1515
/*
16-
1716
Encrypted messages are prefixed with an encryptionVersion byte
1817
that is used for us to be able to properly encode/decode. We
1918
currently support the following versions:
2019
21-
0 - AES-GCM 128, using PKCS7 padding
22-
1 - AES-GCM 128, no padding. Padding not needed, caused bloat.
23-
20+
0 - AES-GCM 128, using PKCS7 padding
21+
1 - AES-GCM 128, no padding. Padding not needed, caused bloat.
2422
*/
2523
type encryptionVersion uint8
2624

state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"sync/atomic"
1414
"time"
1515

16-
"github.com/armon/go-metrics"
16+
"github.com/hashicorp/go-metrics/compat"
1717
)
1818

1919
type NodeStateType int

state_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"testing"
1717
"time"
1818

19-
"github.com/armon/go-metrics"
19+
"github.com/hashicorp/go-metrics/compat"
2020
iretry "github.com/hashicorp/memberlist/internal/retry"
2121
"github.com/stretchr/testify/require"
2222
)

0 commit comments

Comments
 (0)