Skip to content

Commit 69d8734

Browse files
authored
[client] Debug information for connection (#4439)
Improve logging Print the exact time when the first WireGuard handshake occurs Print the steps for gathering system information
1 parent 5113c70 commit 69d8734

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

client/iface/configurer/usp.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ func toLastHandshake(stringVar string) (time.Time, error) {
394394
if err != nil {
395395
return time.Time{}, fmt.Errorf("parse handshake sec: %w", err)
396396
}
397+
398+
// If sec is 0 (Unix epoch), return zero time instead
399+
// This indicates no handshake has occurred
400+
if sec == 0 {
401+
return time.Time{}, nil
402+
}
403+
397404
return time.Unix(sec, 0), nil
398405
}
399406

client/internal/engine.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,6 @@ func (e *Engine) receiveManagementEvents() {
949949
e.config.LazyConnectionEnabled,
950950
)
951951

952-
// err = e.mgmClient.Sync(info, e.handleSync)
953952
err = e.mgmClient.Sync(e.ctx, info, e.handleSync)
954953
if err != nil {
955954
// happens if management is unavailable for a long time.
@@ -960,7 +959,7 @@ func (e *Engine) receiveManagementEvents() {
960959
}
961960
log.Debugf("stopped receiving updates from Management Service")
962961
}()
963-
log.Debugf("connecting to Management Service updates stream")
962+
log.Infof("connecting to Management Service updates stream")
964963
}
965964

966965
func (e *Engine) updateSTUNs(stuns []*mgmProto.HostConfig) error {

client/internal/peer/wg_watcher.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ type WGWatcher struct {
3030
peerKey string
3131
stateDump *stateDump
3232

33-
ctx context.Context
34-
ctxCancel context.CancelFunc
35-
ctxLock sync.Mutex
33+
ctx context.Context
34+
ctxCancel context.CancelFunc
35+
ctxLock sync.Mutex
36+
enabledTime time.Time
3637
}
3738

3839
func NewWGWatcher(log *log.Entry, wgIfaceStater WGInterfaceStater, peerKey string, stateDump *stateDump) *WGWatcher {
@@ -48,6 +49,7 @@ func NewWGWatcher(log *log.Entry, wgIfaceStater WGInterfaceStater, peerKey strin
4849
func (w *WGWatcher) EnableWgWatcher(parentCtx context.Context, onDisconnectedFn func()) {
4950
w.log.Debugf("enable WireGuard watcher")
5051
w.ctxLock.Lock()
52+
w.enabledTime = time.Now()
5153

5254
if w.ctx != nil && w.ctx.Err() == nil {
5355
w.log.Errorf("WireGuard watcher already enabled")
@@ -101,6 +103,11 @@ func (w *WGWatcher) periodicHandshakeCheck(ctx context.Context, ctxCancel contex
101103
onDisconnectedFn()
102104
return
103105
}
106+
if lastHandshake.IsZero() {
107+
elapsed := handshake.Sub(w.enabledTime).Seconds()
108+
w.log.Infof("first wg handshake detected within: %.2fsec, (%s)", elapsed, handshake)
109+
}
110+
104111
lastHandshake = *handshake
105112

106113
resetTime := time.Until(handshake.Add(checkPeriod))

client/system/info.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/netip"
77
"strings"
88

9+
log "github.com/sirupsen/logrus"
910
"google.golang.org/grpc/metadata"
1011

1112
"github.com/netbirdio/netbird/shared/management/proto"
@@ -172,6 +173,7 @@ func isDuplicated(addresses []NetworkAddress, addr NetworkAddress) bool {
172173

173174
// GetInfoWithChecks retrieves and parses the system information with applied checks.
174175
func GetInfoWithChecks(ctx context.Context, checks []*proto.Checks) (*Info, error) {
176+
log.Debugf("gathering system information with checks: %d", len(checks))
175177
processCheckPaths := make([]string, 0)
176178
for _, check := range checks {
177179
processCheckPaths = append(processCheckPaths, check.GetFiles()...)
@@ -181,9 +183,11 @@ func GetInfoWithChecks(ctx context.Context, checks []*proto.Checks) (*Info, erro
181183
if err != nil {
182184
return nil, err
183185
}
186+
log.Debugf("gathering process check information completed")
184187

185188
info := GetInfo(ctx)
186189
info.Files = files
187190

191+
log.Debugf("all system information gathered successfully")
188192
return info, nil
189193
}

client/system/info_windows.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@ func GetInfo(ctx context.Context) *Info {
4848
gio.Hostname = extractDeviceName(ctx, systemHostname)
4949
gio.NetbirdVersion = version.NetbirdVersion()
5050
gio.UIVersion = extractUserAgent(ctx)
51-
5251
return gio
5352
}

0 commit comments

Comments
 (0)