mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 00:31:17 -08:00
Control via nodecap.LogUploadAuth may notify the node that there is an authorization token to use when uploading logs. If specified, then the logtail.Logger will use that token when uploading. Unfortunately, there is a time-of-use and time-of-check discrepancy that complicates logging. When logs are written under the context of being for a particular node, we cannot store the token, as it may be invalid by the time that the logs are uploaded. Instead, we add Logger.SetAuthID to annotate subsequent log entries with an identifier for the token to later use. Only when we upload do we strip out the auth ID, lookup the auth token to use, and then perform the upload. We assume that control will notify the client of new tokens well before they expire. Fetching a refreshed token is not the job of the client. Updates tailscale/corp#39092 Signed-off-by: Joe Tsai <[email protected]>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build ts_omit_logtail
|
|
|
|
package logtail
|
|
|
|
import (
|
|
"context"
|
|
"iter"
|
|
"time"
|
|
|
|
tslogger "tailscale.com/types/logger"
|
|
"tailscale.com/types/logid"
|
|
)
|
|
|
|
// Noop implementations of everything when ts_omit_logtail is set.
|
|
|
|
type Logger struct{}
|
|
|
|
type Buffer any
|
|
|
|
type Logtail struct {
|
|
ClientTime time.Time `json:"client_time,omitzero"`
|
|
ProcID uint32 `json:"proc_id,omitzero"`
|
|
ProcSeq uint64 `json:"proc_seq,omitzero"`
|
|
AuthID string `json:"auth_id,omitzero"`
|
|
}
|
|
|
|
type LogEntry[T any] struct {
|
|
Logtail Logtail `json:"logtail,omitzero"`
|
|
Value T `json:",inline,embed"` // both options; see the non-omit variant in logtail.go
|
|
}
|
|
|
|
func UploadLogs[T any](ctx context.Context, conf Config, entries iter.Seq[LogEntry[T]]) error {
|
|
return nil
|
|
}
|
|
|
|
func Disable() {}
|
|
|
|
func (*Logger) SetEnabled(enabled bool) {}
|
|
|
|
func NewLogger(cfg Config, logf tslogger.Logf) *Logger {
|
|
return &Logger{}
|
|
}
|
|
|
|
func (*Logger) Write(p []byte) (n int, err error) {
|
|
return len(p), nil
|
|
}
|
|
|
|
func (*Logger) Logf(format string, args ...any) {}
|
|
func (*Logger) Shutdown(ctx context.Context) error { return nil }
|
|
func (*Logger) SetVerbosityLevel(level int) {}
|
|
|
|
func (l *Logger) SetSockstatsLabel(label any) {}
|
|
|
|
func (l *Logger) PrivateID() logid.PrivateID { return logid.PrivateID{} }
|
|
func (l *Logger) StartFlush() {}
|
|
|
|
func (*Logger) SetAuthID(id string) {}
|
|
func (*Logger) RegisterAuthToken(authID string, authToken func() string) {}
|
|
|
|
func RegisterLogTap(dst chan<- string) (unregister func()) {
|
|
return func() {}
|
|
}
|
|
|
|
func (*Logger) SetNetMon(any) {}
|