Skip to content

Conversation

@grindtildeath
Copy link
Contributor

[REF] rest_log: Add hooks to read configuration from system params

This allows to use the same syntax than the existing one from
rest.log.active to define other config parameters.

[IMP] rest_log: Allow printing server logs on incoming requests

Werkzeug logs are only generated when Odoo answers HTTP requests,
whereas this will allow to know whenever a request is dispatched
through rest services.

[IMP] rest_log: Allow to profile requests through rest services

Leverage ir.profile machinery to track what happens when a user
calls some rest services.

Since profiling can be done only for a single user at a time the
system parameter rest.log.profiling.uid has to be defined with
the ID from res.users whose calls need to be profiled.

Moreover, system parameter rest.log.profiling.conf can be defined
using the syntax from rest.log.active to fine tune which requests
will trigger the profiling for the user defined by the previous
parameter.

To note, once a request is identified to start the profiling, all
incoming requests from the user will be profiled until the timeout
duration defined by rest.log.profiling.duration is reached.

This allows to use the same syntax than the existing one from
rest.log.active to define other config parameters.
Werkzeug logs are only generated when Odoo answers HTTP requests,
whereas this will allow to know whenever a request is dispatched
through rest services.
Leverage ir.profile machinery to track what happens when a user
calls some rest services.

Since profiling can be done only for a single user at a time the
system parameter rest.log.profiling.uid has to be defined with
the ID from res.users whose calls need to be profiled.

Moreover, system parameter rest.log.profiling.conf can be defined
using the syntax from rest.log.active to fine tune which requests
will trigger the profiling for the user defined by the previous
parameter.

To note, once a request is identified to start the profiling, all
incoming requests from the user will be profiled until the timeout
duration defined by rest.log.profiling.duration is reached.
@OCA-git-bot
Copy link
Contributor

Hi @simahawk,
some modules you are maintaining are being modified, check this out!

Copy link
Contributor

@simahawk simahawk left a comment

Choose a reason for hiding this comment

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

early review, to be tested.

_log_calls_in_db = False

def dispatch(self, method_name, *args, params=None):
if self._server_debug_logging_active(method_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we really need an IF here. All in all we can control this with debug levels.

profiling_duration = 10
try:
profiling_duration = int(
self.env["ir.config_parameter"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to take care of such params?
We can simply set base.profiling_enabled_until when we set the other params.
We'll reduce complexity here. In fact, we could simply check if profiling is enable by calling ir.profile._enabled_until()

_logger.warning(
"System parameter rest.log.profiling.duration is not defined. Profiling will be active for the next 10 minutes"
)
profiling_enabled_until = fields.Datetime.now() + relativedelta(
Copy link
Contributor

Choose a reason for hiding this comment

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

missing imports

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.

3 participants