Skip to content

Commit

Permalink
feat: improve TCP connect statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Apr 15, 2024
1 parent 8120c06 commit 3207255
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/enginenetx/httpsdialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type httpsDialerEventsHandler interface {
// case, obviously, you MUST NOT consider the tactic failed.
OnStarting(tactic *httpsDialerTactic)
OnTCPConnectError(ctx context.Context, tactic *httpsDialerTactic, err error)
OnTCPConnectSuccess(tactic *httpsDialerTactic)
OnTLSHandshakeError(ctx context.Context, tactic *httpsDialerTactic, err error)
OnTLSVerifyError(tactic *httpsDialerTactic, err error)
OnSuccess(tactic *httpsDialerTactic)
Expand Down Expand Up @@ -259,9 +260,6 @@ func httpsFilterTactics(input <-chan *httpsDialerTactic) <-chan *httpsDialerTact
tx.InitialDelay = happyEyeballsDelay(index)
index++

// TODO(bassosimone): here we should also avoid connecting
// to TCP endpoints that are unreachable

// emit the tactic
output <- tx
}
Expand Down Expand Up @@ -344,6 +342,12 @@ func (hd *httpsDialer) dialTLS(
return nil, err
}

// track successful TCP connections such that we have stats
// regarding which endpoints work as intended: if we can't dial
// a specific TCP endpoint a couple of times, it doesn't make
// sense to continue trying with different SNIs.
hd.stats.OnTCPConnectSuccess(tactic)

// create TLS configuration
tlsConfig := &tls.Config{
InsecureSkipVerify: true, // Note: we're going to verify at the end of the func!
Expand Down
10 changes: 10 additions & 0 deletions internal/enginenetx/statsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func (*nullStatsManager) OnTCPConnectError(ctx context.Context, tactic *httpsDia
// nothing
}

// OnTCPConnectSuccess implements httpsDialerEventsHandler.
func (*nullStatsManager) OnTCPConnectSuccess(tactic *httpsDialerTactic) {
// nothing
}

// OnTLSHandshakeError implements httpsDialerEventsHandler.
func (*nullStatsManager) OnTLSHandshakeError(ctx context.Context, tactic *httpsDialerTactic, err error) {
// nothing
Expand Down Expand Up @@ -524,6 +529,11 @@ func (mt *statsManager) OnTCPConnectError(ctx context.Context, tactic *httpsDial
statsSafeIncrementMapStringInt64(&record.HistoTCPConnectError, err.Error())
}

// OnTCPConnectSuccess implements httpsDialerEventsHandler.
func (mt *statsManager) OnTCPConnectSuccess(tactic *httpsDialerTactic) {
// TODO(bassosimone): implement this method
}

// OnTLSHandshakeError implements httpsDialerEventsHandler.
func (mt *statsManager) OnTLSHandshakeError(ctx context.Context, tactic *httpsDialerTactic, err error) {
// get exclusive access
Expand Down

0 comments on commit 3207255

Please sign in to comment.