fix(apps): validate EventsCompactionConfig.compaction_interval > 0#6399
Open
hiroakis wants to merge 1 commit into
Open
fix(apps): validate EventsCompactionConfig.compaction_interval > 0#6399hiroakis wants to merge 1 commit into
hiroakis wants to merge 1 commit into
Conversation
compaction_interval and overlap_size were plain required ints with no
validation, unlike their sibling fields token_threshold (gt=0) and
event_retention_size (ge=0).
A compaction_interval of 0 (or negative) silently makes the sliding-window
trigger fire on *every* invocation, because the guard in
_run_compaction_for_sliding_window,
if len(new_invocation_ids) < config.compaction_interval:
return None
can never hold. This is an easy foot-gun and is inconsistent with the
validated sibling fields.
Add Field(gt=0) to compaction_interval and Field(ge=0) to overlap_size
(0 = no overlap, which is valid), plus tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add validation to
EventsCompactionConfigsocompaction_intervalmust be> 0andoverlap_sizemust be>= 0, consistent with the sibling fieldstoken_threshold(gt=0) andevent_retention_size(ge=0).Currently
compaction_interval=0(or negative) is silently accepted and makes the sliding-window trigger fire on every invocation, because the guardlen(new_invocation_ids) < config.compaction_intervalin_run_compaction_for_sliding_windowcan never hold.Fixes #6397
Changes
_configs.py:compaction_interval: int = Field(gt=0),overlap_size: int = Field(ge=0)compaction_interval=0/-1andoverlap_size=-1; allowoverlap_size=0Test
pytest tests/unittests/apps/test_compaction.py— 52 passed. pre-commit hooks pass.Note
This PR intentionally keeps the fields required and only adds bounds. Making the sliding-window pair optional (to disable it without a sentinel) is tracked separately in #6398.