Skip to content

Commit

Permalink
Moving outputs/transport => common/transport (#16734)
Browse files Browse the repository at this point in the history
* Moving outputs/transport => common/transport

* Removing outputs/tls.go

* Pass config object by value (not pointer)

* Fixing formatting of imports

* Adding developer CHANGELOG entries

* Fixing formatting of imports

* Running go mod tidy

* Moving MakeDialer into transport

* Running go mod tidy
  • Loading branch information
ycombinator authored Mar 4, 2020
1 parent a846029 commit 6352ea1
Show file tree
Hide file tree
Showing 51 changed files with 98 additions and 161 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Python 3 is required now to run python tests and tools. {pull}14798[14798]
- The type `memqueue.Broker` is no longer exported; instead of `memqueue.NewBroker`, call `memqueue.NewQueue` (which provides the same public interface). {pull}16667[16667]
- `queue.Eventer` has been renamed to `queue.ACKListener` {pull}16691[16691]
- The `libbeat/outputs/transport` package has been moved to `libbeat/common/transport`. {pull}16734[16734]
- The `libbeat/outputs/tls.go` file has been removed. All exported symbols in that file (`libbeat/outputs.*`) are now available as `libbeat/common/tlscommon.*`. {pull}16734[16734]

==== Bugfixes

Expand Down
3 changes: 1 addition & 2 deletions filebeat/input/kafka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/monitoring"
"github.com/elastic/beats/v7/libbeat/monitoring/adapter"
"github.com/elastic/beats/v7/libbeat/outputs"
)

