-
-
Notifications
You must be signed in to change notification settings - Fork 101
Forward logs to Discord #579
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
Merged
Merged
Conversation
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
Mom0aut
reviewed
Sep 26, 2022
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogForwarder.java
Outdated
Show resolved
Hide resolved
Mom0aut
reviewed
Sep 27, 2022
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogForwarder.java
Outdated
Show resolved
Hide resolved
Tais993
reviewed
Sep 29, 2022
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogForwarder.java
Show resolved
Hide resolved
927f820
to
9f0fc4b
Compare
a week old, a semi approval. merging this |
9f0fc4b
to
d395ad0
Compare
Kudos, SonarCloud Quality Gate passed! |
Tais993
reviewed
Oct 4, 2022
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogAppender.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogForwarder.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogForwarder.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogForwarder.java
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/logging/discord/DiscordLogForwarder.java
Show resolved
Hide resolved
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.
Overview
This is a convenience replacement for the (broken/deactivated) Logviewer project.
It forwards all logs to a Discord channel, via webhooks.
Info/Error channel
The day to day routine will be that we want to be notified when an error/warning happened, but not for info logs. Therefore, we set up 2 channels with separate webhooks. One for errors, one for infos:
Now, users can mute one channel and keep notifications on for the other.
Security
Note that logs can contain sensitive information (for example when banning an user). Therefore, a new log marker
LogMarkers.SENSITIVE
has been added. Logs with that marker are not forwarded to Discord. All existing logs have been checked and adjusted. Looks something like this:Details
Queue
The implementation is relatively straightforward, but has some non trivial complexity. In a nutshell, it buffers all incoming logs in a
PriorityQueue
(ordered on the timestamp to ensure correct log order). The queue has a max size of10_000
logs and ideally is never hit in practice (this is to protect RAM, in case).The queue is then processed each 5 seconds with a
ScheduledExecutorService
. The service then polls and sends a maximum of 10 logs in a batch request to Discord.Failures
If the request fails, the logs are put back into the queue. If a batch fails 3 times, it is discarded to not entirely block the whole mechanism forever.
Rate limitting
When we send too much, Discord hits us with rate limits (
429
http status). When this happens, we extract the end of the limitation from theretry-after
header and skip theScheduledExecutorService
calls untilInstant.now()
is after that time.Logging the logger
The whole system also has logging/error reporting itself. Its logs all have a
LogMarkers.NO_DISCORD
though, to prevent that it forwards its own logs - which could lead to a potential infinite loop of spawning logs in an erroneous scenario.Config
The config has been changed, add:
Checklist