mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 03:31:39 +00:00
control/controlclient: use structured logging for MapResponse.ControlTime
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
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() {
|
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 {
|
if resp.KeepAlive {
|
||||||
vlogf("netmap: got keep-alive")
|
vlogf("netmap: got keep-alive")
|
||||||
|
@ -213,6 +213,7 @@ type LogCatcher struct {
|
|||||||
buf bytes.Buffer
|
buf bytes.Buffer
|
||||||
gotErr error
|
gotErr error
|
||||||
reqs int
|
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
|
// UseLogf makes the logcatcher implementation use a given logf function
|
||||||
@ -223,6 +224,13 @@ func (lc *LogCatcher) UseLogf(fn logger.Logf) {
|
|||||||
lc.logf = fn
|
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 {
|
func (lc *LogCatcher) logsContains(sub mem.RO) bool {
|
||||||
lc.mu.Lock()
|
lc.mu.Lock()
|
||||||
defer lc.mu.Unlock()
|
defer lc.mu.Unlock()
|
||||||
@ -315,6 +323,10 @@ func (lc *LogCatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
id := privID.Public().String()[:3] // good enough for integration tests
|
id := privID.Public().String()[:3] // good enough for integration tests
|
||||||
for _, ent := range jreq {
|
for _, ent := range jreq {
|
||||||
|
if lc.raw {
|
||||||
|
lc.buf.Write(bodyBytes)
|
||||||
|
continue
|
||||||
|
}
|
||||||
fmt.Fprintf(&lc.buf, "%s\n", strings.TrimSpace(ent.Text))
|
fmt.Fprintf(&lc.buf, "%s\n", strings.TrimSpace(ent.Text))
|
||||||
if lc.logf != nil {
|
if lc.logf != nil {
|
||||||
lc.logf("logcatch:%s: %s", id, strings.TrimSpace(ent.Text))
|
lc.logf("logcatch:%s: %s", id, strings.TrimSpace(ent.Text))
|
||||||
|
@ -149,6 +149,7 @@ func TestCollectPanic(t *testing.T) {
|
|||||||
func TestControlTimeLogLine(t *testing.T) {
|
func TestControlTimeLogLine(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
env := newTestEnv(t)
|
env := newTestEnv(t)
|
||||||
|
env.LogCatcher.StoreRawJSON()
|
||||||
n := newTestNode(t, env)
|
n := newTestNode(t, env)
|
||||||
|
|
||||||
n.StartDaemon()
|
n.StartDaemon()
|
||||||
@ -157,7 +158,7 @@ func TestControlTimeLogLine(t *testing.T) {
|
|||||||
n.AwaitRunning()
|
n.AwaitRunning()
|
||||||
|
|
||||||
if err := tstest.WaitFor(20*time.Second, func() error {
|
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)) {
|
if !n.env.LogCatcher.logsContains(mem.S(sub)) {
|
||||||
return fmt.Errorf("log catcher didn't see %#q; got %s", sub, n.env.LogCatcher.logsString())
|
return fmt.Errorf("log catcher didn't see %#q; got %s", sub, n.env.LogCatcher.logsString())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user