Send RESET event upon window expiry#13874
Conversation
There was a problem hiding this comment.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
| Comment | Accepted (Y/N) | Reason |
|---|---|---|
| #### Log Improvement Suggestion No: 1 | ||
| #### Log Improvement Suggestion No: 2 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesThrottleStreamProcessor RESET Event Emission
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@components/apimgt/org.wso2.carbon.apimgt.throttling.siddhi.extension/src/main/java/org/wso2/carbon/apimgt/throttling/siddhi/extension/ThrottleStreamProcessor.java`:
- Around line 168-181: The issue is that the old representative event in
expiredEventChunk is being cleared after new window events are added to it,
causing loss of the first event reference needed for the RESET event. To fix
this in the ThrottleStreamProcessor's process method, capture the first event
from expiredEventChunk before iterating through and adding new cloned stream
events (before the condition checking null == expiredEventChunk.getFirst()),
clear the expiredEventChunk before processing new events to separate old and new
data, and then after the iteration completes, use the captured old event to
construct and emit the RESET event via streamEventCloner.copyStreamEvent() and
streamEventChunk.add(resetEvent) instead of attempting to get it after clearing.
🪄 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
Run ID: 99b02a12-a059-4d27-9527-9a3e5116640a
📒 Files selected for processing (1)
components/apimgt/org.wso2.carbon.apimgt.throttling.siddhi.extension/src/main/java/org/wso2/carbon/apimgt/throttling/siddhi/extension/ThrottleStreamProcessor.java
There was a problem hiding this comment.
Pull request overview
Updates the custom Siddhi throttling timeBatch window implementation to emit a RESET event when a time window expires (per wso2/api-manager#5064), enabling downstream throttling aggregations to reset state on window boundaries.
Changes:
- Renames the internal “send events” flag to
sendResetEventto reflect the new semantics. - Emits a
StreamEvent.Type.RESETevent on window expiry instead of forwarding anEXPIREDevent. - Avoids storing more than one template event in
expiredEventChunk(only the first is retained).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@components/apimgt/org.wso2.carbon.apimgt.throttling.siddhi.extension/src/test/java/org/wso2/carbon/apimgt/throttling/siddhi/extension/ThrottleTimeBatchWindowTestCase.java`:
- Around line 173-185: The test method does not guarantee that
executionPlanRuntime.shutdown() executes if an assertion fails before reaching
that line, potentially leaving the Siddhi runtime running. Wrap all the code
from executionPlanRuntime.start() through the assertion checks in a try block,
then place executionPlanRuntime.shutdown() in a finally block to ensure the
runtime is always properly shut down regardless of whether any assertion fails.
- Around line 156-180: The currentEvents ArrayList is written to asynchronously
by the QueryCallback.receive method on a callback thread while being read by the
main test thread at line 180, creating a race condition. Replace the plain
ArrayList with a thread-safe collection like CopyOnWriteArrayList to ensure
thread-safe access to events. Additionally, instead of relying on fixed sleep
durations (the Thread.sleep calls), implement a wait mechanism (such as using
CountDownLatch or a polling loop with timeout) to ensure the expected number of
events have arrived before attempting to access the currentEvents collection in
the firstEventAfterReset assignment. This will eliminate the flaky behavior
caused by timing-dependent assertions.
🪄 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
Run ID: 61d9a92b-cebf-4987-8d76-c31a4a2d96fe
📒 Files selected for processing (1)
components/apimgt/org.wso2.carbon.apimgt.throttling.siddhi.extension/src/test/java/org/wso2/carbon/apimgt/throttling/siddhi/extension/ThrottleTimeBatchWindowTestCase.java
$subject
Ref: wso2/api-manager#5064