Skip to content

feat(metadata): 同步 Consul Feature Flag 配置至 Redis - #11711

Open
Zhaoyikaiii wants to merge 5 commits into
TencentBlueKing:masterfrom
Zhaoyikaiii:feat/metadata-feature-flag-consul-redis
Open

feat(metadata): 同步 Consul Feature Flag 配置至 Redis#11711
Zhaoyikaiii wants to merge 5 commits into
TencentBlueKing:masterfrom
Zhaoyikaiii:feat/metadata-feature-flag-consul-redis

Conversation

@Zhaoyikaiii

@Zhaoyikaiii Zhaoyikaiii commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

变更内容

  • 不新增 Feature Flag 数据表、迁移或 Admin 管理入口。
  • Consul 中的既有 Feature Flag 完整快照是事实源;metadata 每 10 分钟读取该快照,并同步到 Unify Query Redis Provider 使用的 Key。
  • Consul 快照缺失或为空时删除 Redis 中的旧值并发布变更通知,使 UQ 清除旧配置;非法 JSON、Redis 写入或发布失败都会令任务失败并上报。
  • 使用既有分布式锁和任务状态指标,避免并发同步。

与消费端的关系

本 PR 对应 bkmonitor-datalink #1195。启用 feature_flag.data_source=redis 后,Unify Query 从 Redis 消费由本任务同步的快照;未切换前仍保持 Consul 默认消费,不改变现网行为。

验证

  • ruff check:通过
  • Python compileall:通过
  • git diff --check:通过
  • 聚焦 pytest 已尝试;当前环境缺少 bk_monitor_base / ai_agent,Django 在测试收集前无法初始化,需要 CI 或标准 bk-monitor 环境完成测试。

@github-actions

Copy link
Copy Markdown

请在 PR 中添加类型标签,例如:fixfeatdocsstylerefactortestchoremerge, perf

@github-actions

Copy link
Copy Markdown

请在 PR 中添加项目标签,例如:project/monitorproject/apmproject/logproject/publicproject/aiops

@Zhaoyikaiii Zhaoyikaiii added feat A new feature. Correlates with MINOR in SemVer project/monitor project monitor labels Jul 29, 2026 — with ChatGPT Codex Connector

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40ffe419fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread feature_flag_manual.py Outdated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 629ccc4bd0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 93e63e0345

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread feature_flag_manual.py Outdated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8cfadc7758

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/models/feature_flag.py Outdated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7afef0e64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/tests/test_feature_flag.py Outdated
Comment thread bkmonitor/metadata/tests/test_feature_flag.py Outdated
Comment thread bkmonitor/metadata/tests/test_feature_flag.py Outdated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 59e13f31cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Zhaoyikaiii

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acef2412be

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/admin.py Outdated
@Zhaoyikaiii

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73848d27c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
Comment thread bkmonitor/metadata/models/feature_flag.py Outdated
@Zhaoyikaiii

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: b3261649b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Zhaoyikaiii

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 4536151e4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Zhaoyikaiii
Zhaoyikaiii marked this pull request as ready for review July 30, 2026 08:06
@Zhaoyikaiii
Zhaoyikaiii force-pushed the feat/metadata-feature-flag-consul-redis branch 2 times, most recently from c6c56fb to bc4727c Compare July 31, 2026 04:00
@Zhaoyikaiii Zhaoyikaiii changed the title feat(metadata): 支持将 Feature Flag 配置同步到 Consul 与 Redis feat(metadata): 同步 Redis Feature Flag 配置至 Consul Jul 31, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc4727cc43

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/tests/test_feature_flag.py
@Zhaoyikaiii
Zhaoyikaiii force-pushed the feat/metadata-feature-flag-consul-redis branch 2 times, most recently from a727d45 to e517bb4 Compare July 31, 2026 04:11
@Zhaoyikaiii

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: e517bb4c1e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Zhaoyikaiii
Zhaoyikaiii force-pushed the feat/metadata-feature-flag-consul-redis branch from e517bb4 to df88432 Compare July 31, 2026 06:13
@Zhaoyikaiii Zhaoyikaiii changed the title feat(metadata): 同步 Redis Feature Flag 配置至 Consul feat(metadata): 同步 Consul Feature Flag 配置至 Redis Jul 31, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df88432587

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/feature_flag.py Outdated
Comment thread bkmonitor/metadata/feature_flag.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d30303d7e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bkmonitor/metadata/feature_flag.py
Comment thread bkmonitor/metadata/feature_flag.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52fbc7d87d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +95 to +96
if marker != payload_digest:
raise RuntimeError("feature flag migration already completed with a different snapshot")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip completed migrations after Redis flags evolve

After cutover, when the Redis-backed feature-flag publisher legitimately updates the target snapshot, the completion marker still contains the digest of the original Consul snapshot, so this comparison raises instead of honoring the completed migration. Any later deployment or operator retry of migrate_feature_flag_to_redis therefore ends in CommandError despite the migration having succeeded and the current Redis data being valid; treat the marker as an immutable completion indicator rather than requiring the live target to retain its migration-time digest.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat A new feature. Correlates with MINOR in SemVer project/monitor project monitor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant