Repository navigation
feat(web): configuration-only optional frontend analytics - #1037
xiaoyaner0201 wants to merge 6 commits into
Conversation
Move the passive helper and Umami adapter into one product source, retain the existing assertions, and add consent-aware lazy lifecycle control. Refs iflytek#989 Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>
Safely transport bounded JSON using existing image tools, generate isolated exact proxy routes with verified HTTPS, and wire Compose and Helm with closed defaults. Refs iflytek#989 Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>
Replace manual injection instructions with Compose, Docker and Helm configuration, explicit platform initialization, consent controls, privacy boundaries and verified task status. Refs iflytek#989 Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>
Clarify the one-time initialization sequence verified during the guide walkthrough. Refs iflytek#989 Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>
Helm --set-string parses {...} as a list, so the enabled-analytics
contract case failed schema validation in CI. Use a values file, the
same way the operator guide documents the setting.
Refs iflytek#989
Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>
|
我们基于当前提交 本次使用源码构建的真实镜像、真实 SkillHub 后端和 Umami 验证了:
这些主要链路均通过,暂未发现阻断性的浏览器或代理运行问题。建议本 PR 再调整以下两部分: 1. 隔离 Helm 统计配置的影响 目前统计字段放在共享 ConfigMap 中,而后端 Pod 的 checksum 覆盖整份 ConfigMap。因此仅修改统计开关、规则、网站 UUID 或上游地址,也会触发后端 Pod 替换;部分存储配置使用 我们已通过 Helm 模板渲染对照确认。建议将统计配置拆到 Web 专用 ConfigMap,或收窄后端 checksum 的输入范围,并补测试:只改统计配置时,仅 Web 更新;修改后端配置时,后端仍正常更新。无需为此大范围重构 Chart。 2. 对齐文档与验收记录
一键部署增强可以另开 PR,不要求本次完成。 建议后续在现有
已有统计平台的部署方跳过第一步。文档说明网络连通、密钥复用、升级和备份即可,不必为了“一键”增加自动创建网站的逻辑。 当前 PR 保留现有配置化接入和可选 Compose 方式即可。完成上述 Helm 隔离和文档调整后,我们再核验受影响部分。 |
|
感谢细致的核验,两部分都已按建议调整,新 head 是 1. Helm 统计配置隔离 统计的两个值从共享 ConfigMap 移到 Web 专用的
在旧模板上跑这组测试会失败;我也试过把统计值同时留在共享 ConfigMap,测试同样会拦下。 2. 文档与验收记录
一键部署按你们的建议另开 PR。辛苦再核验一下受影响的部分。 |
Move analytics values into a Web-only ConfigMap. The server checksum hashes the shared ConfigMap, so analytics-only changes used to replace server pods. Contract tests render before/after values and assert that analytics-only changes roll only Web while backend changes still roll the server. Docs: Compose restart does not re-read .env.release, old tabs keep the old config, a valid but unknown Umami website returns 400 and stores nothing, and new adapters also need deploy-side validation, proxy endpoints and tests. OpenSpec now separates executed Helm template checks from the real-cluster verification that has not been run. Signed-off-by: 千乘妍 (Xiaoyaner) <258399167+xiaoyaner0201@users.noreply.github.com>
47285e4 to
f8ab71e
Compare
Summary
Refs #989(两步交付的第二步。合并并验证后,可以关闭 #989)
按 #1010 合并时的约定和 OpenSpec
openspec/changes/add-configurable-frontend-analytics/里的 PR-2 部分,把前端动作统计做成「改配置就能开」的可选功能。SKILLHUB_WEB_ANALYTICS_CONFIG(JSON:enabled、adapter、consent、rules、adapterConfig)和SKILLHUB_WEB_ANALYTICS_UPSTREAM(统计平台地址,只在部署侧使用,不会下发到浏览器)。不需要改 JS、复制文件或手写 Nginx。enabled:false、consent:denied或配置写错时,不加载采集模块和 SDK,也不发请求;页面启动不等待统计平台。web/src/features/analytics/(通用类型、controller、loader、静态注册表、adapters/umami)。feat(web): add passive semantic analytics attributes across frontend workflows #1010 的两组测试一起迁入,断言没有改动。通用部分不认识 Umami 的字段,以后加平台只需新增一个注册的 adapter。/_skillhub-analytics/代理。只放行 Umami 的script.js和api/send,其他路径都返回 404,不暴露管理界面。HTTPS 上游会校验证书并带正确的 SNI;代理会去掉 Cookie、Authorization、Referer。保留前缀已同步到20-base-path.sh、base-path-config.ts、validate-release-config.sh和 Helm 校验。子路径部署可用。runtime-config.js,浏览器端按数据解析。代价是多了一个约 90 行、有测试覆盖的小解析器。compose.release.yml、.env.release.example和 Helm 的 values、schema、ConfigMap、Deployment 都已透传,默认关闭。新增可选的compose.analytics-umami.yml,用来自托管 Umami 和它自己的 Postgres:必须显式提供密码,管理端口只绑本机,不额外增加 Nginx。docs/frontend-analytics-integration.md改写成只改配置的中文接入指南,内容包括已有 Umami、自托管组合、动态授权、验收、排障、升级和关闭;docs/frontend-analytics.md更新为英文契约。docs/examples/analytics/只保留一个指路说明。OpenSpectasks.md只勾选了本 PR 实际完成的项目。Validation
基于
6c276d38(当前 main),headf8ab71e2。另外做了本地真实运行验收:用本 PR 构建的前端、仓库里的 Nginx 模板和启动脚本,配合 Umami 3.4.1 与 Postgres,在真实 Chrome 中完成 26 项检查,Umami 实际入库 9 条事件。检查覆盖:
stop()后不再发送/skillhub/子路径部署SkillHub 后端 API 是合成响应,不能作为后端业务的端到端证明。
还没覆盖的部分:
Risk
/_skillhub-analytics/成为保留前缀,SKILLHUB_WEB_BASE_PATH不能以它开头。修改配置后需要重新创建 Web(Compose 用up -d --force-recreate web,restart不会重新注入环境变量),新打开的页面才会生效;已经打开的旧标签页不会因关闭配置立即停止,需要刷新或关闭。Helm 的统计值放在 Web 专用 ConfigMap,只改统计配置时仅 Web 滚动更新,后端 Pod 不替换。SKILLHUB_WEB_ANALYTICS_CONFIG并重新创建 Web,新页面即完全关闭;回退镜像版本也可以。Notes
api/send返回400 Website not found,事件不入库。排障表已补充。docs/frontend-analytics-integration.md、docs/frontend-analytics.md、docs/09-deployment.md和 chart README 的入口链接。English
Refs #989 (second step; #989 can be closed once this is merged and verified).
Implements the PR-2 part of
openspec/changes/add-configurable-frontend-analytics/, as agreed when #1010 was merged:SKILLHUB_WEB_ANALYTICS_CONFIG(JSON:enabled,adapter,consent,rules,adapterConfig) andSKILLHUB_WEB_ANALYTICS_UPSTREAM(deploy-side origin, never sent to the browser) through Docker/Compose or Helm. No JS, file copying or hand-written Nginx.enabled:false,consent:deniedor invalid config means no analytics chunk, no SDK and no request. App startup never waits on the collector.web/src/features/analytics/(types, controller, loader, static registry,adapters/umami). Both feat(web): add passive semantic analytics attributes across frontend workflows #1010 test suites moved with their assertions unchanged. Generic code has no Umami fields, and new platforms are added as registered adapters.script.jsandapi/sendare proxied under/_skillhub-analytics/; all other paths return 404. HTTPS upstreams are verified with correct SNI, and Cookie, Authorization and Referer are stripped. The reserved prefix is synced across the base-path checks and Helm validation, and sub-path deployment works.runtime-config.js, where the browser parses it as data. The trade-off is a small, tested parser of about 90 lines..env.release.exampleand Helm values, schema, ConfigMap and Deployment pass the config through, with analytics off by default. The optionalcompose.analytics-umami.ymloverlay self-hosts Umami and its own Postgres, requires explicit secrets, binds the admin port to loopback only and adds no extra Nginx.docs/examples/analytics/is now a pointer only. OpenSpec ticks cover only the work done in this PR.Validation at head
f8ab71e2on base6c276d38:unbound variablefrom forwarded-proto also appears on main.helm lint --strictandconfiguration-contracts.shpass (helm 3.19.0 container). Analytics lives in a Web-only ConfigMap; the contract test asserts analytics-only changes roll only Web and backend changes still roll the server. These are template checks; no real-cluster install was run.A local real-runtime run (this PR's dist with the repo's Nginx template and entrypoints, plus Umami 3.4.1, Postgres and real Chrome) passed 26 checks, with 9 events stored. Covered: default zero requests, enabled loading, allowlisted payload, invalid config, DNS failure and collector downtime isolation, 404 for unregistered paths,
stop(),/skillhub/sub-path and a 5 MiB upload. SkillHub API responses were synthetic.Not run locally:
Rollback: clear
SKILLHUB_WEB_ANALYTICS_CONFIGand recreate Web (docker compose restartdoes not re-read the env file). Old tabs keep collecting until reloaded or closed.Notes: new platforms need a registered adapter plus deploy-side validation, proxy endpoints and tests. A valid UUID for a website that does not exist in Umami gets
400 Website not foundand stores nothing; passing config validation does not prove collection.