all: replace logtail.{Public,Private}ID with logid.{Public,Private}ID (#7404)

The log ID types were moved to a separate package so that
code that only depend on log ID types do not need to link
in the logic for the logtail client itself.
Not all code need the logtail client.

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
pull/7411/head
Joe Tsai 1 year ago committed by GitHub
parent d41f6a8752
commit 0d19f5d421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,7 +43,7 @@ import (
jsonv2 "github.com/go-json-experiment/json"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"tailscale.com/logtail"
"tailscale.com/types/logid"
"tailscale.com/types/netlogtype"
"tailscale.com/util/must"
)
@ -136,8 +136,8 @@ func processObject(dec *jsonv2.Decoder) {
type message struct {
Logtail struct {
ID logtail.PublicID `json:"id"`
Logged time.Time `json:"server_time"`
ID logid.PublicID `json:"id"`
Logged time.Time `json:"server_time"`
} `json:"logtail"`
Logged time.Time `json:"logged"`
netlogtype.Message

@ -298,6 +298,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
tailscale.com/util/lineread from tailscale.com/hostinfo+
tailscale.com/util/mak from tailscale.com/control/controlclient+
tailscale.com/util/multierr from tailscale.com/control/controlclient+
tailscale.com/util/must from tailscale.com/logpolicy
tailscale.com/util/osshare from tailscale.com/ipn/ipnlocal+
W tailscale.com/util/pidowner from tailscale.com/ipn/ipnauth
tailscale.com/util/racebuild from tailscale.com/logpolicy

@ -11,11 +11,11 @@ import (
"tailscale.com/ipn"
"tailscale.com/ipn/ipnstate"
"tailscale.com/ipn/store/mem"
"tailscale.com/logtail"
"tailscale.com/tailcfg"
"tailscale.com/tstest"
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/types/logid"
"tailscale.com/types/persist"
"tailscale.com/wgengine"
)
@ -37,8 +37,8 @@ func TestLocalLogLines(t *testing.T) {
// This lets the logListen tracker verify that the rate-limiter allows these key lines.
logf := logger.RateLimitedFnWithClock(logListen.Logf, 5*time.Second, 0, 10, time.Now)
logid := func(hex byte) logtail.PublicID {
var ret logtail.PublicID
logid := func(hex byte) logid.PublicID {
var ret logid.PublicID
for i := 0; i < len(ret); i++ {
ret[i] = hex
}

@ -43,7 +43,9 @@ import (
"tailscale.com/safesocket"
"tailscale.com/smallzstd"
"tailscale.com/types/logger"
"tailscale.com/types/logid"
"tailscale.com/util/clientmetric"
"tailscale.com/util/must"
"tailscale.com/util/racebuild"
"tailscale.com/util/winutil"
"tailscale.com/version"
@ -94,8 +96,8 @@ func LogHost() string {
// Config represents an instance of logs in a collection.
type Config struct {
Collection string
PrivateID logtail.PrivateID
PublicID logtail.PublicID
PrivateID logid.PrivateID
PublicID logid.PublicID
}
// Policy is a logger and its public ID.
@ -103,15 +105,12 @@ type Policy struct {
// Logtail is the logger.
Logtail *logtail.Logger
// PublicID is the logger's instance identifier.
PublicID logtail.PublicID
PublicID logid.PublicID
}
// NewConfig creates a Config with collection and a newly generated PrivateID.
func NewConfig(collection string) *Config {
id, err := logtail.NewPrivateID()
if err != nil {
panic("logtail.NewPrivateID should never fail")
}
id := must.Get(logid.NewPrivateID())
return &Config{
Collection: collection,
PrivateID: id,

@ -125,11 +125,11 @@ The caller can query-encode the following fields:
"collections": {
"collection1.yourcompany.com": {
"instances": {
"<logtail.PublicID>" :{
"<logid.PublicID>" :{
"first-seen": "timestamp",
"size": 4096
},
"<logtail.PublicID>" :{
"<logid.PublicID>" :{
"first-seen": "timestamp",
"size": 512000,
"orphan": true,

@ -15,7 +15,7 @@ import (
"strings"
"time"
"tailscale.com/logtail"
"tailscale.com/types/logid"
)
func main() {
@ -56,7 +56,7 @@ func main() {
log.Fatalf("logreprocess: read error %d: %s", resp.StatusCode, string(b))
}
tracebackCache := make(map[logtail.PublicID]*ProcessedMsg)
tracebackCache := make(map[logid.PublicID]*ProcessedMsg)
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
@ -98,8 +98,8 @@ func main() {
type Msg struct {
Logtail struct {
Instance logtail.PublicID `json:"instance"`
ClientTime time.Time `json:"client_time"`
Instance logid.PublicID `json:"instance"`
ClientTime time.Time `json:"client_time"`
} `json:"logtail"`
Text string `json:"text"`
@ -110,6 +110,6 @@ type ProcessedMsg struct {
ClientTime time.Time `json:"client_time"`
} `json:"logtail"`
OrigInstance logtail.PublicID `json:"orig_instance"`
Text string `json:"text"`
OrigInstance logid.PublicID `json:"orig_instance"`
Text string `json:"text"`
}

@ -12,6 +12,7 @@ import (
"os"
"tailscale.com/logtail"
"tailscale.com/types/logid"
)
func main() {
@ -25,7 +26,7 @@ func main() {
log.SetFlags(0)
var id logtail.PrivateID
var id logid.PrivateID
if err := id.UnmarshalText([]byte(*privateID)); err != nil {
log.Fatalf("logtail: bad -privateid: %v", err)
}

@ -31,12 +31,12 @@ import (
"go4.org/mem"
"tailscale.com/derp"
"tailscale.com/derp/derphttp"
"tailscale.com/logtail"
"tailscale.com/net/stun/stuntest"
"tailscale.com/smallzstd"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/types/logid"
"tailscale.com/types/nettype"
"tailscale.com/version"
)
@ -283,7 +283,7 @@ func (lc *LogCatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// collectionName := pathPaths[0]
privID, err := logtail.ParsePrivateID(pathParts[1])
privID, err := logid.ParsePrivateID(pathParts[1])
if err != nil {
log.Printf("bad log ID: %q: %v", r.URL.Path, err)
}

@ -33,7 +33,7 @@ func NewPrivateID() (id PrivateID, err error) {
func (id PrivateID) MarshalText() ([]byte, error) {
b := make([]byte, hex.EncodedLen(len(id)))
if i := hex.Encode(b, id[:]); i != len(b) {
return nil, fmt.Errorf("logtail.PrivateID.MarshalText: i=%d", i)
return nil, fmt.Errorf("logid.PrivateID.MarshalText: i=%d", i)
}
return b, nil
}
@ -61,10 +61,10 @@ func (id PrivateID) IsZero() bool { return id == PrivateID{} }
func (id *PrivateID) UnmarshalText(s []byte) error {
b, err := hex.DecodeString(string(s))
if err != nil {
return fmt.Errorf("logtail.PrivateID.UnmarshalText: %v", err)
return fmt.Errorf("logid.PrivateID.UnmarshalText: %v", err)
}
if len(b) != len(id) {
return fmt.Errorf("logtail.PrivateID.UnmarshalText: invalid hex length: %d", len(b))
return fmt.Errorf("logid.PrivateID.UnmarshalText: invalid hex length: %d", len(b))
}
copy(id[:], b)
return nil
@ -121,14 +121,14 @@ func MustParsePublicID(s string) PublicID {
func (id PublicID) MarshalText() ([]byte, error) {
b := make([]byte, hex.EncodedLen(len(id)))
if i := hex.Encode(b, id[:]); i != len(b) {
return nil, fmt.Errorf("logtail.PublicID.MarshalText: i=%d", i)
return nil, fmt.Errorf("logid.PublicID.MarshalText: i=%d", i)
}
return b, nil
}
func (id *PublicID) UnmarshalText(s []byte) error {
if len(s) != len(id)*2 {
return fmt.Errorf("logtail.PublicID.UnmarshalText: invalid hex length: %d", len(s))
return fmt.Errorf("logid.PublicID.UnmarshalText: invalid hex length: %d", len(s))
}
for i := range id {
a, ok1 := fromHexChar(s[i*2+0])

@ -22,6 +22,7 @@ import (
"tailscale.com/net/tsaddr"
"tailscale.com/smallzstd"
"tailscale.com/tailcfg"
"tailscale.com/types/logid"
"tailscale.com/types/netlogtype"
"tailscale.com/util/multierr"
"tailscale.com/wgengine/router"
@ -89,7 +90,7 @@ var testClient *http.Client
// is a non-tailscale IP address to contact for that particular tailscale node.
// The IP protocol and source port are always zero.
// The sock is used to populated the PhysicalTraffic field in Message.
func (nl *Logger) Startup(nodeID tailcfg.StableNodeID, nodeLogID, domainLogID logtail.PrivateID, tun, sock Device) error {
func (nl *Logger) Startup(nodeID tailcfg.StableNodeID, nodeLogID, domainLogID logid.PrivateID, tun, sock Device) error {
nl.mu.Lock()
defer nl.mu.Unlock()
if nl.logger != nil {

@ -7,9 +7,9 @@ package wgcfg
import (
"net/netip"
"tailscale.com/logtail"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/logid"
)
//go:generate go run tailscale.com/cmd/cloner -type=Config,Peer
@ -28,8 +28,8 @@ type Config struct {
// NetworkLogging enables network logging.
// It is disabled if either ID is the zero value.
NetworkLogging struct {
NodeID logtail.PrivateID
DomainID logtail.PrivateID
NodeID logid.PrivateID
DomainID logid.PrivateID
}
}

@ -11,10 +11,10 @@ import (
"strings"
"golang.org/x/exp/slices"
"tailscale.com/logtail"
"tailscale.com/net/tsaddr"
"tailscale.com/tailcfg"
"tailscale.com/types/logger"
"tailscale.com/types/logid"
"tailscale.com/types/netmap"
"tailscale.com/wgengine/wgcfg"
)
@ -64,11 +64,11 @@ func WGCfg(nm *netmap.NetworkMap, logf logger.Logf, flags netmap.WGConfigFlags,
cfg.NodeID = nm.SelfNode.StableID
canNetworkLog := slices.Contains(nm.SelfNode.Capabilities, tailcfg.CapabilityDataPlaneAuditLogs)
if canNetworkLog && nm.SelfNode.DataPlaneAuditLogID != "" && nm.DomainAuditLogID != "" {
nodeID, errNode := logtail.ParsePrivateID(nm.SelfNode.DataPlaneAuditLogID)
nodeID, errNode := logid.ParsePrivateID(nm.SelfNode.DataPlaneAuditLogID)
if errNode != nil {
logf("[v1] wgcfg: unable to parse node audit log ID: %v", errNode)
}
domainID, errDomain := logtail.ParsePrivateID(nm.DomainAuditLogID)
domainID, errDomain := logid.ParsePrivateID(nm.DomainAuditLogID)
if errDomain != nil {
logf("[v1] wgcfg: unable to parse domain audit log ID: %v", errDomain)
}

Loading…
Cancel
Save