Add more trace logging

This commit is contained in:
Kristoffer Dalby
2021-08-05 21:47:06 +01:00
parent a8c8a358d0
commit 575b15e5fa

40
api.go
View File

@@ -225,6 +225,10 @@ func (h *Headscale) RegistrationHandler(c *gin.Context) {
// //
// At this moment the updates are sent in a quite horrendous way, but they kinda work. // At this moment the updates are sent in a quite horrendous way, but they kinda work.
func (h *Headscale) PollNetMapHandler(c *gin.Context) { func (h *Headscale) PollNetMapHandler(c *gin.Context) {
log.Trace().
Str("handler", "PollNetMap").
Str("id", c.Param("id")).
Msg("PollNetMapHandler called")
body, _ := io.ReadAll(c.Request.Body) body, _ := io.ReadAll(c.Request.Body)
mKeyStr := c.Param("id") mKeyStr := c.Param("id")
mKey, err := wgkey.ParseHex(mKeyStr) mKey, err := wgkey.ParseHex(mKeyStr)
@@ -255,6 +259,11 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
c.String(http.StatusUnauthorized, "") c.String(http.StatusUnauthorized, "")
return return
} }
log.Trace().
Str("handler", "PollNetMap").
Str("id", c.Param("id")).
Str("machine", m.Name).
Msg("Found machine in database")
hostinfo, _ := json.Marshal(req.Hostinfo) hostinfo, _ := json.Marshal(req.Hostinfo)
m.Name = req.Hostinfo.Hostname m.Name = req.Hostinfo.Hostname
@@ -277,17 +286,36 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
} }
h.db.Save(&m) h.db.Save(&m)
pollData := make(chan []byte, 1)
update := make(chan []byte, 1) update := make(chan []byte, 1)
cancelKeepAlive := make(chan []byte, 1)
pollData := make(chan []byte, 1)
defer close(pollData) defer close(pollData)
cancelKeepAlive := make(chan []byte, 1)
defer close(cancelKeepAlive) defer close(cancelKeepAlive)
log.Trace().
Str("handler", "PollNetMap").
Str("id", c.Param("id")).
Str("machine", m.Name).
Msg("Locking poll mutex")
h.pollMu.Lock() h.pollMu.Lock()
h.clientsPolling[m.ID] = update h.clientsPolling[m.ID] = update
h.pollMu.Unlock() h.pollMu.Unlock()
log.Trace().
Str("handler", "PollNetMap").
Str("id", c.Param("id")).
Str("machine", m.Name).
Msg("Unlocking poll mutex")
data, err := h.getMapResponse(mKey, req, m) data, err := h.getMapResponse(mKey, req, m)
if err != nil { if err != nil {
log.Error().
Str("handler", "PollNetMap").
Str("id", c.Param("id")).
Str("machine", m.Name).
Err(err).
Msg("Failed to get Map response")
c.String(http.StatusInternalServerError, ":(") c.String(http.StatusInternalServerError, ":(")
return return
} }
@@ -299,10 +327,12 @@ func (h *Headscale) PollNetMapHandler(c *gin.Context) {
// Details on the protocol can be found in https://github.com/tailscale/tailscale/blob/main/tailcfg/tailcfg.go#L696 // Details on the protocol can be found in https://github.com/tailscale/tailscale/blob/main/tailcfg/tailcfg.go#L696
log.Debug(). log.Debug().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Str("id", c.Param("id")).
Str("machine", m.Name). Str("machine", m.Name).
Bool("readOnly", req.ReadOnly). Bool("readOnly", req.ReadOnly).
Bool("omitPeers", req.OmitPeers). Bool("omitPeers", req.OmitPeers).
Bool("stream", req.Stream) Bool("stream", req.Stream).
Msg("Client map request processed")
if req.ReadOnly { if req.ReadOnly {
log.Info(). log.Info().
@@ -457,6 +487,10 @@ func (h *Headscale) keepAlive(cancel chan []byte, pollData chan []byte, mKey wgk
} }
func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Machine) (*[]byte, error) { func (h *Headscale) getMapResponse(mKey wgkey.Key, req tailcfg.MapRequest, m Machine) (*[]byte, error) {
log.Trace().
Str("func", "getMapResponse").
Str("machine", req.Hostinfo.Hostname).
Msg("Creating Map response")
node, err := m.toNode() node, err := m.toNode()
if err != nil { if err != nil {
log.Error(). log.Error().