feat(library): 采集接入 RDS 型 0.9.0 栈
build / build (push) Failing after 1m33s

为什么:测试 0.9.0 栈(Compose 项目 weknora-v090)没有源库容器,治理库也不在
容器里,两者都是 RDS。旧实现用 -source-pg/-governance-pg 的容器地址拼 DSN、
用 docker exec psql 读路由绑定,在这类栈上采集根本起不来——不是权限问题,是
地址解析方式错了。

怎么改:
- 新增 internal/librarydsn 收敛"这次 DSN 从哪来":容器模式保持原形状
  (sslmode=disable,目标不变);-source-pg 为空时改用源应用容器 env 的 DB_*
  直连托管实例,TLS 取 LIBRARY_SOURCE_DB_SSLMODE(默认 require,prefer/allow
  这类会静默降级的取值直接拒);-governance-pg 为空时从
  LIBRARY_GOVERNANCE_DSN_FILE 的 0600 文件读 DSN(复用 dobotaiops.ReadDSNFile,
  不另写一份同义实现)。两条路径都不进日志/错误/describe,错误只点名缺哪个变量、
  缺哪个文件。
- libraryctl 的路由绑定读取按模式分派,只共用行解析;外部路径用只读会话。
  libraryagent 的 identity/health 增报 source_db/governance_db 模式;-describe
  只打这两项,不再 dump 配置。
- 新增 scripts/library-capture-v090.sh:weknora-v090 的唯一写入者 app + 逐个
  声明的 non-writers,两个 -pg 传空走外部模式,归档根可环境变量覆盖,
  LIBRARYCTL_BIN 缺失即失败;0.7.1 入口脚本一字未动。

怎么验:internal/librarydsn 三条路径(容器/RDS/文件)各有用例,缺变量、缺文件、
0644 文件、非 PostgreSQL 内容均失败关闭且断言错误不含口令;cmd/libraryctl 侧
钉住文件模式接线与"错误不带地址";v090 脚本进 CI 做 bash -n 加标志/服务声明
断言,并拒绝 0.7.1 容器名出现在新入口。make verify 17 项全绿。

未做:真实采集、生产 executor、Key/KB 绑定。
This commit is contained in:
姚章浩
2026-11-16 20:53:40 +08:00
parent fba2713b4e
commit 0aa9f273e6
9 changed files with 601 additions and 34 deletions
+11 -2
View File
@@ -26,6 +26,8 @@ import (
"sync"
"syscall"
"time"
"knowledge-governance/internal/librarydsn"
)
// Config is fixed at start-up by the operator (systemd unit / CLI flags). It is
@@ -429,15 +431,22 @@ func (a *Agent) health() response {
}
// identity 被日志与健康应答共用一份,避免两处描述漂移。
//
// 数据库只报来源模式(container|external|file),不报地址:agent 的应答会被治理侧
// 存档,DSN 里带口令,一旦写进身份就再也收不回来了。
func (c Config) identity() map[string]any {
identity := map[string]any{
"project": c.Project,
"archive_root": c.ArchiveRoot,
"journal_root": c.JournalRoot,
"source_app": c.SourceApp,
"source_pg": c.SourcePG,
"source_es": c.SourceES,
"writers": c.Writers,
// source_pg 仍是容器名(不是地址、不是凭据),保留它以让既有健康页/事后核对
// 读得到同一份字段;数据库**来源**由下面两个模式字段表达,外部模式下它为空。
"source_pg": c.SourcePG,
"source_db": librarydsn.SourceMode(c.SourcePG),
"governance_db": librarydsn.GovernanceMode(c.GovernancePG),
"writers": c.Writers,
}
if c.SourceS3Endpoint != "" {
identity["source_s3_endpoint"] = c.SourceS3Endpoint