Skip to content

Commit

Permalink
statsd: Update to datadog-go v5 API (#15247)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Feb 15, 2024
1 parent 7327b22 commit bcfc5fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
15 changes: 9 additions & 6 deletions go/stats/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions go/stats/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit bcfc5fb

Please sign in to comment.