Commit graph

99 commits

Author SHA1 Message Date
Aarol D'Souza
c55ff193a6
fix: add type hints to whitelisted methods 3 (#37149)
* fix(apps): add type hints to whitelisted methods

* fix(recorder): add type hints to whitelisted methods

* fix(comments): add type hints to whitelisted methods

* fix(oauth2): add type hints to whitelisted methods

* fix(google_calendar): add type hints to whitelisted methods

* fix(print): add type hints to whitelisted methods

* fix(print_format_builder): add type hints to whitelisted methods

* refactor(network_printer_settings): remove unused args

* fix(document): add type hints to whitelisted methods

* fix(user_settings): add type hints to whitelisted methods

* fix(mapper): add type hints to whitelisted methods

* fix(connected_app): add type hints to whitelisted methods

* fix(google_contacts): add type hints to whitelisted methods

* fix(frappecloud_billing): add type hints to whitelisted methods

* test: rewrite test to fit the strict type check

* fix(social_login_key): add type hints to whitelisted methods

* fix(share): add type hints to whitelisted methods

* fix(webhook): add type hints to whitelisted methods

* fix(workflow): add type hints to whitelisted methods

* fix(workflow main): add type hints to whitelisted methods

* fix(workflow_action): add type hints to whitelisted methods

* fix: flexible type hint

* fix(client): add type hints to whitelisted methods

* fix: fix some of the tighter types

* fix(frappecloud_billing): add str typehint to whitelisted endpoint

* fix: target_doc can be dict/json string

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2026-02-20 06:50:19 +00:00
HENRY Florian
56b2dfeea1
feat: remove strip_dirs in Recorder python cProcfile (#33300) 2025-07-15 17:51:44 +05:30
Sagar Vora
b3e1eda4c8
feat: global frappe.in_test flag (#32960)
* feat: global `frappe.in_test` flag

* feat: helper utility to toggle `frappe.in_test`

* fix: use `toggle_test_mode` util

* fix: use `frappe.in_test`

* chore: add comment explaining global `in_test`

* chore: ignore commit replacing flag usage

* test: temporarily disable `frappe.in_test`

this worked earlier because flag was set in werkzeug.local which was separate for API test client

* test: add comment explaining change
2025-06-17 19:19:31 +05:30
Ankush Menat
856513423f
fix: recorder auto-disable (#32296)
This broke with client cache implementation... oopsie.
2025-04-25 11:32:55 +00:00
Ankush Menat
360d19741e fix(recorder): patch replica DB connection 2025-04-24 11:02:03 +05:30
Ankush Menat
26b1360c50 refactor: Remember patched connections
This way if `frappe.db` changes we don't end up trying to unpatch the
wrong thing.
2025-04-24 10:52:53 +05:30
Sagar Vora
f51781c90a fix: use python feature to limit profiler output 2025-03-20 08:38:25 +05:30
Sagar Vora
521ff071ae perf: compute query type only once 2025-03-15 13:39:57 +05:30
Ankush Menat
b95d741ffe
fix(DX): Limit cprofiler output to 200 lines (#31538)
Most of the time, first 100 lines are all you need, so 200 should be
more than enough.
2025-03-06 06:42:40 +00:00
Ankush Menat
29733febcb refactor: minor cleanup / avoid repeat calls
This get+conditional set is also slightly prone to data races, but
doesn't seem to be harmful as of now.

Rationale:
- To enable recorder one must first send a request, so this should be
  set long before.
- While enabling we can accidentally clear cache for another worker by
  invalidating it, but that is kind of acceptable behaviour. We ONLY set
  it to False when `None` is received from Redis. Local invalidations
  remove it completely.
2025-01-06 18:57:57 +05:30
Ankush Menat
a3c48da7f4 perf: enable client side caching for recorder flag 2025-01-06 18:57:57 +05:30
David Arnold
bd06784d1b
ci: Run optimized python and control warnings (#28063)
* ci: run doubly optimized python

* ci: control python warnings
2024-10-09 13:29:30 +00:00
Ankush Menat
df2b9c0983
fix(recorder): handle frappe.db.sql(run=0) (#25450) 2024-03-14 17:47:37 +00:00
Akhil Narang
26ae0f3460
fix: ruff fixes
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-07 17:04:31 +05:30
Ankush Menat
9107627dac fix: recorder timezone bug
use system timezone to avoid showing incorrect timestamp
2024-02-05 11:37:24 +05:30
Ankush Menat
009b06d974 feat: Jobs/Request filtering 2024-02-05 11:33:31 +05:30
Ankush Menat
e494cb4f6e feat: configurable recording
Configurable behaviours:
- Record SQL queries
- Explain queries
- Record stack frames
- Run profiler
- Filter some requests
2024-02-05 11:33:31 +05:30
Ankush Menat
3c183344aa feat: profile requests using recorder
WIP:
- [x] Basic working feature
- [ ] Make this optional, this has insanely high overhead.
- [ ] Specify requests/function filter to profile/record. This will
  allow better recording in production sites.
- [ ] Make SQL profiling optional too
2024-02-05 11:33:31 +05:30
Ankush Menat
d5d9b12472
test: flaky server tests (#24301)
* Revert "fix(test_recorder): get the correct request (#24143)"

This reverts commit 745080c56e.

* test: disable recording before running assertions

* test: Dont set emails in test for broken email setup
2024-01-15 08:09:46 +00:00
Akhil Narang
745080c56e
fix(test_recorder): get the correct request (#24143)
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-01-06 09:42:53 +05:30
Ankush Menat
3916398f1a
fix(recorder): Normalize IN in SQL queries (#24132) 2024-01-04 19:08:59 +05:30
Akhil Narang
35ea093b51
feat: support background jobs in recorder
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-01-04 15:51:26 +05:30
Ankush Menat
57699a54b1
fix: Show server script name in traceback (#23676)
* fix: Show server script name in traceback

* chore: typo

Co-authored-by: Sagar Vora <sagar@resilient.tech>

---------

Co-authored-by: Sagar Vora <sagar@resilient.tech>
2023-12-08 15:01:13 +05:30
Ankush Menat
961585f1d9
fix: misc dx improvemnts (#22188)
* fix(dx): simplify adding callbacks

frappe.db.after_commit(func) == frappe.db.after_commit.add(func)

* fix: trace id missing

DB gets initted before request
2023-08-28 07:01:25 +00:00
Ankush Menat
074bed9ad6 fix: delete imported recorder file after import 2023-08-10 12:58:01 +05:30
Ankush Menat
5a7348668a Merge branch 'develop' into virtual-doc-for-frappe-recorder 2023-08-10 12:57:16 +05:30
Ankush Menat
40c5dc5426 refactor: flatten file argument in function call 2023-08-10 12:56:40 +05:30
Gursheen Anand
30f17f417b fix: handle file uploader obj while importing 2023-08-05 17:44:00 +05:30
Ankush Menat
8bf8950c2b
fix: include server script in recorder stack trace (#21891)
[skip ci]
2023-08-01 20:59:46 +05:30
Ankush Menat
42aff950ce
feat(DX): normalize queries in recorder (#21735)
Attempt to normalize query by removing "variables"
This gives a different view of similar duplicate queries.

These two are distinct queries:
```sql
select * from user where name = 'x'
select * from user where name = 'z'
```

But their "normalized" form would be same:
```sql
select * from user where name = ?
```

This helps highlight queries ran in loop which might not register as
duplicate but are possibly "duplicate".
2023-07-19 16:45:30 +05:30
Ankush Menat
adf30693a9 ci: update pyupgrade 2023-07-14 14:24:08 +05:30
Ankush Menat
154a6dd9ed
perf: Reduce recorder overhead (#21656)
By processing `EXPLAIN` of queries in background after recording is
completed, the overhead reduces significantly and hence can be used
"more" in production environment too.
2023-07-12 19:34:23 +05:30
Ankush Menat
774a75dbde
perf: use cached workflow doc for transitions (#21300)
* fix: expire `RECORDER_INTERCEPT_FLAG` in one hour

Leaving this running in prod can be dangerous.

* perf: Use cached doc in workflows
2023-06-09 12:43:40 +05:30
Ankush Menat
fa6dc03cc8
refactor: frappe.cache() usage to frappe.cache (#21282) 2023-06-08 11:47:17 +05:30
Ankush Menat
ec3f705e4f
feat: finer frappe Recorder control with decorator (#19220)
Currently frappe recorder can be enabled globally and profiles every
request. This is often way too much info. If you already know where
problem lies you use this decorator sparingly to only profile relevant
functions.

Usage:
```py
from frappe.recorder import record_queries

@record_queries
def sus_slow_function():
    frappe.db.sql("select everything from everywhere")
```
2022-12-09 14:18:49 +05:30
Ankush Menat
bbcc365a24
fix: use monotonic clock for timing code (#19138)
* fix: use monotonic time for timing code

`time.time()` depends on system clock which can drift away and get corrected
over time. If you're unlucky it will get corrected in your timing code
and give absurd results.

* test: dont check for status

can refresh and give wrong output

[skip ci]
2022-12-06 15:42:37 +05:30
Gavin D'souza
c86e1de38a fix(recorder): Publish update only to Administrator 2022-11-15 13:12:51 +05:30
Gavin D'souza
71b5c77e6e Merge branch 'develop' of github.com:frappe/frappe into mariadb-client-refactor 2022-07-05 14:55:02 +05:30
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
2022-07-01 11:51:05 +05:30
Gavin D'souza
bc3780560e perf: Use lazy mogrified query for logging
For parameterized queries, there's an improvement of ~30% in query
execution via frappe.db.sql - from 58.6 µs ± 2.37 µs to 44.6 µs ± 1.56 µs
2022-06-16 14:26:34 +05:30
Gavin D'souza
154d794c6c fix: Recorder to use frappe.db.last_query to pick out last executed stmt 2022-06-16 13:29:35 +05:30
Gavin D'souza
b696fa6da5 perf: Pre-compile and re-use regexp pattern
Converted all possible usages of re.* that weren't compiling the regex
separately and re-using it. Separated out the compiled patterns as
global variables. Repetitive patterns could be made DRY-er.

Would be nicer to have all regexes in a single module so that we could
re-use better, keep track of outdated, and keep checks for possible
reDos' etc
2022-06-08 14:07:38 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
Gavin D'souza
3446026555 chore: Update header: license.txt => LICENSE
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
2021-09-03 12:02:59 +05:30
Ankush Menat
1bebe28876
feat: import/export full recorder captures 2021-08-25 23:20:55 +05:30
Gavin D'souza
e407b78506 chore: Drop dead and deprecated code
* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
2021-05-26 15:31:29 +05:30
Aditya Hase
e54694dbf4
fix(recorder): Error page rendering shouldn't fail when recorder is active 2020-10-28 09:36:39 +05:30
Aditya Hase
cb294329ad style: Black + Flake8 2020-05-08 15:35:53 +05:30
Aditya Hase
2ed69034cb perf(recorder): Don't store context (code) and frame locals 2020-05-08 15:34:55 +05:30
Rushabh Mehta
1c893e44c0 fix: frappe.conf.db_type -> frappe.db.db_type 2019-05-24 11:44:28 +05:30