From c81818b75078b5aa48741baeea7bcdbb7618a8b3 Mon Sep 17 00:00:00 2001 From: AliDatadog <125997632+AliDatadog@users.noreply.github.com> Date: Tue, 7 Jan 2025 12:10:56 +0100 Subject: [PATCH] [Backport 7.62.x][incident-33684] Reuse sysprobe-client between traceroute calls (#32716) Co-authored-by: Stuart Geipel --- .../traceroute/traceroute_linux.go | 10 ++------ .../traceroute/traceroute_sysprobe.go | 24 +++++++++++++++++++ .../traceroute/traceroute_windows.go | 10 ++------ 3 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 pkg/networkpath/traceroute/traceroute_sysprobe.go diff --git a/pkg/networkpath/traceroute/traceroute_linux.go b/pkg/networkpath/traceroute/traceroute_linux.go index e3d54f61ccf48..28f470ba8e02d 100644 --- a/pkg/networkpath/traceroute/traceroute_linux.go +++ b/pkg/networkpath/traceroute/traceroute_linux.go @@ -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" @@ -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 } diff --git a/pkg/networkpath/traceroute/traceroute_sysprobe.go b/pkg/networkpath/traceroute/traceroute_sysprobe.go new file mode 100644 index 0000000000000..dd2c21c47b287 --- /dev/null +++ b/pkg/networkpath/traceroute/traceroute_sysprobe.go @@ -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")), + }, + } +}) diff --git a/pkg/networkpath/traceroute/traceroute_windows.go b/pkg/networkpath/traceroute/traceroute_windows.go index 8e05c249e4a35..b0913e8ba95ec 100644 --- a/pkg/networkpath/traceroute/traceroute_windows.go +++ b/pkg/networkpath/traceroute/traceroute_windows.go @@ -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" @@ -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 }