Prevent triggering queries from logging
Prevent triggering queries from logging
This will raise an exception in development and log it in production when logging an application context would trigger an exception.
The lazy attributes are put in place to prevent just that. But this means that calling the lazy attribute should query for it. We can do that by reading a variable inside the proc, rather than calling a method that would load the object.
Because we're sometimes logging early in the request cycle, before
resources are loaded, we need to make sure we don't memoize these
nils. So now, the LazyAttributes
only memoize nils when they had
received an invalid type. In other cases, when the value was still
nil
it will retrigger the block.
We also include the context in error logging, so we need to exclude enforcing the limit there, to avoid the recursion it would cause.
Lazily push user & project into logging-context
This avoids some queries triggered when logging the ApplicationContext
from an internal API call. By using the ivar to access @project
or
@actor
we avoid loading the information. We'll still log the
information if it was already loaded at the time we want to log.
Preload logging attributes before logging context
We do this so the logging itself would not trigger any queries. Most
of the time, we just need to preload the route on a group or
project. We can do this through the new
Routable#preload_for_logging
.
In the case of runner-client, we deduct the context from either the project linked to the runner, or the group linked to it.
Add documentation to Gitlab::Utils::LazyAttributes