Logging sometimes reports wrong database in multisite

AI-generated summary

The discussion revolves around an issue where Rails logs in a multisite Discourse setup sometimes report incorrect databases, likely due to a race condition in logging. Users michaeld, sam, and tgxworld acknowledge the problem and suggest that the current log format is problematic. sam proposes adopting lograge as a better, more parsable logging solution, which tgxworld has already implemented with a hidden setting. The team is considering making lograge the default, with codinghorror and pfaffman supporting this move. dscat adds that while lograge is useful, the default KeyValue formatter complicates integration with their JSON-based logging stack, and has proposed a PR to allow overriding the formatter via an environment variable.

I was investigating an issue and it seems like the lines in production.log sometimes report the wrong database.

I’ve seen this a few times before, so this is not a single incident. Here’s a good and clear example where you can see that the third line has been logged as belonging to database db3785 where it obviously is about the same request as the fourth line, which is logged as belonging to db9210.

image

I was unable to pinpoint the responsible code, it might be deep inside Rails, and this is probably a race condition.

v1.8.x on Unicorn.

No, we’re not using Docker, no, I don’t think that matters here, and no, I don’t expect a quick solution.
Just letting you guys know what we are seeing :slight_smile:

1 лайк

Rails logs are a trashfire, we plan to start using a new format in future

6 лайков

I’ll put this on my list first, it seems like the connection is switched even before logging is complete.

6 лайков

This is really unsolvable with the current log format. @tgxworld is going to investigate making GitHub - roidrage/lograge: An attempt to tame Rails' default policy to log everything. · GitHub an optional (and hopefully default) log format for rails to avoid this mess and give us properly parsable log files.

3 лайка

Note that lograge can now be enabled via a hidden SiteSetting.logging_provider or setting ENABLE_LOGRAGE to 1. We’ll be testing this on our servers for awhile before deciding if lograge should be the default for all Discourse users.

4 лайка

Is lograge the default now?

1 лайк

Nope but we can make it so.

3 лайка

Я перемещаю это в Contribute > Feature, так как у нас уже есть система, которая хорошо работает для мультисайтов, а мультисайты встречаются крайне редко.

Я не против перейти на lograge по умолчанию в долгосрочной перспективе — это даст Discourse Doctor больше аргументов.

3 лайка

lograge seems like a vast improvement and it took me forever to find this topic to find how to start it.

Is it too soon to un-hide the site setting?

Would it be disastrous to change the default to lograge for new installs?

It’s not immediately clear what discourse-doctor might do, grep for “Error”, but having some logs around to look at is a first step. . .

Yeah @tgxworld let’s make lograge the default?

Привет,

в нашей организации мы используем lograge/graylog для всех наших приложений и применяем JSON-форматер, так как он предоставляет более удобный способ анализа проблем.

Мы внедряем форум на базе Discourse, который поддерживает опцию lograge, но использует форматер KeyValue, что усложнило бы нашу настройку.

У меня есть PR adding a lograge formatter env var by dscataglini · Pull Request #12206 · discourse/discourse · GitHub, в котором форматер по умолчанию остаётся KeyValue, как сейчас, но появляется возможность переопределить его, указав переменную окружения LOGRAGE_FORMATTER.

1 лайк