mirror of
https://github.com/tailscale/tailscale.git
synced 2025-11-16 19:07:42 +00:00
ipn/ipnlocal: add verbose Taildrive logging on client side
This allows logging the following Taildrive behavior from the client's perspective when --verbose=1: - Initialization of Taildrive remotes for every peer - Peer availability checks - All HTTP requests to peers (not just GET and PUT) Updates tailscale/corp#29702 Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:
committed by
Percy Wegmann
parent
47e77565c6
commit
6a9bf9172b
@@ -306,10 +306,12 @@ func (b *LocalBackend) updateDrivePeersLocked(nm *netmap.NetworkMap) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *LocalBackend) driveRemotesFromPeers(nm *netmap.NetworkMap) []*drive.Remote {
|
func (b *LocalBackend) driveRemotesFromPeers(nm *netmap.NetworkMap) []*drive.Remote {
|
||||||
|
b.logf("[v1] taildrive: setting up drive remotes from peers")
|
||||||
driveRemotes := make([]*drive.Remote, 0, len(nm.Peers))
|
driveRemotes := make([]*drive.Remote, 0, len(nm.Peers))
|
||||||
for _, p := range nm.Peers {
|
for _, p := range nm.Peers {
|
||||||
peerID := p.ID()
|
peerID := p.ID()
|
||||||
url := fmt.Sprintf("%s/%s", peerAPIBase(nm, p), taildrivePrefix[1:])
|
url := fmt.Sprintf("%s/%s", peerAPIBase(nm, p), taildrivePrefix[1:])
|
||||||
|
b.logf("[v1] taildrive: appending remote for peer %d: %s", peerID, url)
|
||||||
driveRemotes = append(driveRemotes, &drive.Remote{
|
driveRemotes = append(driveRemotes, &drive.Remote{
|
||||||
Name: p.DisplayName(false),
|
Name: p.DisplayName(false),
|
||||||
URL: url,
|
URL: url,
|
||||||
@@ -320,6 +322,7 @@ func (b *LocalBackend) driveRemotesFromPeers(nm *netmap.NetworkMap) []*drive.Rem
|
|||||||
cn := b.currentNode()
|
cn := b.currentNode()
|
||||||
peer, ok := cn.NodeByID(peerID)
|
peer, ok := cn.NodeByID(peerID)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
b.logf("[v1] taildrive: Available(): peer %d not found", peerID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,14 +335,17 @@ func (b *LocalBackend) driveRemotesFromPeers(nm *netmap.NetworkMap) []*drive.Rem
|
|||||||
// The netmap.Peers slice is not updated in all cases.
|
// The netmap.Peers slice is not updated in all cases.
|
||||||
// It should be fixed now that we use PeerByIDOk.
|
// It should be fixed now that we use PeerByIDOk.
|
||||||
if !peer.Online().Get() {
|
if !peer.Online().Get() {
|
||||||
|
b.logf("[v1] taildrive: Available(): peer %d offline", peerID)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the peer is allowed to share with us.
|
// Check that the peer is allowed to share with us.
|
||||||
if cn.PeerHasCap(peer, tailcfg.PeerCapabilityTaildriveSharer) {
|
if cn.PeerHasCap(peer, tailcfg.PeerCapabilityTaildriveSharer) {
|
||||||
|
b.logf("[v1] taildrive: Available(): peer %d available", peerID)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.logf("[v1] taildrive: Available(): peer %d not allowed to share", peerID)
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1459,7 +1459,7 @@ func (b *LocalBackend) WhoIs(proto string, ipp netip.AddrPort) (n tailcfg.NodeVi
|
|||||||
}
|
}
|
||||||
n, ok = cn.NodeByID(nid)
|
n, ok = cn.NodeByID(nid)
|
||||||
if !ok {
|
if !ok {
|
||||||
return zero, u, false
|
return zero, u, false
|
||||||
}
|
}
|
||||||
up, ok := cn.UserByID(n.User())
|
up, ok := cn.UserByID(n.User())
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -5960,6 +5960,7 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
|
|||||||
// the number of bytesRead.
|
// the number of bytesRead.
|
||||||
type responseBodyWrapper struct {
|
type responseBodyWrapper struct {
|
||||||
io.ReadCloser
|
io.ReadCloser
|
||||||
|
logVerbose bool
|
||||||
bytesRx int64
|
bytesRx int64
|
||||||
bytesTx int64
|
bytesTx int64
|
||||||
log logger.Logf
|
log logger.Logf
|
||||||
@@ -5981,8 +5982,22 @@ func (rbw *responseBodyWrapper) logAccess(err string) {
|
|||||||
|
|
||||||
// Some operating systems create and copy lots of 0 length hidden files for
|
// Some operating systems create and copy lots of 0 length hidden files for
|
||||||
// tracking various states. Omit these to keep logs from being too verbose.
|
// tracking various states. Omit these to keep logs from being too verbose.
|
||||||
if rbw.contentLength > 0 {
|
if rbw.logVerbose || rbw.contentLength > 0 {
|
||||||
rbw.log("taildrive: access: %s from %s to %s: status-code=%d ext=%q content-type=%q content-length=%.f tx=%.f rx=%.f err=%q", rbw.method, rbw.selfNodeKey, rbw.shareNodeKey, rbw.statusCode, rbw.fileExtension, rbw.contentType, roundTraffic(rbw.contentLength), roundTraffic(rbw.bytesTx), roundTraffic(rbw.bytesRx), err)
|
levelPrefix := ""
|
||||||
|
if rbw.logVerbose {
|
||||||
|
levelPrefix = "[v1] "
|
||||||
|
}
|
||||||
|
rbw.log(
|
||||||
|
"%staildrive: access: %s from %s to %s: status-code=%d ext=%q content-type=%q content-length=%.f tx=%.f rx=%.f err=%q",
|
||||||
|
levelPrefix,
|
||||||
|
rbw.method,
|
||||||
|
rbw.selfNodeKey,
|
||||||
|
rbw.shareNodeKey,
|
||||||
|
rbw.statusCode,
|
||||||
|
rbw.fileExtension,
|
||||||
|
rbw.contentType,
|
||||||
|
roundTraffic(rbw.contentLength),
|
||||||
|
roundTraffic(rbw.bytesTx), roundTraffic(rbw.bytesRx), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6037,17 +6052,8 @@ func (dt *driveTransport) RoundTrip(req *http.Request) (resp *http.Response, err
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
contentType := "unknown"
|
contentType := "unknown"
|
||||||
switch req.Method {
|
if ct := req.Header.Get("Content-Type"); ct != "" {
|
||||||
case httpm.PUT:
|
contentType = ct
|
||||||
if ct := req.Header.Get("Content-Type"); ct != "" {
|
|
||||||
contentType = ct
|
|
||||||
}
|
|
||||||
case httpm.GET:
|
|
||||||
if ct := resp.Header.Get("Content-Type"); ct != "" {
|
|
||||||
contentType = ct
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dt.b.mu.Lock()
|
dt.b.mu.Lock()
|
||||||
@@ -6061,6 +6067,7 @@ func (dt *driveTransport) RoundTrip(req *http.Request) (resp *http.Response, err
|
|||||||
|
|
||||||
rbw := responseBodyWrapper{
|
rbw := responseBodyWrapper{
|
||||||
log: dt.b.logf,
|
log: dt.b.logf,
|
||||||
|
logVerbose: req.Method != httpm.GET && req.Method != httpm.PUT, // other requests like PROPFIND are quite chatty, so we log those at verbose level
|
||||||
method: req.Method,
|
method: req.Method,
|
||||||
bytesTx: int64(bw.bytesRead),
|
bytesTx: int64(bw.bytesRead),
|
||||||
selfNodeKey: selfNodeKey,
|
selfNodeKey: selfNodeKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user