feat: add --alter-logs-indexes-retention-days flag - #703
Conversation
Add a sync/migrate flag that overrides num_retention_days on logs indexes where the field is present, mirroring the existing --alter-flex-logs-retention-days flag (which overrides num_flex_logs_retention_days). Both use insert-if-present semantics: the override is applied only when the flag is set and the field already exists on the resource, so a resource lacking the field is never modified. Refactor pre_resource_action_hook to drive both overrides from a single _RETENTION_OVERRIDES table of (config attribute, resource field) pairs, keeping the flex behavior byte-for-byte identical while making future retention overrides trivial to add.
|
Reviewed this end-to-end — nice addition. The new What I validated:
Non-blocking suggestion: add a migrate-path invalid-value case (parallel to the sync invalid-value test), since this option is shared across both commands. |
michael-richey
left a comment
There was a problem hiding this comment.
Completed a code + test review; details captured in the PR comment. No blocking issues found.
Parametrize test_cli_rejects_invalid_logs_indexes_retention_days across both sync and migrate, mirroring the acceptance test, so the shared --alter-logs-indexes-retention-days option is rejected for invalid values on both commands.
|
Thanks for the review. Addressed the non-blocking suggestion in 12d4fdb: |
Summary
Add a new
sync/migrateflag,--alter-logs-indexes-retention-days, that overrides the standard (non-flex) retention window on logs indexes. It mirrors the existing--alter-flex-logs-retention-daysflag, which overrides the flex-tier retention window.Motivation
--alter-flex-logs-retention-daysalready lets operators overridenum_flex_logs_retention_dayson synced logs indexes. There was no equivalent for the standard retention field,num_retention_days. This adds the symmetric flag so operators can adjust non-flex retention during sync/migrate without editing imported state by hand.Behavior
--alter-logs-indexes-retention-days,type=IntRange(min=30),default=None._sync_options, so it is available on bothsyncandmigrate(same as the flex flag).LogsIndexes.pre_resource_action_hook, when the flag is set andnum_retention_daysis already present on the resource, the field is overwritten with the supplied value. Insert-if-present semantics: a resource that lacks the field is never modified — the field is never added, only overridden. This matches the flex flag exactly.Implementation
pre_resource_action_hookpreviously had a single hardcoded block for the flex field. Rather than duplicating it for the new field, the hook now drives both overrides from a class-level table:The flex behavior is byte-for-byte identical to before; future retention overrides are now a one-line table addition.
Config plumbing (
Configurationdataclass field,build_configkwargs extraction, constructor kwarg) follows the same pattern as the flex flag.Tests
New file
tests/unit/test_logs_indexes_retention.py(mirrorstest_logs_indexes_flex_retention.py):syncandmigrate(flag value reachesrun_cmdasalter_logs_indexes_retention_days).invalid,-1,0,29— below themin=30floor).num_retention_days.num_retention_daysto a resource lacking it.None) preserves the existingnum_retention_days.All values are synthetic (
index-test, integer day counts).Test plan
tox -e py311 -- tests/unit/test_logs_indexes_retention.py tests/unit/test_logs_indexes_flex_retention.py— 20 passedtox -e ruff— cleanpytest tests/unit) — no new failures vs.origin/main(9 pre-existing subprocess-test failures are unrelated and reproduce on cleanmain)