Skip to content

Conversation

@hauleth
Copy link
Contributor

@hauleth hauleth commented Apr 24, 2025

Output logs in line JSON format (JSON object per line) in format that is as similar to the format that is expected by the Logflare as possible.

The idea there is to log to the Vector which will then take care of logging to file(s) and to dispatch the logs to Logflare.

It provides 3 new ENV variables that we need to set in deployment:

  • SUPAVISOR_LOG_FILE_PATH=<path> - path to file where we want to store our logs. These logs are automatically rotated and up to 5 files (each max 8 MiB, though I think we can make it configurable or larger) are stored
  • SUPAVISOR_LOG_FORMAT=json to output logs in Logflare JSON format
  • SUPAVISOR_ACCESS_LOG_FILE_PATH=<path> - path to access log for fail2ban processing

That is current approach. I also started using SUPAVISOR_ prefix to all (new) environment variables that are used to configure Supavisor, to easily scan for variables that we are defining. Current uses of Logflare will work as is, that behaviour is not removed, but the Supavisor will log to stdout (or file if specified) by default now. I wonder whether we should always log to stdout and log to file in addition to logging to stdout. That is open and that is almost one line change if needed.

This module https://github.com/supabase/supavisor/pull/653/files#diff-fcb4c5de26c4fdbe08d536956db8eb369be522fa167e1c43638c936caa9684b4 would probably need to be exported to some new Logflare library (cc @Ziinc), but for simplicity it is currently in Supavisor. I haven't yet written proper test for it.

I also have added new metadata field for logs in ClientHandler - state. It contains the connection state at the time of log. It is mostly useful for logging access logs (as these are heavily limited) where I log only events in exchange state (as it is where all connection failures happen). I also set logger metadata much earlier in the connection setup to be able to see all that info ASAP.

This code also utilises new JSON module in Elixir, so it requires fairly recent (1.18) Elixir and OTP 27+.

@hauleth hauleth force-pushed the json-log-format branch 3 times, most recently from 7acd329 to ad6fd9c Compare April 29, 2025 11:44
@hauleth hauleth marked this pull request as ready for review May 11, 2025 11:27
@hauleth hauleth requested a review from a team as a code owner May 11, 2025 11:27
Copy link
Contributor

@abc3 abc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 🔥 🔥

@abc3
Copy link
Contributor

abc3 commented May 15, 2025

would be interesting to stress test EC2 with heavy writes and see how IOPS react 🤔

@hauleth hauleth force-pushed the json-log-format branch 12 times, most recently from 84167fc to 087f7ec Compare May 19, 2025 12:35
@hauleth hauleth force-pushed the json-log-format branch 2 times, most recently from 97bde4d to 27f174e Compare May 31, 2025 15:57
hauleth added 6 commits June 11, 2025 14:39
Output logs in line JSON format (JSON object per line) in format that is
as similar to the format that is expected by the Logflare as possible.

The idea there is to log to the Vector which will then take care of
logging to file(s) and to dispatch the logs to Logflare.
@hauleth hauleth merged commit 7487b81 into main Jun 11, 2025
16 of 20 checks passed
@hauleth hauleth deleted the json-log-format branch June 11, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants