-
-
Notifications
You must be signed in to change notification settings - Fork 368
[18.0][IMP] rest_log: add profiling #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
grindtildeath
wants to merge
11
commits into
OCA:18.0
Choose a base branch
from
camptocamp:18.0-imp-server_logs_and_profiling
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cf0dfe4
[REF] rest_log: Add hooks to read configuration from system params
grindtildeath e589ae4
[IMP] rest_log: Allow to profile requests through rest services
grindtildeath 5ad3655
[IMP] rest_log: use Profiler
simahawk d98f506
[IMP] rest_log: simplify configuration
simahawk 92835f8
[IMP] rest_log: profile more than one user at once
simahawk 002ecd2
[IMP] rest_log: split exception tests
simahawk 582e759
[IMP] rest_log: improve profiling and add tests
simahawk 95389e0
fixup! [IMP] rest_log: improve profiling and add tests
simahawk b612bc5
fixup! fixup! [IMP] rest_log: improve profiling and add tests
simahawk ed1546d
[DOC] rest_log: update readme
simahawk 179fdd3
fixup! fixup! [IMP] rest_log: improve profiling and add tests
simahawk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| from odoo.http import Response, request | ||
| from odoo.modules.registry import Registry | ||
| from odoo.service.model import PG_CONCURRENCY_ERRORS_TO_RETRY | ||
| from odoo.tools.profiler import Profiler | ||
|
|
||
| from odoo.addons.base_rest.http import JSONEncoder | ||
| from odoo.addons.component.core import AbstractComponent | ||
|
|
@@ -41,6 +42,9 @@ class BaseRESTService(AbstractComponent): | |
| def dispatch(self, method_name, *args, params=None): | ||
| if not self._db_logging_active(method_name): | ||
| return super().dispatch(method_name, *args, params=params) | ||
| if self._start_profiling(method_name): | ||
| with self._profiling_get_profiler(): | ||
| return self._dispatch_with_db_logging(method_name, *args, params=params) | ||
| return self._dispatch_with_db_logging(method_name, *args, params=params) | ||
|
|
||
| def _dispatch_with_db_logging(self, method_name, *args, params=None): | ||
|
|
@@ -224,3 +228,46 @@ def _get_matching_active_conf(self, method_name): | |
| return self.env["rest.log"]._get_matching_active_conf( | ||
| self._collection, self._usage, method_name | ||
| ) | ||
|
|
||
| def _start_profiling(self, method_name): | ||
| if request.session.profile_session and request.db: | ||
| return None | ||
| profiling_uids = self._profiling_get_uids() | ||
| profiling_conf_match = self._profiling_get_matching_conf(method_name) | ||
| res = profiling_conf_match and self.env.uid in profiling_uids | ||
| if res: | ||
| _logger.info( | ||
| "Profiling enabled for uids=%s %s", | ||
| str(profiling_uids), | ||
| f"{self._collection}.{self._usage}.{method_name}", | ||
| ) | ||
| return res | ||
|
|
||
| def _profiling_get_uids(self): | ||
| try: | ||
| param = ( | ||
| self.env["ir.config_parameter"] | ||
| .sudo() | ||
| .get_param("rest.log.profiling.uids", "") | ||
| ) | ||
| if not param.strip(): | ||
| return [] | ||
| return [int(x.strip()) for x in param.strip().split(",") if x.strip()] | ||
| except ValueError as err: | ||
| _logger.warning( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should return None after ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no valid uid is found, then profiling_uid is set to 0, which never matches self.env.uid. |
||
| "Cannot get uid from system parameter rest.log.profiling.uid: %s", | ||
| str(err), | ||
| ) | ||
| return [] | ||
|
|
||
| def _profiling_get_matching_conf(self, method_name): | ||
| return self.env["rest.log"]._get_matching_conf_from_param( | ||
| "rest.log.profiling.conf", self._collection, self._usage, method_name | ||
| ) | ||
|
|
||
| def _profiling_get_profiler(self, method_name): | ||
| call_name = f"{self._collection}.{self._usage}.{method_name}" | ||
| return Profiler( | ||
| description=f"REST LOG {call_name}", | ||
| profile_session=f"{self.env.user.name} (uid={self.env.uid})", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from . import test_db_logging | ||
| from . import test_db_logging_exception |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.