-
Notifications
You must be signed in to change notification settings - Fork 87
Handle only the latest event with the most up to date state #43
Conversation
🤖 zincr found 0 problems , 0 warnings
|
🤖 zincr found 1 problem , 0 warnings
Details on how to resolve are provided below ApprovalsAll proposed changes must be reviewed by project maintainers before they can be merged Not enough people have approved this pull request - please ensure that 1 additional user, who have not contributed to this pull request approve the changes.
|
So basically if the fetching manages to get any events, you restart it to make sure there is only one event fetched? 🤔 |
@samurang87 Yes. And getting all the events till nothing is left. All events except the last one are therefore ignored — as intended. |
Why will the event we are interested in be fetched rapidly ? And why will the number of event decrease ? |
@parking52 @samurang87 I didn't get your last comments. What number of events decreased? What exactly is fetched rapidly? |
@parking52 @samurang87 See the examples in #42 — there are few objects with few events (e.g. "mycrd-expr1"), of which only the latest is of our interest. |
@parking52 @samurang87 This is efficiently an equivalent of this logic: while queue.qsize() > 0:
event = await queue.get() Except that:
event = None
first_time = True
try:
while first_time or queue.qsize() > 0:
first_time = False
event = await asyncio.wait_for(queue.get(), timeout=5.0)
except asyncio.TimeoutError:
if event is None:
break
# when (event is not None) or (no timeout on the last event), continue. |
With this change, if the queue contains a batch of events, react only to the latest one — to follow the "eventual consistency" principle of Kubernetes.
The batch is time-framed to 0.1s, so that it is fast enough for all normal cases when only one event arrives, but slow enough for the initial object listing when multiple events arrive.
Still, some minimal time-frame is needed, as the streaming and parsing of the events inside of the kubernetes library is not immediate.