Skip to content

Commit

Permalink
add SetTLSHandshakeTimeout to config
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkenny committed Dec 4, 2024
1 parent c2d0a52 commit 969ad11
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
3 changes: 3 additions & 0 deletions agg/agg.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agg

import (
"log"
"sync"
"time"

Expand Down Expand Up @@ -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()
Expand Down
19 changes: 13 additions & 6 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net"
"net/http"
"net/url"
Expand All @@ -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{}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
36 changes: 21 additions & 15 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 969ad11

Please sign in to comment.