control/controlclient: use structured logging for MapResponse.ControlTime

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
pull/3978/head
Josh Bleecher Snyder 3 years ago committed by Josh Bleecher Snyder
parent 84138450a4
commit 823d970d60

@ -773,7 +773,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm
}
if resp.ControlTime != nil && !resp.ControlTime.IsZero() {
c.logf("netmap: control time is %v", resp.ControlTime.UTC().Format(time.RFC3339Nano))
c.logf.JSON(1, "controltime", resp.ControlTime.UTC())
}
if resp.KeepAlive {
vlogf("netmap: got keep-alive")

@ -213,6 +213,7 @@ type LogCatcher struct {
buf bytes.Buffer
gotErr error
reqs int
raw bool // indicates whether to store the raw JSON logs uploaded, instead of just the text
}
// UseLogf makes the logcatcher implementation use a given logf function
@ -223,6 +224,13 @@ func (lc *LogCatcher) UseLogf(fn logger.Logf) {
lc.logf = fn
}
// StoreRawJSON instructs lc to save the raw JSON uploads, rather than just the text.
func (lc *LogCatcher) StoreRawJSON() {
lc.mu.Lock()
defer lc.mu.Unlock()
lc.raw = true
}
func (lc *LogCatcher) logsContains(sub mem.RO) bool {
lc.mu.Lock()
defer lc.mu.Unlock()
@ -315,6 +323,10 @@ func (lc *LogCatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else {
id := privID.Public().String()[:3] // good enough for integration tests
for _, ent := range jreq {
if lc.raw {
lc.buf.Write(bodyBytes)
continue
}
fmt.Fprintf(&lc.buf, "%s\n", strings.TrimSpace(ent.Text))
if lc.logf != nil {
lc.logf("logcatch:%s: %s", id, strings.TrimSpace(ent.Text))

@ -149,6 +149,7 @@ func TestCollectPanic(t *testing.T) {
func TestControlTimeLogLine(t *testing.T) {
t.Parallel()
env := newTestEnv(t)
env.LogCatcher.StoreRawJSON()
n := newTestNode(t, env)
n.StartDaemon()
@ -157,7 +158,7 @@ func TestControlTimeLogLine(t *testing.T) {
n.AwaitRunning()
if err := tstest.WaitFor(20*time.Second, func() error {
const sub = `netmap: control time is 2020-08-03T00:00:00.000000001Z`
const sub = `"controltime":"2020-08-03T00:00:00.000000001Z"`
if !n.env.LogCatcher.logsContains(mem.S(sub)) {
return fmt.Errorf("log catcher didn't see %#q; got %s", sub, n.env.LogCatcher.logsString())
}

Loading…
Cancel
Save