From bcfc5fb9332c04d8f3e7c1cff9c33211aa80e2b0 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Thu, 15 Feb 2024 11:41:12 +0100 Subject: [PATCH] statsd: Update to datadog-go v5 API (#15247) Signed-off-by: Dirkjan Bussink --- go.mod | 3 +-- go.sum | 2 -- go/stats/statsd/statsd.go | 15 +++++++++------ go/stats/statsd/statsd_test.go | 5 ++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index b9d8ba06b85..28cf40c1907 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 github.com/Azure/azure-pipeline-go v0.2.3 github.com/Azure/azure-storage-blob-go v0.15.0 - github.com/DataDog/datadog-go v4.8.3+incompatible github.com/HdrHistogram/hdrhistogram-go v0.9.0 // indirect github.com/aquarapid/vaultlib v0.5.1 github.com/armon/go-metrics v0.4.1 // indirect @@ -92,6 +91,7 @@ require ( ) require ( + github.com/DataDog/datadog-go/v5 v5.5.0 github.com/Shopify/toxiproxy/v2 v2.7.0 github.com/bndr/gotabulate v1.1.2 github.com/gammazero/deque v0.2.1 @@ -119,7 +119,6 @@ require ( github.com/DataDog/appsec-internal-go v1.4.0 // indirect github.com/DataDog/datadog-agent/pkg/obfuscate v0.50.2 // indirect github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.50.2 // indirect - github.com/DataDog/datadog-go/v5 v5.5.0 // indirect github.com/DataDog/go-libddwaf/v2 v2.2.3 // indirect github.com/DataDog/go-sqllexer v0.0.10 // indirect github.com/DataDog/go-tuf v1.0.2-0.5.2 // indirect diff --git a/go.sum b/go.sum index ee64870fec3..456c1a3e194 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,6 @@ github.com/DataDog/datadog-agent/pkg/obfuscate v0.50.2/go.mod h1:A4nLJvxlg6BO/8/ github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.50.2 h1:7jn5EOu84uph4sd+pB3vF8LnsdTjhh+1/NnCvfNpG4A= github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.50.2/go.mod h1:Vc+snp0Bey4MrrJyiV2tVxxJb6BmLomPvN1RgAvjGaQ= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q= -github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/datadog-go/v5 v5.5.0 h1:G5KHeB8pWBNXT4Jtw0zAkhdxEAWSpWH00geHI6LDrKU= github.com/DataDog/datadog-go/v5 v5.5.0/go.mod h1:K9kcYBlxkcPP8tvvjZZKs/m1edNAUFzBbdpTUKfCsuw= github.com/DataDog/go-libddwaf/v2 v2.2.3 h1:LpKE8AYhVrEhlmlw6FGD41udtDf7zW/aMdLNbCXpegQ= diff --git a/go/stats/statsd/statsd.go b/go/stats/statsd/statsd.go index f791d7b742d..099b8eea0f6 100644 --- a/go/stats/statsd/statsd.go +++ b/go/stats/statsd/statsd.go @@ -8,7 +8,7 @@ import ( "strings" "sync" - "github.com/DataDog/datadog-go/statsd" + "github.com/DataDog/datadog-go/v5/statsd" "github.com/spf13/pflag" "vitess.io/vitess/go/stats" @@ -81,15 +81,18 @@ func InitWithoutServenv(namespace string) { log.Info("statsdAddress is empty") return } - statsdC, err := statsd.NewBuffered(statsdAddress, 100) + opts := []statsd.Option{ + statsd.WithMaxMessagesPerPayload(100), + statsd.WithNamespace(namespace), + } + if tags := stats.ParseCommonTags(stats.CommonTags); len(tags) > 0 { + opts = append(opts, statsd.WithTags(makeCommonTags(tags))) + } + statsdC, err := statsd.New(statsdAddress, opts...) if err != nil { log.Errorf("Failed to create statsd client %v", err) return } - statsdC.Namespace = namespace + "." - if tags := stats.ParseCommonTags(stats.CommonTags); len(tags) > 0 { - statsdC.Tags = makeCommonTags(tags) - } sb.namespace = namespace sb.statsdClient = statsdC sb.sampleRate = statsdSampleRate diff --git a/go/stats/statsd/statsd_test.go b/go/stats/statsd/statsd_test.go index c615da3cdfd..feab8ae6759 100644 --- a/go/stats/statsd/statsd_test.go +++ b/go/stats/statsd/statsd_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/DataDog/datadog-go/statsd" + "github.com/DataDog/datadog-go/v5/statsd" "github.com/stretchr/testify/assert" "vitess.io/vitess/go/stats" @@ -19,8 +19,7 @@ func getBackend(t *testing.T) (StatsBackend, *net.UDPConn) { udpAddr, _ := net.ResolveUDPAddr("udp", addr) server, _ := net.ListenUDP("udp", udpAddr) bufferLength := 9 - client, _ := statsd.NewBuffered(addr, bufferLength) - client.Namespace = "test." + client, _ := statsd.New(addr, statsd.WithMaxMessagesPerPayload(bufferLength), statsd.WithNamespace("test")) var sb StatsBackend sb.namespace = "foo" sb.sampleRate = 1