Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/xtcp2/testdata/defineflags-golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ enrichLocality false best-effort: per namespace, dump the local addresses + rout
enrichNic false best-effort: read NIC identity (driver/model/pci/speed/firmware) from sysfs+ethtool once at startup and stamp each uplink's nic_* columns. Non-fatal on read failure. Falls back to ENRICH_NIC env.
envelopeFlushBytes 0 Safety-net cap on the in-flight protobufList Envelope's UNCOMPRESSED proto size in bytes (franz-go compresses post-flush, so wire size is typically 3-8x smaller). 0 = use daemon default (768 KiB). Whichever cap (bytes/rows) trips first wins.
envelopeFlushRows 0 Primary cap on the in-flight protobufList Envelope's row count. 0 = use daemon default (10000). Cheap, predictable; pairs with -envelopeFlushBytes as a safety net.
eventsDest the events destination for -eventsEnable: a file: path at v1 (the destinations' factories are single-dest, so the export owns its file sink; see docs/netlink/events-export.md). Falls back to EVENTS_DEST env.
eventsEnable false export rtnetlink notifications (link, address, route, neigh, rule) as xtcp_netlink_events rows, one listener per monitored namespace, flushed to -eventsDest on the events flush caps; the record path is untouched. Needs -eventsDest. Falls back to EVENTS_ENABLE env.
eventsFlushInterval 0s time between interval flushes of the events envelope; 0 = the measured default (1s — the locality consumer's own chosen latency; see pkg/xtcp/events_export_policy.go). Falls back to EVENTS_FLUSH_INTERVAL env.
eventsFlushThresholdBytes 0 size cap on the in-flight events envelope, in bytes (measured bodies run 40-1548); 0 = the measured default (64 KiB). Falls back to EVENTS_FLUSH_THRESHOLD_BYTES env.
eventsFlushThresholdRows 0 row-count cap on the events envelope (the boot flood peak is 56 events per 100ms, so the cap fires first under load); 0 = the measured default (64). Falls back to EVENTS_FLUSH_THRESHOLD_ROWS env.
frequency 10s Poll frequency
goMaxProcs 4 goMaxProcs = https://golang.org/pkg/runtime/#GOMAXPROCS
grpcListenAddress gRPC TCP address or Unix socket path. Empty derives TCP from -grpcPort. Falls back to GRPC_LISTEN_ADDRESS env.
Expand Down
5 changes: 5 additions & 0 deletions cmd/xtcp2/testdata/printflags-golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
*enrichLocality: true
*localityRefreshInterval: 125ms
*localityEvents: true
*eventsEnable: true
*eventsDest: file:/var/lib/xtcp2/events.bin
*eventsFlushInterval: 161ms
*eventsFlushThresholdRows: 162
*eventsFlushThresholdBytes: 163
compiledInEnrichers: {{compiledInEnrichers}}
*linkMonitor: true
*linkMonitorBaselineFile: linkMonitorBaselineFile-v
Expand Down
113 changes: 85 additions & 28 deletions cmd/xtcp2/xtcp2.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ const (
// localityEventsCst keeps -enrichLocality on its timed re-dump until the
// rtnetlink listener has soaked.
localityEventsCst = false
// eventsEnableCst: the rtnetlink events export is off by default
// (docs/netlink/events-export.md) — an opt-in second stream beside the
// record path.
eventsEnableCst = false
// eventsDestCst is where -eventsEnable writes: empty, so an operator who
// enables the export without choosing a destination gets a startup error
// (an empty -eventsDest path is rejected), never a silent no-op.
eventsDestCst = ""
// eventsFlushIntervalCst / eventsFlushThresholdRowsCst /
// eventsFlushThresholdBytesCst: 0 means the EXM constants
// (pkg/xtcp/events_export_policy.go), measured from the committed event
// corpora — see the -eventsEnable flag's help text.
eventsFlushIntervalCst = 0
eventsFlushThresholdRowsCst = 0
eventsFlushThresholdBytesCst = 0
// ASN enrichment is off by default and the artifact path has no sensible
// default. asnRefreshIntervalCst re-stats the artifact hourly and reloads it
// only when its size/mtime changed, so a refreshed — or late-arriving —
Expand Down Expand Up @@ -373,6 +388,12 @@ type mainFlags struct {
localityRefreshInterval *time.Duration
localityEvents *bool

eventsEnable *bool
eventsDest *string
eventsFlushInterval *time.Duration
eventsFlushRows *uint
eventsFlushBytes *uint

linkMonitor *bool
linkMonitorBaselineFile *string
linkMonitorSettle *time.Duration
Expand Down Expand Up @@ -686,6 +707,12 @@ func defineEnrichmentFlags(f *mainFlags) {
f.enrichLocality = flag.Bool("enrichLocality", enrichLocalityCst, "best-effort: per namespace, dump the local addresses + routing table via rtnetlink and classify each socket's destination as self/local-subnet/remote, stamping the enrich_socket_dest_locality + interface-name columns (bound idiag_if and route egress). Non-fatal on read failure. Falls back to ENRICH_LOCALITY env."+enricherBuildNote(xtcp.EnricherLocality))
f.localityRefreshInterval = flag.Duration("localityRefreshInterval", localityRefreshIntervalCst, "how often -enrichLocality re-dumps every namespace's addresses/routes on the reconcile path (new namespaces are always dumped on the next reconcile; failed or loopback-only namespaces retry on a 30s-5m backoff); 0 = discover each namespace once, never refresh. Auto-detected uplinks (no -uplinkInterfaces) are re-read on the same interval. Falls back to LOCALITY_REFRESH_INTERVAL env.")
f.localityEvents = flag.Bool("localityEvents", localityEventsCst, "with -enrichLocality, keep each namespace's locality snapshot current from rtnetlink link/address/route notifications (one listener per namespace) so a change shows within about a second; -localityRefreshInterval then becomes a backstop resync. Ignored without -enrichLocality. Falls back to LOCALITY_EVENTS env.")

f.eventsEnable = flag.Bool("eventsEnable", eventsEnableCst, "export rtnetlink notifications (link, address, route, neigh, rule) as xtcp_netlink_events rows, one listener per monitored namespace, flushed to -eventsDest on the events flush caps; the record path is untouched. Needs -eventsDest. Falls back to EVENTS_ENABLE env.")
f.eventsDest = flag.String("eventsDest", eventsDestCst, "the events destination for -eventsEnable: a file: path at v1 (the destinations' factories are single-dest, so the export owns its file sink; see docs/netlink/events-export.md). Falls back to EVENTS_DEST env.")
f.eventsFlushInterval = flag.Duration("eventsFlushInterval", eventsFlushIntervalCst, "time between interval flushes of the events envelope; 0 = the measured default (1s — the locality consumer's own chosen latency; see pkg/xtcp/events_export_policy.go). Falls back to EVENTS_FLUSH_INTERVAL env.")
f.eventsFlushRows = flag.Uint("eventsFlushThresholdRows", eventsFlushThresholdRowsCst, "row-count cap on the events envelope (the boot flood peak is 56 events per 100ms, so the cap fires first under load); 0 = the measured default (64). Falls back to EVENTS_FLUSH_THRESHOLD_ROWS env.")
f.eventsFlushBytes = flag.Uint("eventsFlushThresholdBytes", eventsFlushThresholdBytesCst, "size cap on the in-flight events envelope, in bytes (measured bodies run 40-1548); 0 = the measured default (64 KiB). Falls back to EVENTS_FLUSH_THRESHOLD_BYTES env.")
}

// printFlags echoes every flag xtcp2 will act on to stdout at startup.
Expand Down Expand Up @@ -834,6 +861,11 @@ func printEnrichmentFlags(f *mainFlags) {
fmt.Println("*enrichLocality:", *f.enrichLocality)
fmt.Println("*localityRefreshInterval:", *f.localityRefreshInterval)
fmt.Println("*localityEvents:", *f.localityEvents)
fmt.Println("*eventsEnable:", *f.eventsEnable)
fmt.Println("*eventsDest:", *f.eventsDest)
fmt.Println("*eventsFlushInterval:", *f.eventsFlushInterval)
fmt.Println("*eventsFlushThresholdRows:", *f.eventsFlushRows)
fmt.Println("*eventsFlushThresholdBytes:", *f.eventsFlushBytes)
// Which enrichers this artifact actually contains. Printed next to the
// flags because the two together are what determine whether the enrich_*
// columns will be populated; either one alone is misleading.
Expand Down Expand Up @@ -933,34 +965,39 @@ func buildConfig(f *mainFlags, des *xtcp_config.EnabledDeserializers) *xtcp_conf
Location: *f.location,
Hostname: *f.hostname,
// DaemonVersion: build provenance (-ldflags) stamped on every record.
DaemonVersion: versionString(),
ResolveContainerId: *f.resolveContainerId,
EnrichContainerEnable: *f.enrichContainer,
DockerSocketPath: *f.dockerSocket,
EnrichLldpEnable: *f.enrichLldp,
LldpdSocketPath: *f.lldpdSocket,
LldpdVersionHint: *f.lldpdVersionHint,
EnrichNicEnable: *f.enrichNic,
UplinkCount: uint32(*f.uplinkCount),
UplinkInterfaces: splitCSV(*f.uplinkInterfaces),
PopulateNsid: *f.populateNsid,
EnrichAsnEnable: *f.enrichAsn,
AsnDbPath: *f.asnDbPath,
AsnRefreshInterval: durationpb.New(*f.asnRefreshInterval),
IpmetaBootstrapPath: *f.ipmetaBootstrapPath,
IpmetaCachePath: *f.ipmetaCachePath,
EnrichLocalityEnable: *f.enrichLocality,
LocalityRefreshInterval: durationpb.New(*f.localityRefreshInterval),
LocalityEventsEnable: *f.localityEvents,
LinkMonitor: buildLinkMonitorConfig(f),
Ipv4Ttl: uint32(*f.ipv4Ttl),
Ipv6HopLimit: uint32(*f.ipv6HopLimit),
ListenerAuth: buildListenerAuth(f),
AdminListenerAuth: buildAdminListenerAuth(f),
GrpcPort: uint32(*f.grpcPort),
GrpcListener: grpcListener,
PrometheusListener: prometheusListener,
EnabledDeserializers: des,
DaemonVersion: versionString(),
ResolveContainerId: *f.resolveContainerId,
EnrichContainerEnable: *f.enrichContainer,
DockerSocketPath: *f.dockerSocket,
EnrichLldpEnable: *f.enrichLldp,
LldpdSocketPath: *f.lldpdSocket,
LldpdVersionHint: *f.lldpdVersionHint,
EnrichNicEnable: *f.enrichNic,
UplinkCount: uint32(*f.uplinkCount),
UplinkInterfaces: splitCSV(*f.uplinkInterfaces),
PopulateNsid: *f.populateNsid,
EnrichAsnEnable: *f.enrichAsn,
AsnDbPath: *f.asnDbPath,
AsnRefreshInterval: durationpb.New(*f.asnRefreshInterval),
IpmetaBootstrapPath: *f.ipmetaBootstrapPath,
IpmetaCachePath: *f.ipmetaCachePath,
EnrichLocalityEnable: *f.enrichLocality,
LocalityRefreshInterval: durationpb.New(*f.localityRefreshInterval),
LocalityEventsEnable: *f.localityEvents,
EventsEnable: *f.eventsEnable,
EventsDest: *f.eventsDest,
EventsFlushIntervalMs: uint32(f.eventsFlushInterval.Milliseconds()),
EventsFlushThresholdRows: uint32(*f.eventsFlushRows),
EventsFlushThresholdBytes: uint32(*f.eventsFlushBytes),
LinkMonitor: buildLinkMonitorConfig(f),
Ipv4Ttl: uint32(*f.ipv4Ttl),
Ipv6HopLimit: uint32(*f.ipv6HopLimit),
ListenerAuth: buildListenerAuth(f),
AdminListenerAuth: buildAdminListenerAuth(f),
GrpcPort: uint32(*f.grpcPort),
GrpcListener: grpcListener,
PrometheusListener: prometheusListener,
EnabledDeserializers: des,

IoUring: *f.ioUring,
IoUringRecvBatchSize: uint32(*f.ioUringRecvBatch),
Expand Down Expand Up @@ -2167,6 +2204,26 @@ func envOverrideEnrichment(c *xtcp_config.XtcpConfig, debugLevel uint) {
c.LocalityEventsEnable = v
logEnv("LOCALITY_EVENTS", fmt.Sprintf("c.LocalityEventsEnable:%t", v), debugLevel)
}
if v, ok := envBool("EVENTS_ENABLE"); ok {
c.EventsEnable = v
logEnv("EVENTS_ENABLE", fmt.Sprintf("c.EventsEnable:%t", v), debugLevel)
}
if v, ok := envString("EVENTS_DEST"); ok && strings.TrimSpace(v) != "" {
c.EventsDest = v
logEnv("EVENTS_DEST", fmt.Sprintf("c.EventsDest:%s", c.EventsDest), debugLevel)
}
if v, ok := envDuration("EVENTS_FLUSH_INTERVAL"); ok {
c.EventsFlushIntervalMs = uint32(v.Milliseconds())
logEnv("EVENTS_FLUSH_INTERVAL", fmt.Sprintf("c.EventsFlushIntervalMs:%d", c.EventsFlushIntervalMs), debugLevel)
}
if v, ok := envUint32("EVENTS_FLUSH_THRESHOLD_ROWS"); ok {
c.EventsFlushThresholdRows = v
logEnv("EVENTS_FLUSH_THRESHOLD_ROWS", fmt.Sprintf("c.EventsFlushThresholdRows:%d", c.EventsFlushThresholdRows), debugLevel)
}
if v, ok := envUint32("EVENTS_FLUSH_THRESHOLD_BYTES"); ok {
c.EventsFlushThresholdBytes = v
logEnv("EVENTS_FLUSH_THRESHOLD_BYTES", fmt.Sprintf("c.EventsFlushThresholdBytes:%d", c.EventsFlushThresholdBytes), debugLevel)
}
if v, ok := envUint32("UPLINK_COUNT"); ok {
c.UplinkCount = v
logEnv("UPLINK_COUNT", fmt.Sprintf("c.UplinkCount:%d", v), debugLevel)
Expand Down
8 changes: 7 additions & 1 deletion cmd/xtcp2/xtcp2_flags_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const (
// mainFlags field must be a registered flag and every registered flag must
// have a field. A flag added without a field, or a field that stops being
// registered, is the drift this file exists to notice.
mainFlagsFieldCountCst = 146 // + treatmentConfig (embedded agent) and treatmentAttribution (journal reader)
mainFlagsFieldCountCst = 151 // + treatmentConfig (embedded agent) and treatmentAttribution (journal reader); 146->151: the events export block (-eventsEnable/-eventsDest/-eventsFlush*), events-export.md Tier EXD-T02

printFlagsGoldenCst = "testdata/printflags-golden.txt"
defineFlagsGoldenCst = "testdata/defineflags-golden.txt"
Expand Down Expand Up @@ -245,6 +245,12 @@ func populatedMainFlags() *mainFlags {
localityRefreshInterval: ms(125),
localityEvents: b(true),

eventsEnable: b(true),
eventsDest: s("file:/var/lib/xtcp2/events.bin"),
eventsFlushInterval: ms(161),
eventsFlushRows: u(162),
eventsFlushBytes: u(163),

linkMonitor: b(true),
linkMonitorBaselineFile: s("linkMonitorBaselineFile-v"),
linkMonitorSettle: ms(141),
Expand Down
16 changes: 16 additions & 0 deletions cmd/xtcp2/xtcp2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@ func TestPrintFlags(t *testing.T) {
f.enrichLocality = &b
f.localityRefreshInterval = &d
f.localityEvents = &b
f.eventsEnable = &b
f.eventsDest = &s
f.eventsFlushInterval = &d
f.eventsFlushRows = &n
f.eventsFlushBytes = &n
f.linkMonitor = &b
f.linkMonitorBaselineFile = &s
f.linkMonitorSettle = &d
Expand Down Expand Up @@ -1212,6 +1217,10 @@ func TestBuildConfig(t *testing.T) {
cols := "hostname,tcpInfoRtt"
dst := "udp:127.0.0.1:13000"
dwf := uint(4)
eventsDest := "file:/tmp/xtcp2-events.bin"
efi := 900 * time.Millisecond
efr := uint(64)
efb := uint(65536)
topic := "topic1"
xp := "x.proto"
ksu := "http://sr"
Expand Down Expand Up @@ -1341,6 +1350,8 @@ func TestBuildConfig(t *testing.T) {
enrichAsn: &iu, asnDbPath: &mar, asnRefreshInterval: &rf,
ipmetaBootstrapPath: &ipmetaBootstrap, ipmetaCachePath: &ipmetaCache,
enrichLocality: &iu, localityRefreshInterval: &rf, localityEvents: &iu,
eventsEnable: &iu, eventsDest: &eventsDest, eventsFlushInterval: &efi,
eventsFlushRows: &efr, eventsFlushBytes: &efb,
linkMonitor: &iu, linkMonitorBaselineFile: &lmBaseline, linkMonitorSettle: &rf,
linkMonitorLearnDeadline: &lmDeadline,
linkMonitorResync: &subc, linkMonitorStatsInterval: &pf, linkMonitorStatsInclude: &lmInclude,
Expand Down Expand Up @@ -1402,6 +1413,11 @@ func TestBuildConfig(t *testing.T) {
{"ReconcileBeforePoll", c.ReconcileBeforePoll, false},
{"IpmetaBootstrapPath", c.IpmetaBootstrapPath, ipmetaBootstrap},
{"IpmetaCachePath", c.IpmetaCachePath, ipmetaCache},
{"EventsEnable", c.EventsEnable, true},
{"EventsDest", c.EventsDest, eventsDest},
{"EventsFlushIntervalMs", c.EventsFlushIntervalMs, uint32(900)},
{"EventsFlushThresholdRows", c.EventsFlushThresholdRows, uint32(64)},
{"EventsFlushThresholdBytes", c.EventsFlushThresholdBytes, uint32(65536)},
{"LinkMonitor.Enable", c.LinkMonitor.GetEnable(), true},
{"LinkMonitor.BaselineFile", c.LinkMonitor.GetBaselineFile(), lmBaseline},
{"LinkMonitor.Settle", c.LinkMonitor.GetSettle().AsDuration(), 3 * time.Minute},
Expand Down
Loading