Skip to content

Commit

Permalink
[Backport 7.62.x][incident-33684] Reuse sysprobe-client between trace…
Browse files Browse the repository at this point in the history
…route calls (#32716)

Co-authored-by: Stuart Geipel <[email protected]>
  • Loading branch information
AliDatadog and pimlu authored Jan 7, 2025
1 parent 7a5ab99 commit c81818b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
10 changes: 2 additions & 8 deletions pkg/networkpath/traceroute/traceroute_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import (
"encoding/json"
"net/http"

sysprobeclient "github.com/DataDog/datadog-agent/cmd/system-probe/api/client"
"github.com/DataDog/datadog-agent/comp/core/telemetry"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/networkpath/payload"
"github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
Expand All @@ -37,12 +35,8 @@ type LinuxTraceroute struct {
func New(cfg config.Config, _ telemetry.Component) (*LinuxTraceroute, error) {
log.Debugf("Creating new traceroute with config: %+v", cfg)
return &LinuxTraceroute{
cfg: cfg,
sysprobeClient: &http.Client{
Transport: &http.Transport{
DialContext: sysprobeclient.DialContextFunc(pkgconfigsetup.SystemProbe().GetString("system_probe_config.sysprobe_socket")),
},
},
cfg: cfg,
sysprobeClient: getSysProbeClient(),
}, nil
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/networkpath/traceroute/traceroute_sysprobe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build linux || windows

package traceroute

import (
"net/http"

sysprobeclient "github.com/DataDog/datadog-agent/cmd/system-probe/api/client"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/util/funcs"
)

var getSysProbeClient = funcs.MemoizeNoError(func() *http.Client {
return &http.Client{
Transport: &http.Transport{
DialContext: sysprobeclient.DialContextFunc(pkgconfigsetup.SystemProbe().GetString("system_probe_config.sysprobe_socket")),
},
}
})
10 changes: 2 additions & 8 deletions pkg/networkpath/traceroute/traceroute_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
"errors"
"net/http"

sysprobeclient "github.com/DataDog/datadog-agent/cmd/system-probe/api/client"
"github.com/DataDog/datadog-agent/comp/core/telemetry"
pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
"github.com/DataDog/datadog-agent/pkg/networkpath/payload"
"github.com/DataDog/datadog-agent/pkg/networkpath/traceroute/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
Expand Down Expand Up @@ -45,12 +43,8 @@ func New(cfg config.Config, _ telemetry.Component) (*WindowsTraceroute, error) {
}

return &WindowsTraceroute{
cfg: cfg,
sysprobeClient: &http.Client{
Transport: &http.Transport{
DialContext: sysprobeclient.DialContextFunc(pkgconfigsetup.SystemProbe().GetString("system_probe_config.sysprobe_socket")),
},
},
cfg: cfg,
sysprobeClient: getSysProbeClient(),
}, nil
}

Expand Down

0 comments on commit c81818b

Please sign in to comment.