From 955ac74326ac0d7b6af7640da6a2bb4437603bae Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Fri, 17 Jan 2025 13:24:44 -0500 Subject: [PATCH 1/2] Upgrade to using hashicorp/go-metrics instead of armon/go-metrics This necessarily also pulls in the upgraded version of the consul-server-connection-manager library. --- .github/workflows/build.yml | 16 ++++++++-------- .github/workflows/consul-dataplane-checks.yaml | 5 ++++- go.mod | 5 +++-- go.sum | 5 +++++ pkg/consuldp/consul_dataplane.go | 2 +- pkg/consuldp/metrics.go | 6 +++--- pkg/consuldp/metrics_test.go | 2 +- pkg/consuldp/stats.go | 2 +- pkg/consuldp/xds.go | 2 +- pkg/metrics-cache/metricscache.go | 2 +- pkg/metrics-cache/metricscache_test.go | 2 +- 11 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e323c9c3..1f2e8e13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,14 +75,14 @@ jobs: strategy: matrix: include: - - {goos: "linux", goarch: "arm"} - - {goos: "linux", goarch: "arm64"} - - {goos: "linux", goarch: "386"} - - {goos: "linux", goarch: "amd64"} - - {goos: "linux", goarch: "amd64", gotags: "fips", env: "CGO_ENABLED=1 GOEXPERIMENT=boringcrypto", fips: "+fips1402", pkg_suffix: "-fips" } - - {goos: "linux", goarch: "arm64", gotags: "fips", env: "CGO_ENABLED=1 GOEXPERIMENT=boringcrypto CC=aarch64-linux-gnu-gcc", fips: "+fips1402", pkg_suffix: "-fips" } - - {goos: "darwin", goarch: "amd64"} - - {goos: "darwin", goarch: "arm64"} + - {goos: "linux", goarch: "arm", gotags: "hashicorpmetrics"} + - {goos: "linux", goarch: "arm64", gotags: "hashicorpmetrics"} + - {goos: "linux", goarch: "386", gotags: "hashicorpmetrics"} + - {goos: "linux", goarch: "amd64", gotags: "hashicorpmetrics"} + - {goos: "linux", goarch: "amd64", gotags: "hashicorpmetrics,fips", env: "CGO_ENABLED=1 GOEXPERIMENT=boringcrypto", fips: "+fips1402", pkg_suffix: "-fips" } + - {goos: "linux", goarch: "arm64", gotags: "hashicorpmetrics,fips", env: "CGO_ENABLED=1 GOEXPERIMENT=boringcrypto CC=aarch64-linux-gnu-gcc", fips: "+fips1402", pkg_suffix: "-fips" } + - {goos: "darwin", goarch: "amd64", gotags: "hashicorpmetrics"} + - {goos: "darwin", goarch: "arm64", gotags: "hashicorpmetrics"} fail-fast: true diff --git a/.github/workflows/consul-dataplane-checks.yaml b/.github/workflows/consul-dataplane-checks.yaml index 79d821ca..4529226b 100644 --- a/.github/workflows/consul-dataplane-checks.yaml +++ b/.github/workflows/consul-dataplane-checks.yaml @@ -6,7 +6,10 @@ on: - main - release/** pull_request: - + +env: + GOFLAGS: "-tags=hashicorpmetrics" + jobs: conditional-skip: uses: ./.github/workflows/reusable-conditional-skip.yml diff --git a/go.mod b/go.mod index 91a545fd..92cc44b7 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,11 @@ go 1.20 require ( dario.cat/mergo v1.0.0 - github.com/armon/go-metrics v0.4.1 github.com/hashi-derek/grpc-proxy v0.0.0-20231207191910-191266484d75 - github.com/hashicorp/consul-server-connection-manager v0.1.9 + github.com/hashicorp/consul-server-connection-manager v0.1.10 github.com/hashicorp/consul/proto-public v0.6.3 github.com/hashicorp/go-hclog v1.5.0 + github.com/hashicorp/go-metrics v0.5.4 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-rootcerts v1.0.2 github.com/mitchellh/mapstructure v1.5.0 @@ -20,6 +20,7 @@ require ( require ( github.com/DataDog/datadog-go v3.2.0+incompatible // indirect + github.com/armon/go-metrics v0.4.1 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect diff --git a/go.sum b/go.sum index c82aa028..5ca3dc38 100644 --- a/go.sum +++ b/go.sum @@ -149,6 +149,8 @@ github.com/hashi-derek/grpc-proxy v0.0.0-20231207191910-191266484d75 h1:V5Uqf7Vo github.com/hashi-derek/grpc-proxy v0.0.0-20231207191910-191266484d75/go.mod h1:5eEnHfK72jOkp4gC1dI/Q/E9MFNOM/ewE/vql5ijV3g= github.com/hashicorp/consul-server-connection-manager v0.1.9 h1:jHO10v0Hk/WE05qz1gnUDd9WPQEFf5e2bP1Gs+s56rA= github.com/hashicorp/consul-server-connection-manager v0.1.9/go.mod h1:rsVRioiTxfyh4yXcEnm1Lb9RrzJl0Lz08+nLgdlZR2I= +github.com/hashicorp/consul-server-connection-manager v0.1.10 h1:L4O8Y+vSoF2e+Yj8ttuYiuDCglCseXt9hB09AXeXHAM= +github.com/hashicorp/consul-server-connection-manager v0.1.10/go.mod h1:Y2BihRUCMQtooOQTyrlMzfa04OjXfu/zcsX34tBCcjY= github.com/hashicorp/consul/proto-public v0.6.3 h1:iDA+fHtcqIc3kMMWkND6CD9W98jfKER0EC9GI7jOUvg= github.com/hashicorp/consul/proto-public v0.6.3/go.mod h1:a1pOtKbQ2+iRnMlEA2bywlEZ0nbCQ2pS7GDQN6pqLwU= github.com/hashicorp/consul/sdk v0.16.1 h1:V8TxTnImoPD5cj0U9Spl0TUxcytjcbbJeADFF07KdHg= @@ -160,6 +162,8 @@ github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+ github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-metrics v0.5.4 h1:8mmPiIJkTPPEbAiV97IxdAGNdRdaWwVap1BU6elejKY= +github.com/hashicorp/go-metrics v0.5.4/go.mod h1:CG5yz4NZ/AI/aQt9Ucm/vdBnbh7fvmv4lxZ350i+QQI= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-netaddrs v0.1.0 h1:TnlYvODD4C/wO+j7cX1z69kV5gOzI87u3OcUinANaW8= @@ -229,6 +233,7 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_golang v1.13.0 h1:b71QUfeo5M8gq2+evJdTPfZhYMAU0uKPkyPJ7TPsloU= github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ= diff --git a/pkg/consuldp/consul_dataplane.go b/pkg/consuldp/consul_dataplane.go index 76df0b99..84a14134 100644 --- a/pkg/consuldp/consul_dataplane.go +++ b/pkg/consuldp/consul_dataplane.go @@ -12,11 +12,11 @@ import ( "net/http" "strings" - "github.com/armon/go-metrics" "github.com/hashicorp/consul-server-connection-manager/discovery" "github.com/hashicorp/consul/proto-public/pbdataplane" "github.com/hashicorp/consul/proto-public/pbdns" "github.com/hashicorp/go-hclog" + "github.com/hashicorp/go-metrics" "google.golang.org/grpc" "github.com/hashicorp/consul-dataplane/pkg/dns" diff --git a/pkg/consuldp/metrics.go b/pkg/consuldp/metrics.go index 64213a07..043c5b9d 100644 --- a/pkg/consuldp/metrics.go +++ b/pkg/consuldp/metrics.go @@ -14,11 +14,11 @@ import ( "sync" "time" - "github.com/armon/go-metrics" - "github.com/armon/go-metrics/datadog" - "github.com/armon/go-metrics/prometheus" "github.com/hashicorp/consul-server-connection-manager/discovery" "github.com/hashicorp/go-hclog" + "github.com/hashicorp/go-metrics" + "github.com/hashicorp/go-metrics/datadog" + "github.com/hashicorp/go-metrics/prometheus" "github.com/hashicorp/go-multierror" prom "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/collectors" diff --git a/pkg/consuldp/metrics_test.go b/pkg/consuldp/metrics_test.go index 6dd7fd5b..b2702048 100644 --- a/pkg/consuldp/metrics_test.go +++ b/pkg/consuldp/metrics_test.go @@ -17,7 +17,7 @@ import ( "testing" "time" - "github.com/armon/go-metrics" + "github.com/hashicorp/go-metrics" "github.com/stretchr/testify/require" "github.com/hashicorp/consul-dataplane/internal/bootstrap" diff --git a/pkg/consuldp/stats.go b/pkg/consuldp/stats.go index a3fb7a14..201f6430 100644 --- a/pkg/consuldp/stats.go +++ b/pkg/consuldp/stats.go @@ -3,7 +3,7 @@ package consuldp -import "github.com/armon/go-metrics/prometheus" +import "github.com/hashicorp/go-metrics/prometheus" var gauges = []prometheus.GaugeDefinition{ { diff --git a/pkg/consuldp/xds.go b/pkg/consuldp/xds.go index f3cb564f..801ab3d9 100644 --- a/pkg/consuldp/xds.go +++ b/pkg/consuldp/xds.go @@ -9,8 +9,8 @@ import ( "net" "strings" - "github.com/armon/go-metrics" "github.com/hashi-derek/grpc-proxy/proxy" + "github.com/hashicorp/go-metrics" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" diff --git a/pkg/metrics-cache/metricscache.go b/pkg/metrics-cache/metricscache.go index 1b6819f2..3b45089c 100644 --- a/pkg/metrics-cache/metricscache.go +++ b/pkg/metrics-cache/metricscache.go @@ -7,7 +7,7 @@ import ( "sync" "sync/atomic" - "github.com/armon/go-metrics" + "github.com/hashicorp/go-metrics" ) type metric struct { diff --git a/pkg/metrics-cache/metricscache_test.go b/pkg/metrics-cache/metricscache_test.go index 22167348..a239a3f6 100644 --- a/pkg/metrics-cache/metricscache_test.go +++ b/pkg/metrics-cache/metricscache_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/armon/go-metrics" + "github.com/hashicorp/go-metrics" "github.com/stretchr/testify/require" ) From 81a6dc1f0666255d44d5ec60d7163849d292fe9b Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Fri, 17 Jan 2025 13:36:50 -0500 Subject: [PATCH 2/2] Fixup tags in Makefile and enable the depguard in golangci-lint --- .golangci.yml | 21 ++++++++++++++++++--- Makefile | 4 +++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2ead2dec..6bb6cb5c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,9 +1,24 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 +linters: + enable: + - depguard + issues: exclude-rules: # Allow usage of deprecated values. - - linters: [ staticcheck ] - text: 'SA1019:' - path: "(pkg/consuldp/bootstrap.go)" \ No newline at end of file + - linters: [staticcheck] + text: "SA1019:" + path: "(pkg/consuldp/bootstrap.go)" + +linters-settings: + depguard: + rules: + main: + list-mode: lax + deny: + - pkg: github.com/armon/go-metrics + desc: "use github.com/hashicorp/go-metrics" + - pkg: github.com/hashicorp/go-metrics/compat + desc: "use github.com/hashicorp/go-metrics" diff --git a/Makefile b/Makefile index cb3c7c0f..36f8e09b 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,8 @@ PLATFORM = $(OS)/$(ARCH) DIST = dist/$(PLATFORM) BIN = $(DIST)/$(BIN_NAME) +GOTAGS=hashicorpmetrics + VERSION = $(shell ./build-scripts/version.sh pkg/version/version.go) GOLANG_VERSION ?= $(shell head -n 1 .go-version) BOOTSTRAP_PACKAGE_DIR=internal/bootstrap @@ -44,7 +46,7 @@ dist: ## make dist directory and ignore everything .PHONY: bin bin: dist ## Build the binary - GOARCH=$(ARCH) GOOS=$(OS) CGO_ENABLED=0 go build -trimpath -buildvcs=false -ldflags="$(GOLDFLAGS)" -o $(BIN) ./cmd/$(BIN_NAME) + GOARCH=$(ARCH) GOOS=$(OS) CGO_ENABLED=0 go build -tags="$(GOTAGS)" -trimpath -buildvcs=false -ldflags="$(GOLDFLAGS)" -o $(BIN) ./cmd/$(BIN_NAME) .PHONY: dev dev: bin ## Build binary and copy to the destination