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

@ -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/lineread from tailscale.com/hostinfo+
tailscale.com/util/mak from tailscale.com/control/controlclient+ tailscale.com/util/mak from tailscale.com/control/controlclient+
tailscale.com/util/multierr 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+ tailscale.com/util/osshare from tailscale.com/ipn/ipnlocal+
W tailscale.com/util/pidowner from tailscale.com/ipn/ipnauth W tailscale.com/util/pidowner from tailscale.com/ipn/ipnauth
tailscale.com/util/racebuild from tailscale.com/logpolicy tailscale.com/util/racebuild from tailscale.com/logpolicy

@ -11,11 +11,11 @@ import (
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/ipn/store/mem" "tailscale.com/ipn/store/mem"
"tailscale.com/logtail"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/tstest" "tailscale.com/tstest"
"tailscale.com/types/key" "tailscale.com/types/key"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/types/logid"
"tailscale.com/types/persist" "tailscale.com/types/persist"
"tailscale.com/wgengine" "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. // 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) logf := logger.RateLimitedFnWithClock(logListen.Logf, 5*time.Second, 0, 10, time.Now)
logid := func(hex byte) logtail.PublicID { logid := func(hex byte) logid.PublicID {
var ret logtail.PublicID var ret logid.PublicID
for i := 0; i < len(ret); i++ { for i := 0; i < len(ret); i++ {
ret[i] = hex ret[i] = hex
} }

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

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

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

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

@ -31,12 +31,12 @@ import (
"go4.org/mem" "go4.org/mem"
"tailscale.com/derp" "tailscale.com/derp"
"tailscale.com/derp/derphttp" "tailscale.com/derp/derphttp"
"tailscale.com/logtail"
"tailscale.com/net/stun/stuntest" "tailscale.com/net/stun/stuntest"
"tailscale.com/smallzstd" "tailscale.com/smallzstd"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/key" "tailscale.com/types/key"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/types/logid"
"tailscale.com/types/nettype" "tailscale.com/types/nettype"
"tailscale.com/version" "tailscale.com/version"
) )
@ -283,7 +283,7 @@ func (lc *LogCatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
// collectionName := pathPaths[0] // collectionName := pathPaths[0]
privID, err := logtail.ParsePrivateID(pathParts[1]) privID, err := logid.ParsePrivateID(pathParts[1])
if err != nil { if err != nil {
log.Printf("bad log ID: %q: %v", r.URL.Path, err) 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) { func (id PrivateID) MarshalText() ([]byte, error) {
b := make([]byte, hex.EncodedLen(len(id))) b := make([]byte, hex.EncodedLen(len(id)))
if i := hex.Encode(b, id[:]); i != len(b) { 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 return b, nil
} }
@ -61,10 +61,10 @@ func (id PrivateID) IsZero() bool { return id == PrivateID{} }
func (id *PrivateID) UnmarshalText(s []byte) error { func (id *PrivateID) UnmarshalText(s []byte) error {
b, err := hex.DecodeString(string(s)) b, err := hex.DecodeString(string(s))
if err != nil { if err != nil {
return fmt.Errorf("logtail.PrivateID.UnmarshalText: %v", err) return fmt.Errorf("logid.PrivateID.UnmarshalText: %v", err)
} }
if len(b) != len(id) { 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) copy(id[:], b)
return nil return nil
@ -121,14 +121,14 @@ func MustParsePublicID(s string) PublicID {
func (id PublicID) MarshalText() ([]byte, error) { func (id PublicID) MarshalText() ([]byte, error) {
b := make([]byte, hex.EncodedLen(len(id))) b := make([]byte, hex.EncodedLen(len(id)))
if i := hex.Encode(b, id[:]); i != len(b) { 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 return b, nil
} }
func (id *PublicID) UnmarshalText(s []byte) error { func (id *PublicID) UnmarshalText(s []byte) error {
if len(s) != len(id)*2 { 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 { for i := range id {
a, ok1 := fromHexChar(s[i*2+0]) a, ok1 := fromHexChar(s[i*2+0])

@ -22,6 +22,7 @@ import (
"tailscale.com/net/tsaddr" "tailscale.com/net/tsaddr"
"tailscale.com/smallzstd" "tailscale.com/smallzstd"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/logid"
"tailscale.com/types/netlogtype" "tailscale.com/types/netlogtype"
"tailscale.com/util/multierr" "tailscale.com/util/multierr"
"tailscale.com/wgengine/router" "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. // is a non-tailscale IP address to contact for that particular tailscale node.
// The IP protocol and source port are always zero. // The IP protocol and source port are always zero.
// The sock is used to populated the PhysicalTraffic field in Message. // 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() nl.mu.Lock()
defer nl.mu.Unlock() defer nl.mu.Unlock()
if nl.logger != nil { if nl.logger != nil {

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

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

Loading…
Cancel
Save