type kafkaInputConfig struct {
Expand Down Expand Up @@ -169,7 +168,7 @@ func newSaramaConfig(config kafkaInputConfig) (*sarama.Config, error) {
k.Consumer.Group.Rebalance.Retry.Backoff = config.Rebalance.RetryBackoff
k.Consumer.Group.Rebalance.Retry.Max = config.Rebalance.MaxRetries

tls, err := outputs.LoadTLSConfig(config.TLS)
tls, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions filebeat/input/mqtt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package mqtt
import (
libmqtt "github.com/eclipse/paho.mqtt.golang"

"github.com/elastic/beats/v7/libbeat/outputs"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
)

func createClientOptions(config mqttInputConfig, onConnectHandler func(client libmqtt.Client)) (*libmqtt.ClientOptions, error) {
Expand All @@ -36,7 +36,7 @@ func createClientOptions(config mqttInputConfig, onConnectHandler func(client li
}

if config.TLS != nil {
tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
tlsConfig, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions filebeat/inputsource/tcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/elastic/beats/v7/libbeat/common/atomic"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
)

// Server represent a TCP server
Expand All @@ -41,7 +40,7 @@ type Server struct {
done chan struct{}
factory HandlerFactory
log *logp.Logger
tlsConfig *transport.TLSConfig
tlsConfig *tlscommon.TLSConfig
closer *Closer
clientsCount atomic.Int
}
Expand Down
5 changes: 3 additions & 2 deletions heartbeat/monitors/active/dialchain/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
"github.com/elastic/beats/v7/heartbeat/monitors/jobs"
"github.com/elastic/beats/v7/heartbeat/monitors/wrappers"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
)

// Builder maintains a DialerChain for building dialers and dialer based
Expand All @@ -46,7 +47,7 @@ type Builder struct {
type BuilderSettings struct {
Timeout time.Duration
Socks5 transport.ProxyConfig
TLS *transport.TLSConfig
TLS *tlscommon.TLSConfig
}

// Endpoint configures a host with all port numbers to be monitored by a dialer
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/active/dialchain/dialchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package dialchain

import (
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
)

// DialerChain composes builders for multiple network layers, used to build
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/active/dialchain/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/elastic/beats/v7/heartbeat/look"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/transport"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
)

// TCPDialer creates a new NetDialer with constant event fields and default
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/active/dialchain/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/elastic/beats/v7/heartbeat/look"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
)

// SOCKS5Layer configures a SOCKS5 proxy layer in a DialerChain.
Expand Down
5 changes: 3 additions & 2 deletions heartbeat/monitors/active/dialchain/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
"github.com/elastic/beats/v7/heartbeat/look"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
)

// TLSLayer configures the TLS layer in a DialerChain.
Expand All @@ -39,7 +40,7 @@ import (
// "rtt": { "handshake": { "us": ... }}
// }
// }
func TLSLayer(cfg *transport.TLSConfig, to time.Duration) Layer {
func TLSLayer(cfg *tlscommon.TLSConfig, to time.Duration) Layer {
return func(event *beat.Event, next transport.Dialer) (transport.Dialer, error) {
var timer timer

Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/active/dialchain/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
)

type timer struct {
Expand Down
8 changes: 4 additions & 4 deletions heartbeat/monitors/active/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"github.com/elastic/beats/v7/heartbeat/monitors/jobs"
"github.com/elastic/beats/v7/heartbeat/monitors/wrappers"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/transport"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/outputs"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
)

func init() {
Expand All @@ -47,7 +47,7 @@ func create(
return nil, 0, err
}

tls, err := outputs.LoadTLSConfig(config.TLS)
tls, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, 0, err
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func create(
return js, len(config.Hosts), nil
}

func newRoundTripper(config *Config, tls *transport.TLSConfig) (*http.Transport, error) {
func newRoundTripper(config *Config, tls *tlscommon.TLSConfig) (*http.Transport, error) {
var proxy func(*http.Request) (*url.URL, error)
if config.ProxyURL != "" {
url, err := url.Parse(config.ProxyURL)
Expand Down
9 changes: 5 additions & 4 deletions heartbeat/monitors/active/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ import (

"github.com/elastic/beats/v7/heartbeat/hbtest"
"github.com/elastic/beats/v7/heartbeat/monitors/wrappers"
schedule "github.com/elastic/beats/v7/heartbeat/scheduler/schedule"
"github.com/elastic/beats/v7/heartbeat/scheduler/schedule"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/file"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
btesting "github.com/elastic/beats/v7/libbeat/testing"
"github.com/elastic/go-lookslike"
"github.com/elastic/go-lookslike/isdef"
Expand Down Expand Up @@ -512,7 +513,7 @@ func TestNewRoundTripper(t *testing.T) {

for name, config := range configs {
t.Run(name, func(t *testing.T) {
transp, err := newRoundTripper(&config, &transport.TLSConfig{})
transp, err := newRoundTripper(&config, &tlscommon.TLSConfig{})
require.NoError(t, err)

if config.ProxyURL == "" {
Expand All @@ -525,7 +526,7 @@ func TestNewRoundTripper(t *testing.T) {
require.NotNil(t, transp.Dial)
require.NotNil(t, transport.TLSDialer)

require.Equal(t, (&transport.TLSConfig{}).ToConfig(), transp.TLSClientConfig)
require.Equal(t, (&tlscommon.TLSConfig{}).ToConfig(), transp.TLSClientConfig)
require.True(t, transp.DisableKeepAlives)
})
}
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/active/http/simple_transp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"net/url"
"strings"

"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
)

const (
Expand Down
9 changes: 4 additions & 5 deletions heartbeat/monitors/active/http/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"sync"
"time"

"github.com/elastic/beats/v7/libbeat/common/useragent"

"github.com/elastic/beats/v7/heartbeat/eventext"
"github.com/elastic/beats/v7/heartbeat/look"
"github.com/elastic/beats/v7/heartbeat/monitors"
Expand All @@ -39,7 +37,8 @@ import (
"github.com/elastic/beats/v7/heartbeat/reason"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/v7/libbeat/common/useragent"
)

var userAgent = useragent.UserAgent("Heartbeat")
Expand Down Expand Up @@ -79,7 +78,7 @@ func newHTTPMonitorHostJob(
func newHTTPMonitorIPsJob(
config *Config,
addr string,
tls *transport.TLSConfig,
tls *tlscommon.TLSConfig,
enc contentEncoder,
body []byte,
validator multiValidator,
Expand All @@ -106,7 +105,7 @@ func newHTTPMonitorIPsJob(
func createPingFactory(
config *Config,
port uint16,
tls *transport.TLSConfig,
tls *tlscommon.TLSConfig,
request *http.Request,
body []byte,
validator multiValidator,
Expand Down
5 changes: 2 additions & 3 deletions heartbeat/monitors/active/tcp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
"errors"
"time"

"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/v7/libbeat/outputs/transport"

"github.com/elastic/beats/v7/heartbeat/monitors"
"github.com/elastic/beats/v7/libbeat/common/transport"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
)

type Config struct {
Expand Down
2 changes: 1 addition & 1 deletion heartbeat/monitors/active/tcp/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/elastic/beats/v7/heartbeat/reason"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
"github.com/elastic/beats/v7/libbeat/common/transport"
)

func pingHost(
Expand Down
6 changes: 3 additions & 3 deletions heartbeat/monitors/active/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/elastic/beats/v7/heartbeat/monitors/jobs"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/transport"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/outputs"
"github.com/elastic/beats/v7/libbeat/outputs/transport"
)

func init() {
Expand All @@ -54,7 +54,7 @@ func create(
return nil, 0, err
}

tls, err := outputs.LoadTLSConfig(config.TLS)
tls, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, 0, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,28 @@ import (
"sync"
"time"

"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/v7/libbeat/testing"
)

type Client struct {
dialer Dialer
network string
host string
config *Config
config Config

conn net.Conn
mutex sync.Mutex
}

type Config struct {
Proxy *ProxyConfig
TLS *TLSConfig
TLS *tlscommon.TLSConfig
Timeout time.Duration
Stats IOStatser
}

func MakeDialer(c *Config) (Dialer, error) {
var err error
dialer := NetDialer(c.Timeout)
dialer, err = ProxyDialer(c.Proxy, dialer)
if err != nil {
return nil, err
}
if c.Stats != nil {
dialer = StatsDialer(dialer, c.Stats)
}

if c.TLS != nil {
return TLSDialer(dialer, c.TLS, c.Timeout)
}
return dialer, nil
}

func NewClient(c *Config, network, host string, defaultPort int) (*Client, error) {
func NewClient(c Config, network, host string, defaultPort int) (*Client, error) {
// do some sanity checks regarding network and Config matching +
// address being parseable
switch network {
Expand All @@ -82,7 +66,7 @@ func NewClient(c *Config, network, host string, defaultPort int) (*Client, error
return NewClientWithDialer(dialer, c, network, host, defaultPort)
}

func NewClientWithDialer(d Dialer, c *Config, network, host string, defaultPort int) (*Client, error) {
func NewClientWithDialer(d Dialer, c Config, network, host string, defaultPort int) (*Client, error) {
// check address being parseable
host = fullAddress(host, defaultPort)
_, _, err := net.SplitHostPort(host)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6352ea1

Please sign in to comment.