accesslog

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package accesslog buffers, batches and reports access-log entries to the panel, per node. It is ported from the local XrayR fork service/accesslog (engine-neutral part) and re-railed for Sing2: there is no xray-core app/log stream to wrap, so the log-handler capture layer (xrayLogHandler / buildEntry / regex parsing) is dropped and replaced by a non-blocking Ingest entry point. The caller (billing hook) constructs each api.AccessLogEntry from connection metadata and hands it in directly. See doc/11 §13.

Index

Constants

View Source
const (
	ProbeBroadcast = "broadcast" // send untagged probe rows to every node
	ProbeFirst     = "first"     // send only to the first registered node
	ProbeNone      = "none"      // drop untagged probe rows
)

Probe report policies (untagged rows with no user, e.g. auth failure / scan).

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enable            bool   `mapstructure:"Enable"`
	ReportInvalidUser *bool  `mapstructure:"ReportInvalidUser"` // nil => true (report probe rows)
	ProbeReportPolicy string `mapstructure:"ProbeReportPolicy"` // broadcast | first | none
	BatchSize         int    `mapstructure:"BatchSize"`
	FlushInterval     string `mapstructure:"FlushInterval"` // duration string, e.g. "3s"
	MaxBatch          int    `mapstructure:"MaxBatch"`
	BufferMax         int    `mapstructure:"BufferMax"` // per-node buffer cap
	IngestChanSize    int    `mapstructure:"IngestChanSize"`
}

Config is the process-level access-log reporting configuration. It lives at the top level (sibling of Log) because a single Sing2 process runs a shared access stream for all nodes. Per-node auth (NodeID) is taken from each node's existing ApiConfig via Register. Ported verbatim from the local XrayR fork service/accesslog/config.go (engine-neutral part). See doc/11 §13.1.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager consumes access-log entries from the ingest channel, routes them to per-node buffers by inbound tag, and flushes each buffer to its panel in batches. It is a process-level singleton owned by the panel orchestrator.

func New

func New(cfg *Config) *Manager

New creates a Manager. Unlike the XrayR original it takes no core.Instance or logger: capture is via the explicit Ingest entry point, not a wrapped app/log handler (doc/11 §13.2).

func (*Manager) Close

func (m *Manager) Close()

Close stops the manager. In-flight buffers get a best-effort final drain in each flush goroutine.

func (*Manager) Ingest

func (m *Manager) Ingest(entry api.AccessLogEntry, tag string)

Ingest is the non-blocking capture entry point (replaces XrayR's inline xrayLogHandler.Handle). It is called on the proxy hot path: the entry is posted to the ingest channel and, if the channel is full, dropped rather than blocking forwarding (doc/11 §13.2, cf. manager.go:289-293). tag is the NodeTag segment of the join key; empty means an untagged probe row routed per ProbeReportPolicy. Untagged rows are skipped entirely when ReportInvalidUser is disabled.

func (*Manager) Register

func (m *Manager) Register(tag string, reporter api.AccessLogReporter, nodeID int)

Register adds a node's reporting target keyed by its inbound tag. Controllers call it during Start (before Manager.Start) and again on node rebuild when the tag changes — a late registration after Start launches the new target's flusher immediately so its rows are flushed instead of counted as dropped.

func (*Manager) Start

func (m *Manager) Start()

Start launches the consumer/flusher/stats goroutines. Register all nodes before calling Start.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL