Search: Use content-hash-versioned enrich policy names#3105
Conversation
Enrich policies can't be updated or deleted while referenced by a pipeline. Version the policy name with a SHA256 hash of its definition so re-runs reuse the existing policy, and definition changes create a new one alongside the old. After the pipeline is updated to reference the new policy, old policies are cleaned up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Elastic.Markdown/Exporters/Elasticsearch/ContentDateEnrichment.cs`:
- Around line 203-221: The current 8-char suffix from ComputePolicyHash is too
short and can cause silent collisions; change ComputePolicyHash to return a
longer, safer digest (e.g., full hex or at least 16 chars) and, in the
enrich-policy creation flow where you inspect response.Body / errorType and
handle "resource_already_exists_exception", fetch the existing policy definition
(GET _enrich/policy/{PolicyName}) and compare its full JSON to
BuildPolicyBody().ToJsonString(); only treat the error as a no-op if the
definitions match, otherwise throw a clear InvalidOperationException mentioning
PolicyName and the mismatch. Ensure you reference ComputePolicyHash,
BuildPolicyBody, PolicyName and the existing response/errorType handling when
making these changes.
- Around line 253-255: The current filter (in ContentDateEnrichment.cs around
the block referencing PolicyBaseName and PolicyName) uses
name.StartsWith(PolicyBaseName) which is too broad; change the check so it only
matches the exact versioned naming scheme used by your code (e.g., require the
PolicyBaseName + delimiter and a version token/hash), for example by validating
the suffix with a strict pattern or regex (e.g., ensure
name.StartsWith(PolicyBaseName + "-") and the remainder matches the expected
hash/ GUID/length/hex format) and keep the existing exclusions for null and
PolicyName; update the condition that currently reads name == null || name ==
PolicyName || !name.StartsWith(PolicyBaseName, ...) to instead reject names that
do not conform to the versioned-name pattern.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c4c86446-a970-4cc6-a834-1ba83305827e
📒 Files selected for processing (1)
src/Elastic.Markdown/Exporters/Elasticsearch/ContentDateEnrichment.cs
What
Version enrich policy names with a SHA256 hash of their definition so re-runs don't fail on
resource_already_exists_exception.Why
Elasticsearch enrich policies can't be updated or deleted while referenced by an ingest pipeline. On repeated CI runs,
PutEnrichPolicyAsyncwould try to create a policy that already exists and fail with a 400 error.How
...-policy-a1b2c3d4)CleanupOldPoliciesAsyncTest plan
Notes
Cleanup of old policies is best-effort — if deletion fails (e.g., still referenced by another pipeline), it logs a warning and continues.
🤖 Generated with Claude Code