chore(vpn): send info, debug logs over tunnel (#18240)

Closes https://github.com/coder/internal/issues/397
This commit is contained in:
Ethan
2025-06-06 14:31:27 +10:00
committed by GitHub
parent 0076e8479f
commit 628b81c334
3 changed files with 16 additions and 22 deletions
-1
View File
@@ -65,7 +65,6 @@ func (r *RootCmd) vpnDaemonRun() *serpent.Command {
logger.Info(ctx, "starting tunnel")
tunnel, err := vpn.NewTunnel(ctx, logger, pipe, vpn.NewClient(),
vpn.UseOSNetworkingStack(),
vpn.UseAsLogger(),
vpn.UseCustomLogSinks(sinks...),
)
if err != nil {
+4 -1
View File
@@ -46,7 +46,10 @@ func OpenTunnel(cReadFD, cWriteFD int32) int32 {
return ErrOpenPipe
}
_, err = vpn.NewTunnel(ctx, slog.Make(), conn, vpn.NewClient(),
// We log everything, as filtering is done by whatever renders the OS
// logs.
_, err = vpn.NewTunnel(ctx, slog.Make().Leveled(slog.LevelDebug), conn,
vpn.NewClient(),
vpn.UseOSNetworkingStack(),
vpn.UseAsLogger(),
)
+12 -20
View File
@@ -46,9 +46,6 @@ type Tunnel struct {
logger slog.Logger
logMu sync.Mutex
logs []*TunnelMessage
client Client
// clientLogger is a separate logger than `logger` when the `UseAsLogger`
@@ -300,29 +297,22 @@ func (t *Tunnel) stop(*StopRequest) error {
var _ slog.Sink = &Tunnel{}
func (t *Tunnel) LogEntry(_ context.Context, e slog.SinkEntry) {
t.logMu.Lock()
defer t.logMu.Unlock()
t.logs = append(t.logs, &TunnelMessage{
msg := &TunnelMessage{
Msg: &TunnelMessage_Log{
Log: sinkEntryToPb(e),
},
})
}
func (t *Tunnel) Sync() {
t.logMu.Lock()
logs := t.logs
t.logs = nil
t.logMu.Unlock()
for _, msg := range logs {
select {
case <-t.ctx.Done():
return
case t.sendCh <- msg:
}
}
select {
case <-t.updater.ctx.Done():
return
case <-t.ctx.Done():
return
case t.sendCh <- msg:
}
}
func (*Tunnel) Sync() {}
func sinkEntryToPb(e slog.SinkEntry) *Log {
l := &Log{
// #nosec G115 - Safe conversion for log levels which are small positive integers
@@ -583,6 +573,8 @@ func (u *updater) sendAgentUpdate() {
return
}
u.logger.Debug(u.ctx, "sending agent update")
msg := &TunnelMessage{
Msg: &TunnelMessage_PeerUpdate{
PeerUpdate: &PeerUpdate{