Skip to content

Commit

Permalink
Accommodate for breaking changes in elastic-agent-libs
Browse files Browse the repository at this point in the history
  • Loading branch information
belimawr committed Apr 11, 2024
1 parent 70fcf1d commit 3335e79
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions heartbeat/monitors/active/dialchain/dialers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package dialchain

import (
"context"
"fmt"
"net"
"strconv"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 4 additions & 3 deletions heartbeat/monitors/active/dialchain/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package dialchain

import (
"context"
"net"
"time"

Expand Down Expand Up @@ -58,23 +59,23 @@ 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)
}

// beforeDial will always call fn before executing the underlying dialer.
// 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)
})
}

// 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)
Expand Down
3 changes: 2 additions & 1 deletion metricbeat/helper/dialer/dialer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package dialer

import (
"context"
"errors"
"net"
"strings"
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions x-pack/filebeat/input/cel/transport_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package cel

import (
"context"
"net"
"path/filepath"

Expand All @@ -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))
}
5 changes: 5 additions & 0 deletions x-pack/filebeat/input/httpjson/client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package httpjson

import (
"context"
"net"
"path/filepath"

Expand All @@ -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))
}

0 comments on commit 3335e79

Please sign in to comment.