Added Noise field to logging

This commit is contained in:
Juan Font Alonso 2022-08-14 23:11:33 +02:00
parent df8ecdb603
commit 7cc227d01e

View File

@ -36,6 +36,7 @@ func (h *Headscale) handlePollCommon(
if err != nil { if err != nil {
log.Error(). log.Error().
Caller(). Caller().
Bool("noise", isNoise).
Str("func", "handleAuthKey"). Str("func", "handleAuthKey").
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Err(err) Err(err)
@ -58,6 +59,7 @@ func (h *Headscale) handlePollCommon(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("node_key", machine.NodeKey). Str("node_key", machine.NodeKey).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Err(err). Err(err).
@ -72,6 +74,7 @@ func (h *Headscale) handlePollCommon(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("node_key", machine.NodeKey). Str("node_key", machine.NodeKey).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Err(err). Err(err).
@ -88,6 +91,7 @@ func (h *Headscale) handlePollCommon(
// 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").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Bool("readOnly", mapRequest.ReadOnly). Bool("readOnly", mapRequest.ReadOnly).
Bool("omitPeers", mapRequest.OmitPeers). Bool("omitPeers", mapRequest.OmitPeers).
@ -97,6 +101,7 @@ func (h *Headscale) handlePollCommon(
if mapRequest.ReadOnly { if mapRequest.ReadOnly {
log.Info(). log.Info().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Client is starting up. Probably interested in a DERP map") Msg("Client is starting up. Probably interested in a DERP map")
@ -127,6 +132,7 @@ func (h *Headscale) handlePollCommon(
// Only create update channel if it has not been created // Only create update channel if it has not been created
log.Trace(). log.Trace().
Caller(). Caller().
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Loading or creating update channel") Msg("Loading or creating update channel")
@ -141,6 +147,7 @@ func (h *Headscale) handlePollCommon(
if mapRequest.OmitPeers && !mapRequest.Stream { if mapRequest.OmitPeers && !mapRequest.Stream {
log.Info(). log.Info().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Client sent endpoint update and is ok with a response without peer list") Msg("Client sent endpoint update and is ok with a response without peer list")
writer.Header().Set("Content-Type", "application/json; charset=utf-8") writer.Header().Set("Content-Type", "application/json; charset=utf-8")
@ -162,6 +169,7 @@ func (h *Headscale) handlePollCommon(
} else if mapRequest.OmitPeers && mapRequest.Stream { } else if mapRequest.OmitPeers && mapRequest.Stream {
log.Warn(). log.Warn().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Ignoring request, don't know how to handle it") Msg("Ignoring request, don't know how to handle it")
http.Error(writer, "", http.StatusBadRequest) http.Error(writer, "", http.StatusBadRequest)
@ -171,16 +179,19 @@ func (h *Headscale) handlePollCommon(
log.Info(). log.Info().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Client is ready to access the tailnet") Msg("Client is ready to access the tailnet")
log.Info(). log.Info().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Sending initial map") Msg("Sending initial map")
pollDataChan <- mapResp pollDataChan <- mapResp
log.Info(). log.Info().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Notifying peers") Msg("Notifying peers")
updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "full-update"). updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "full-update").
@ -200,6 +211,7 @@ func (h *Headscale) handlePollCommon(
log.Trace(). log.Trace().
Str("handler", "PollNetMap"). Str("handler", "PollNetMap").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Finished stream, closing PollNetMap session") Msg("Finished stream, closing PollNetMap session")
} }
@ -235,11 +247,13 @@ func (h *Headscale) pollNetMapStream(
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("Waiting for data to stream...") Msg("Waiting for data to stream...")
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msgf("pollData is %#v, keepAliveChan is %#v, updateChan is %#v", pollDataChan, keepAliveChan, updateChan) Msgf("pollData is %#v, keepAliveChan is %#v, updateChan is %#v", pollDataChan, keepAliveChan, updateChan)
@ -248,6 +262,7 @@ func (h *Headscale) pollNetMapStream(
case data := <-pollDataChan: case data := <-pollDataChan:
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "pollData"). Str("channel", "pollData").
Int("bytes", len(data)). Int("bytes", len(data)).
@ -256,6 +271,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "pollData"). Str("channel", "pollData").
Err(err). Err(err).
@ -269,6 +285,7 @@ func (h *Headscale) pollNetMapStream(
log.Error(). log.Error().
Caller(). Caller().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "pollData"). Str("channel", "pollData").
Msg("Cannot cast writer to http.Flusher") Msg("Cannot cast writer to http.Flusher")
@ -278,6 +295,7 @@ func (h *Headscale) pollNetMapStream(
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "pollData"). Str("channel", "pollData").
Int("bytes", len(data)). Int("bytes", len(data)).
@ -289,6 +307,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "pollData"). Str("channel", "pollData").
Err(err). Err(err).
@ -309,6 +328,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "pollData"). Str("channel", "pollData").
Err(err). Err(err).
@ -319,6 +339,7 @@ func (h *Headscale) pollNetMapStream(
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "pollData"). Str("channel", "pollData").
Int("bytes", len(data)). Int("bytes", len(data)).
@ -335,6 +356,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Err(err). Err(err).
@ -347,6 +369,7 @@ func (h *Headscale) pollNetMapStream(
log.Error(). log.Error().
Caller(). Caller().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Msg("Cannot cast writer to http.Flusher") Msg("Cannot cast writer to http.Flusher")
@ -356,6 +379,7 @@ func (h *Headscale) pollNetMapStream(
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Int("bytes", len(data)). Int("bytes", len(data)).
@ -367,6 +391,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Err(err). Err(err).
@ -382,6 +407,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Err(err). Err(err).
@ -392,6 +418,7 @@ func (h *Headscale) pollNetMapStream(
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "keepAlive"). Str("channel", "keepAlive").
Int("bytes", len(data)). Int("bytes", len(data)).
@ -400,6 +427,7 @@ func (h *Headscale) pollNetMapStream(
case <-updateChan: case <-updateChan:
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "update"). Str("channel", "update").
Msg("Received a request for update") Msg("Received a request for update")
@ -413,6 +441,7 @@ func (h *Headscale) pollNetMapStream(
} }
log.Debug(). log.Debug().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Time("last_successful_update", lastUpdate). Time("last_successful_update", lastUpdate).
Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)). Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)).
@ -421,6 +450,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "update"). Str("channel", "update").
Err(err). Err(err).
@ -432,6 +462,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "update"). Str("channel", "update").
Err(err). Err(err).
@ -447,6 +478,7 @@ func (h *Headscale) pollNetMapStream(
log.Error(). log.Error().
Caller(). Caller().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "update"). Str("channel", "update").
Msg("Cannot cast writer to http.Flusher") Msg("Cannot cast writer to http.Flusher")
@ -456,6 +488,7 @@ func (h *Headscale) pollNetMapStream(
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "update"). Str("channel", "update").
Msg("Updated Map has been sent") Msg("Updated Map has been sent")
@ -473,6 +506,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "update"). Str("channel", "update").
Err(err). Err(err).
@ -492,6 +526,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "update"). Str("channel", "update").
Err(err). Err(err).
@ -506,6 +541,7 @@ func (h *Headscale) pollNetMapStream(
} }
log.Trace(). log.Trace().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Time("last_successful_update", lastUpdate). Time("last_successful_update", lastUpdate).
Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)). Time("last_state_change", h.getLastStateChange(machine.Namespace.Name)).
@ -524,6 +560,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "Done"). Str("channel", "Done").
Err(err). Err(err).
@ -539,6 +576,7 @@ func (h *Headscale) pollNetMapStream(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Str("channel", "Done"). Str("channel", "Done").
Err(err). Err(err).
@ -551,6 +589,7 @@ func (h *Headscale) pollNetMapStream(
case <-h.shutdownChan: case <-h.shutdownChan:
log.Info(). log.Info().
Str("handler", "PollNetMapStream"). Str("handler", "PollNetMapStream").
Bool("noise", isNoise).
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Msg("The long-poll handler is shutting down") Msg("The long-poll handler is shutting down")
@ -591,6 +630,7 @@ func (h *Headscale) scheduledPollWorker(
if err != nil { if err != nil {
log.Error(). log.Error().
Str("func", "keepAlive"). Str("func", "keepAlive").
Bool("noise", isNoise).
Err(err). Err(err).
Msg("Error generating the keep alive msg") Msg("Error generating the keep alive msg")
@ -600,6 +640,7 @@ func (h *Headscale) scheduledPollWorker(
log.Debug(). log.Debug().
Str("func", "keepAlive"). Str("func", "keepAlive").
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Bool("noise", isNoise).
Msg("Sending keepalive") Msg("Sending keepalive")
keepAliveChan <- data keepAliveChan <- data
@ -607,6 +648,7 @@ func (h *Headscale) scheduledPollWorker(
log.Debug(). log.Debug().
Str("func", "scheduledPollWorker"). Str("func", "scheduledPollWorker").
Str("machine", machine.Hostname). Str("machine", machine.Hostname).
Bool("noise", isNoise).
Msg("Sending update request") Msg("Sending update request")
updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "scheduled-update"). updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Hostname, "scheduled-update").
Inc() Inc()