Skip to content

Commit

Permalink
Introduce hashicorp/go-metrics compatibility (#760)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mkeeler authored Jan 14, 2025
1 parent 0a77f05 commit 93c69c0
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 14 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,29 @@ Tests can be run by typing `make test`.

If you make any changes to the code, run `make format` in order to automatically
format the code according to Go [standards](https://golang.org/doc/effective_go.html#formatting).


## Metrics Emission and Compatibility

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.

**Build Tags**
* `armonmetrics` - Using this tag will cause metrics to be routed to `armon/go-metrics`
* `hashicorpmetrics` - Using this tag will cause all metrics to be routed to `hashicorp/go-metrics`

If no build tag is specified, the default behavior is to use `armon/go-metrics`.

**Deprecating `armon/go-metrics`**

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.

**Migration**
To migrate an application currently using the older `armon/go-metrics` to instead use `hashicorp/go-metrics` the following should be done.

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
2. Update an applications library dependencies to those that have the compatibility layer configured.
3. Update the application to use `hashicorp/go-metrics` for configuring metrics export instead of `armon/go-metrics`
* Replace all application imports of `github.com/armon/go-metrics` with `github.com/hashicorp/go-metrics`
* Instrument your build system to build with the `hashicorpmetrics` tag.

Eventually once the default behavior changes to use `hashicorp/go-metrics` by default (mid-2025), you can drop the `hashicorpmetrics` build tag.
2 changes: 1 addition & 1 deletion cmd/serf/command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"syscall"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
gsyslog "github.com/hashicorp/go-syslog"
"github.com/hashicorp/logutils"
"github.com/hashicorp/memberlist"
Expand Down
2 changes: 1 addition & 1 deletion cmd/serf/command/agent/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"time"

"github.com/armon/circbuf"
"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
"github.com/hashicorp/serf/serf"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/serf/command/agent/ipc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"sync/atomic"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
"github.com/hashicorp/go-msgpack/v2/codec"
"github.com/hashicorp/logutils"
"github.com/hashicorp/serf/coordinate"
Expand Down
2 changes: 1 addition & 1 deletion coordinate/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
)

// Client manages the estimated network coordinate for a given node, and adjusts
Expand Down
2 changes: 1 addition & 1 deletion coordinate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package coordinate

import (
"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
)

// Config is used to set the parameters of the Vivaldi-based coordinate mapping
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ go 1.19

require (
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
github.com/armon/go-metrics v0.4.1
github.com/hashicorp/go-metrics v0.5.4
github.com/hashicorp/go-msgpack/v2 v2.1.2
github.com/hashicorp/go-syslog v1.0.0
github.com/hashicorp/logutils v1.0.0
github.com/hashicorp/mdns v1.0.5
github.com/hashicorp/memberlist v0.5.1
github.com/hashicorp/memberlist v0.5.2
github.com/mitchellh/cli v1.1.5
github.com/mitchellh/mapstructure v1.5.0
github.com/ryanuber/columnize v2.1.2+incompatible
Expand All @@ -19,6 +19,7 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.1 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/fatih/color v1.9.0 // indirect
Expand Down
55 changes: 53 additions & 2 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion serf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
"github.com/hashicorp/memberlist"
)

Expand Down
2 changes: 1 addition & 1 deletion serf/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"fmt"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
"github.com/hashicorp/go-msgpack/v2/codec"
"github.com/hashicorp/memberlist"
)
Expand Down
2 changes: 1 addition & 1 deletion serf/ping_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
"github.com/hashicorp/go-msgpack/v2/codec"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/serf/coordinate"
Expand Down
2 changes: 1 addition & 1 deletion serf/serf.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"sync/atomic"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
"github.com/hashicorp/go-msgpack/v2/codec"
"github.com/hashicorp/memberlist"
"github.com/hashicorp/serf/coordinate"
Expand Down
2 changes: 1 addition & 1 deletion serf/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"strings"
"time"

"github.com/armon/go-metrics"
"github.com/hashicorp/go-metrics/compat"
)

/*
Expand Down

0 comments on commit 93c69c0

Please sign in to comment.