Skip to content

Conversation

Zabuzard
Copy link
Member

@Zabuzard Zabuzard commented Sep 21, 2022

Overview

This is a convenience replacement for the (broken/deactivated) Logviewer project.

It forwards all logs to a Discord channel, via webhooks.

example

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:

channel split

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:

logger.warn(LogMarkers.SENSITIVE, "Banned user {} for reason: {}", user, reason);

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 of 10_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 the retry-after header and skip the ScheduledExecutorService calls until Instant.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:

"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>"

Checklist

  • Appender
  • Add to config
  • Configurable webhook
  • Proper embeds
  • Error handling
  • Rate limitting / queue / buffer
  • Split info/error channel
  • Javadoc

@Zabuzard Zabuzard added enhancement New feature or request priority: normal labels Sep 21, 2022
@Zabuzard Zabuzard self-assigned this Sep 21, 2022
@Zabuzard Zabuzard requested review from a team as code owners September 21, 2022 14:23
@Zabuzard Zabuzard marked this pull request as draft September 21, 2022 14:26
@Zabuzard Zabuzard marked this pull request as ready for review September 26, 2022 08:21
@Zabuzard Zabuzard requested a review from Tais993 September 30, 2022 11:36
@Zabuzard Zabuzard force-pushed the feature/logs_to_discord branch from 927f820 to 9f0fc4b Compare September 30, 2022 13:08
@Zabuzard
Copy link
Member Author

Zabuzard commented Oct 4, 2022

a week old, a semi approval. merging this

@Zabuzard Zabuzard force-pushed the feature/logs_to_discord branch from 9f0fc4b to d395ad0 Compare October 4, 2022 08:56
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Zabuzard Zabuzard merged commit 8f60483 into develop Oct 4, 2022
@Zabuzard Zabuzard deleted the feature/logs_to_discord branch October 4, 2022 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priority: normal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants