Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check in scheduler #1091

Merged
merged 2 commits into from
Sep 12, 2024
Merged

Check in scheduler #1091

merged 2 commits into from
Sep 12, 2024

Conversation

unflxw
Copy link
Contributor

@unflxw unflxw commented Sep 5, 2024

Part of appsignal/integration-guide#169.

Implement check-in scheduler

Implement a check-in event scheduler, which schedules check-in events
to be transmitted in a separate thread, with a minimum wait period
of ten seconds between requests, and a wait period of a tenth of a
second before the first request, referred to as "debounce" periods.

This is a relatively minor improvement for the existing cron
check-ins, but it is a requirement for the heartbeat check-ins, both
to avoid slowing down customers' applications with blocking requests,
and to avoid misuse of the feature from spamming our servers.

The scheduler also acts as a deduplicator, removing "similar enough"
check-in events -- again, not particularly interesting for cron
check-ins, but a requirement to minimise damage when heartbeat
check-ins are misused.

Implement utility functions for serialising and deserialising NDJSON
payloads.

When an event is scheduled, the scheduler sets a timeout for the
duration of the timeout period, after which the events stored in
the scheduler are transmitted.

When Appsignal.stop is called and awaited, the scheduler is
gracefully stopped, awaiting the transmission of all scheduled
check-in events. During this time, new check-in events cannot be
scheduled.

Avoid probes interval blocking shutdown

The probes instance starts an interval timer on initialisation.
By default, timers cause the Node.js engine to await their
completion on shutdown -- which, this being an interval timer, is
never actually completed. (See #418)

We fixed this in the past by implementing Appsignal.stop, which
clears the interval. But a preferable solution is to mark the
probes' interval as .unref(), telling the Node.js engine that it
does not need to be awaited.

Implement a check-in event scheduler, which schedules check-in events
to be transmitted in a separate thread, with a minimum wait period
of ten seconds between requests, and a wait period of a tenth of a
second before the first request, referred to as "debounce" periods.

This is a relatively minor improvement for the existing cron
check-ins, but it is a requirement for the heartbeat check-ins, both
to avoid slowing down customers' applications with blocking requests,
and to avoid misuse of the feature from spamming our servers.

The scheduler also acts as a deduplicator, removing "similar enough"
check-in events -- again, not particularly interesting for cron
check-ins, but a requirement to minimise damage when heartbeat
check-ins are misused.

Implement utility functions for serialising and deserialising NDJSON
payloads.

When an event is scheduled, the scheduler sets a timeout for the
duration of the timeout period, after which the events stored in
the scheduler are transmitted.

When `Appsignal.stop` is called and awaited, the scheduler is
gracefully stopped, awaiting the transmission of all scheduled
check-in events. During this time, new check-in events cannot be
scheduled.
The probes instance starts an interval timer on initialisation.
By default, timers cause the Node.js engine to await their
completion on shutdown -- which, this being an interval timer, is
never actually completed. (See #418)

We fixed this in the past by implementing `Appsignal.stop`, which
clears the interval. But a preferable solution is to mark the
probes' interval as `.unref()`, telling the Node.js engine that it
does not need to be awaited.
@unflxw unflxw force-pushed the check-in-scheduler branch from 96299f9 to 0f438d6 Compare September 5, 2024 14:31
@backlog-helper

This comment has been minimized.

2 similar comments
@backlog-helper

This comment has been minimized.

@backlog-helper
Copy link


This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

@unflxw unflxw merged commit 0067bb5 into main Sep 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants