From 969ad11df2d85ee5a46c4de57531b7498c4eba92 Mon Sep 17 00:00:00 2001 From: Kenny Hanson Date: Wed, 4 Dec 2024 15:18:30 -0800 Subject: [PATCH 1/2] add SetTLSHandshakeTimeout to config --- agg/agg.go | 3 +++ api/client.go | 19 +++++++++++++------ config.go | 36 +++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/agg/agg.go b/agg/agg.go index c27b7f3..b4ada93 100644 --- a/agg/agg.go +++ b/agg/agg.go @@ -1,6 +1,7 @@ package agg import ( + "log" "sync" "time" @@ -95,6 +96,8 @@ func (a *Agg) aggregate() { for { select { case <-a.ticker.C: + log.Printf("agg size %d", a.queue.count) + log.Printf("dropped %d", a.queue.dropped) a.dispatch() case <-a.quitting: a.dispatch() diff --git a/api/client.go b/api/client.go index c141f00..faffd02 100644 --- a/api/client.go +++ b/api/client.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "log" "net" "net/http" "net/url" @@ -25,12 +26,13 @@ type Client struct { } type ClientConfig struct { - Email string - Token string - Timeout time.Duration - Retries int - API *url.URL - Proxy *url.URL + Email string + Token string + Timeout time.Duration + TLSHandshakeTimeout time.Duration + Retries int + API *url.URL + Proxy *url.URL Logger interface{} } @@ -62,6 +64,10 @@ func NewClient(config ClientConfig) *Client { DisableCompression: false, } + if config.TLSHandshakeTimeout.Seconds() > 0 { + transport.TLSHandshakeTimeout = config.TLSHandshakeTimeout + } + retryClient := retryablehttp.NewClient() retryClient.HTTPClient.Transport = transport retryClient.RetryWaitMin = config.Timeout @@ -379,6 +385,7 @@ func (c *Client) UpdateInterfacesDirectly(dev *Device, updates map[string]Interf func (c *Client) SendFlow(url string, buf *bytes.Buffer) error { r, err := c.do("POST", url, "application/binary", buf, true) if err != nil { + log.Printf("error in sendFlow %v", err) return err } diff --git a/config.go b/config.go index 3329662..470b5a3 100644 --- a/config.go +++ b/config.go @@ -18,21 +18,22 @@ import ( // Config describes the libkflow configuration. type Config struct { - email string - token string - capture Capture - proxy *url.URL - api *url.URL - flow *url.URL - metrics *url.URL - sample int - timeout time.Duration - retries int - logger interface{} - program string - version string - registry go_metrics.Registry - useInternalErrors bool + email string + token string + capture Capture + proxy *url.URL + api *url.URL + flow *url.URL + metrics *url.URL + sample int + timeout time.Duration + tlsHandshakeTimeout time.Duration + retries int + logger interface{} + program string + version string + registry go_metrics.Registry + useInternalErrors bool metricsPrefix string metricsInterval time.Duration @@ -93,6 +94,11 @@ func (c *Config) SetTimeout(timeout time.Duration) { c.timeout = timeout } +// SetTLSHandshakeTimeout sets the TLSHandshakeTimeout on the http client's Transport +func (c *Config) SetTLSHandshakeTimeout(timeout time.Duration) { + c.tlsHandshakeTimeout = timeout +} + // SetRetries sets the number of times to try HTTP requests. func (c *Config) SetRetries(retries int) { c.retries = retries From a6c39c6b878bfa13954917f037d1b6f3b6e15409 Mon Sep 17 00:00:00 2001 From: Kenny Hanson Date: Wed, 4 Dec 2024 15:59:41 -0800 Subject: [PATCH 2/2] remove log.printf --- agg/agg.go | 3 --- api/client.go | 2 -- 2 files changed, 5 deletions(-) diff --git a/agg/agg.go b/agg/agg.go index b4ada93..c27b7f3 100644 --- a/agg/agg.go +++ b/agg/agg.go @@ -1,7 +1,6 @@ package agg import ( - "log" "sync" "time" @@ -96,8 +95,6 @@ func (a *Agg) aggregate() { for { select { case <-a.ticker.C: - log.Printf("agg size %d", a.queue.count) - log.Printf("dropped %d", a.queue.dropped) a.dispatch() case <-a.quitting: a.dispatch() diff --git a/api/client.go b/api/client.go index faffd02..6f55b3a 100644 --- a/api/client.go +++ b/api/client.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net" "net/http" "net/url" @@ -385,7 +384,6 @@ func (c *Client) UpdateInterfacesDirectly(dev *Device, updates map[string]Interf func (c *Client) SendFlow(url string, buf *bytes.Buffer) error { r, err := c.do("POST", url, "application/binary", buf, true) if err != nil { - log.Printf("error in sendFlow %v", err) return err }