Help us shape the future of Go! Take the 2026 Go Developer Survey

logs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package logs 是应用日志管线(T2.20;architecture §4.2 第 5 项「实时流 + 历史落盘检索」):

采集(底座 docker service logs 轮询)→ 脱敏(该 app env 已知值)
→ 内存 ring buffer(per app-service 有界,Follow 回放与实时扇出)
→ 落盘(目录可配,按天分文件,7 天轮转清理,History 检索源)。

Secret 值纪律(state-model §2.9):脱敏只针对**该 app 的 env 已知值** (负面测试保证 env 值不出现在任何出口);短值(< 8 字节)不参与脱敏 (避免把日志打成筛子),属已知取舍。

Index

Constants

View Source
const (
	// SourceContainer 是容器(docker service logs 采集)来源。
	SourceContainer = "container"
	// SourceBuild 是构建日志(builds 表 log_path 产物)来源。
	SourceBuild = "build"
)

日志来源词表。

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Dir 是落盘根目录(logs.dir;缺省 ./fleetly-logs)。
	Dir string `mapstructure:"dir"`
	// RetentionDays 是落盘保留天数(logs.retention_days;缺省 7——架构
	// §2.3 数据保留:应用日志 7 天轮转)。
	RetentionDays int `mapstructure:"retention_days"`
	// ScanIntervalMillis 是采集轮询周期毫秒数(logs.scan_interval_millis;
	// 缺省 2000)。
	ScanIntervalMillis int `mapstructure:"scan_interval_millis"`
	// RingSize 是 per app-service 内存环形缓冲深度(logs.ring_size;缺省
	// 1000——Follow 接入时的回放上限)。
	RingSize int `mapstructure:"ring_size"`
}

Config 是日志管线配置(config 键 logs.*)。零值经 Normalize 回落缺省。

func (Config) Normalize

func (c Config) Normalize() Config

Normalize 回落缺省值(单一事实源在本包;cmd 配置层不做缺省)。

func (Config) ScanInterval

func (c Config) ScanInterval() time.Duration

ScanInterval 返回轮询周期。

type Entry

type Entry struct {
	App     string    `json:"app"`
	Service string    `json:"service"`
	At      time.Time `json:"at"`
	Stderr  bool      `json:"stderr,omitempty"`
	Line    string    `json:"line"`
	// Source ∈ container | build(History 按 source 区分检索)。
	Source string `json:"source"`
}

Entry 是一条应用日志(采集出口与 API 投影的共同形态)。

type HistoryQuery

type HistoryQuery struct {
	App     string
	Service string
	Source  string // "" | container | build
	Since   time.Time
	Until   time.Time
	Limit   int
}

HistoryQuery 是历史检索参数(app 必填;service/source 空 = 不过滤)。

type Manager

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

Manager 是日志管线管理器:采集循环(Start 阻塞到 ctx 取消)、Follow 订阅、History 落盘检索、保留期清理。

func NewManager

func NewManager(cfg Config, st *state.Store, port Port, box *secrets.Box, log *slog.Logger) *Manager

NewManager 构造日志管线管理器(不启动采集;Run 承载循环)。

func (*Manager) Follow

func (m *Manager) Follow(ctx context.Context, app, service string) (<-chan Entry, func())

Follow 订阅实时日志(T2.20:实时流;gRPC Follow RPC 的管线入口)。 先回放 ring(限深回放),后实时扇出;ctx 取消自动注销(断线重连 = 客户端重新 Follow)。

func (*Manager) History

func (m *Manager) History(ctx context.Context, q HistoryQuery) ([]Entry, error)

History 检索历史日志:container 来源走落盘扫描;build 来源读 builds 表 log_path 产物(行级无时间戳,行时间取构建开始时刻——诚实缺失,不伪造 逐行时间)。结果按时间升序,超 limit 取最新 limit 条。

func (*Manager) InvalidateRedaction

func (m *Manager) InvalidateRedaction(appID string)

InvalidateRedaction 主动失效某 app 的脱敏值集缓存(H9):env 写路径 (api set/remove)与部署 env 提升点(engine 观察窗成功)联动调用,把 「新 secret 值在 TTL 窗内被明文采集并按天落盘保留 7 天」的暴露窗收敛 到下一次 forApp 重建。幂等;未知 appID 无害。未挂钩的写路径仍由 TTL 兜底(redact.go redactorTTL 注释)。

func (*Manager) Run

func (m *Manager) Run(ctx context.Context) error

Run 是采集主循环(lynx 服务壳 Start 消费):周期扫描 active apps 的 受管服务 → 逐流轮询 docker service logs(follow=false + since 游标)→ 脱敏 → ring + 落盘 + 扇出。ctx 取消即返回。首轮前做一次落盘清理。

func (*Manager) WithClock

func (m *Manager) WithClock(f func() time.Time) *Manager

WithClock 覆盖时钟(测试注入)。

func (*Manager) WithSecretSource

func (m *Manager) WithSecretSource(s SecretValuesSource) *Manager

WithSecretSource 注入补充脱敏值集供给(B3;装配期调用——实现方提供 state 密文列之外的明文 secret 落点,如 gitserver 钩子 token)。

type Port

type Port interface {
	// StreamServiceLogs 打开 Swarm 服务日志流(follow=false 轮询拉取语义)。
	StreamServiceLogs(ctx context.Context, service string, since time.Time, follow bool) (<-chan substrate.LogLine, error)
	// ManagedServiceProcesses 返回应用的受管 compose 服务名集。
	ManagedServiceProcesses(ctx context.Context, app string) ([]string, error)
}

Port 是日志采集的底座端口(实现 = substrate.Client;cmd 装配注入, 测试用 fake)。

type SecretValuesSource

type SecretValuesSource interface {
	// SecretValues 返回该 app 的补充脱敏明文值集(可为空)。
	SecretValues(ctx context.Context, appID string) []string
}

SecretValuesSource 是 B3 脱敏值集扩面的补充供给端口:返回该 app 在 state 密文列之外仍存明文落点的 secret 值(实现 = gitserver.GitTriggers 的 post-receive 钩子 token——明文只写进钩子文件;logs 不感知实现类型, 装配点注入)。读取失败应返回 nil(观测面降级不阻断采集)。

Jump to

Keyboard shortcuts

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