Skip to content

Commit 4c313a9

Browse files
committed
Clear stats, routes, etc before sending to bg process
1 parent 113e3d7 commit 4c313a9

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

aikido_zen/thread/thread_cache.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def reset(self):
4444
last_updated_at=-1,
4545
received_any_stats=False,
4646
)
47+
self._clear_synced_deltas()
48+
49+
def _clear_synced_deltas(self):
50+
"""Clears delta counters synced to the background process."""
4751
self.middleware_installed = False
4852
self.hostnames.clear()
4953
self.users.clear()
@@ -55,24 +59,28 @@ def renew(self):
5559
if not comms.get_comms():
5660
return
5761

58-
# send stored data and receive new config and routes
62+
# Clear deltas before the IPC, not after. Clearing post-response would
63+
# wipe any increments that arrived in the window where the IPC released
64+
# the GIL.
65+
payload = {
66+
"current_routes": self.routes.get_routes_with_hits(),
67+
"middleware_installed": self.middleware_installed,
68+
"hostnames": self.hostnames.as_array(),
69+
"users": self.users.as_array(),
70+
"stats": self.stats.get_record(),
71+
"ai_stats": self.ai_stats.get_stats(),
72+
"packages": PackagesStore.export(),
73+
}
74+
self._clear_synced_deltas()
75+
5976
res = comms.get_comms().send_data_to_bg_process(
6077
action="SYNC_DATA",
61-
obj={
62-
"current_routes": self.routes.get_routes_with_hits(),
63-
"middleware_installed": self.middleware_installed,
64-
"hostnames": self.hostnames.as_array(),
65-
"users": self.users.as_array(),
66-
"stats": self.stats.get_record(),
67-
"ai_stats": self.ai_stats.get_stats(),
68-
"packages": PackagesStore.export(),
69-
},
78+
obj=payload,
7079
receive=True,
7180
)
7281
if not res["success"] or not res["data"]:
7382
return
7483

75-
self.reset()
7684
# update config
7785
if isinstance(res["data"].get("config"), ServiceConfig):
7886
self.config = res["data"]["config"]

0 commit comments

Comments
 (0)