From 3335e79783fa50d0c3241bc0a39999f760d65117 Mon Sep 17 00:00:00 2001 From: Tiago Queiroz Date: Thu, 11 Apr 2024 15:42:23 +0200 Subject: [PATCH] Accommodate for breaking changes in elastic-agent-libs --- heartbeat/monitors/active/dialchain/dialers.go | 5 +++-- heartbeat/monitors/active/dialchain/util.go | 7 ++++--- metricbeat/helper/dialer/dialer_windows.go | 3 ++- x-pack/filebeat/input/cel/transport_windows.go | 5 +++++ x-pack/filebeat/input/httpjson/client_windows.go | 5 +++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/heartbeat/monitors/active/dialchain/dialers.go b/heartbeat/monitors/active/dialchain/dialers.go index 7889ac82a278..44adf8301f73 100644 --- a/heartbeat/monitors/active/dialchain/dialers.go +++ b/heartbeat/monitors/active/dialchain/dialers.go @@ -18,6 +18,7 @@ package dialchain import ( + "context" "fmt" "net" "strconv" @@ -69,7 +70,7 @@ func UDPDialer(to time.Duration) NetDialer { // CreateNetDialer returns a NetDialer with the given timeout. func CreateNetDialer(timeout time.Duration) NetDialer { return func(event *beat.Event) (transport.Dialer, error) { - return makeDialer(func(network, address string) (net.Conn, error) { + return makeDialer(func(ctx context.Context, network, address string) (net.Conn, error) { var namespace string switch network { @@ -100,7 +101,7 @@ func CreateNetDialer(timeout time.Duration) NetDialer { dialer := &net.Dialer{Timeout: timeout} start := time.Now() - conn, err := transport.DialWith(dialer, network, host, addresses, port) + conn, err := transport.DialWith(ctx, dialer, network, host, addresses, port) if err != nil { return nil, ecserr.NewCouldNotConnectErr(host, port, err) } diff --git a/heartbeat/monitors/active/dialchain/util.go b/heartbeat/monitors/active/dialchain/util.go index cb4ddc64cfe7..99a5381289e8 100644 --- a/heartbeat/monitors/active/dialchain/util.go +++ b/heartbeat/monitors/active/dialchain/util.go @@ -18,6 +18,7 @@ package dialchain import ( + "context" "net" "time" @@ -58,7 +59,7 @@ func (t *timer) stop() { t.e = time.Now() } func (t *timer) duration() time.Duration { return t.e.Sub(t.s) } // makeDialer aliases transport.DialerFunc -func makeDialer(fn func(network, address string) (net.Conn, error)) transport.Dialer { +func makeDialer(fn func(ctx context.Context, network, address string) (net.Conn, error)) transport.Dialer { return transport.DialerFunc(fn) } @@ -66,7 +67,7 @@ func makeDialer(fn func(network, address string) (net.Conn, error)) transport.Di // The callback must return the original or a new address to be used with // the dialer. func beforeDial(dialer transport.Dialer, fn func(string) string) transport.Dialer { - return makeDialer(func(network, address string) (net.Conn, error) { + return makeDialer(func(ctx context.Context, network, address string) (net.Conn, error) { address = fn(address) return dialer.Dial(network, address) }) @@ -74,7 +75,7 @@ func beforeDial(dialer transport.Dialer, fn func(string) string) transport.Diale // afterDial will run fn after the dialer did successfully return a connection. func afterDial(dialer transport.Dialer, fn func(net.Conn) (net.Conn, error)) transport.Dialer { - return makeDialer(func(network, address string) (net.Conn, error) { + return makeDialer(func(ctx context.Context, network, address string) (net.Conn, error) { conn, err := dialer.Dial(network, address) if err == nil { conn, err = fn(conn) diff --git a/metricbeat/helper/dialer/dialer_windows.go b/metricbeat/helper/dialer/dialer_windows.go index 0ef34666d2a8..a91b5a3868c2 100644 --- a/metricbeat/helper/dialer/dialer_windows.go +++ b/metricbeat/helper/dialer/dialer_windows.go @@ -20,6 +20,7 @@ package dialer import ( + "context" "errors" "net" "strings" @@ -60,7 +61,7 @@ func (t *NpipeDialerBuilder) String() string { func (t *NpipeDialerBuilder) Make(timeout time.Duration) (transport.Dialer, error) { to := timeout return transport.DialerFunc( - func(_, _ string) (net.Conn, error) { + func(_ context.Context, _, _ string) (net.Conn, error) { return winio.DialPipe( strings.TrimSuffix(npipe.TransformString(t.Path), "/"), &to, diff --git a/x-pack/filebeat/input/cel/transport_windows.go b/x-pack/filebeat/input/cel/transport_windows.go index 7ab3ffc664be..123b437efdab 100644 --- a/x-pack/filebeat/input/cel/transport_windows.go +++ b/x-pack/filebeat/input/cel/transport_windows.go @@ -7,6 +7,7 @@ package cel import ( + "context" "net" "path/filepath" @@ -21,3 +22,7 @@ type npipeDialer struct { func (d npipeDialer) Dial(_, _ string) (net.Conn, error) { return winio.DialPipe(`\\.\pipe`+filepath.FromSlash(d.path), nil) } + +func (d npipeDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { + return winio.DialPipeContext(ctx, `\\.\pipe`+filepath.FromSlash(d.path)) +} diff --git a/x-pack/filebeat/input/httpjson/client_windows.go b/x-pack/filebeat/input/httpjson/client_windows.go index e6e5bb05f34a..ab18be3397e3 100644 --- a/x-pack/filebeat/input/httpjson/client_windows.go +++ b/x-pack/filebeat/input/httpjson/client_windows.go @@ -7,6 +7,7 @@ package httpjson import ( + "context" "net" "path/filepath" @@ -21,3 +22,7 @@ type npipeDialer struct { func (d npipeDialer) Dial(_, _ string) (net.Conn, error) { return winio.DialPipe(`\\.\pipe`+filepath.FromSlash(d.path), nil) } + +func (d npipeDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { + return winio.DialPipeContext(ctx, `\\.\pipe`+filepath.FromSlash(d.path)) +}