-
Notifications
You must be signed in to change notification settings - Fork 20.7k
fix: restrict debug endpoints to development mode #33428
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,44 +24,46 @@ def health(): # pyright: ignore[reportUnusedFunction] | |
| content_type="application/json", | ||
| ) | ||
|
|
||
| @app.route("/threads") | ||
| def threads(): # pyright: ignore[reportUnusedFunction] | ||
| num_threads = threading.active_count() | ||
| threads = threading.enumerate() | ||
| if dify_config.DEBUG or app.config.get("TESTING"): | ||
|
|
||
| thread_list = [] | ||
| for thread in threads: | ||
| thread_name = thread.name | ||
| thread_id = thread.ident | ||
| is_alive = thread.is_alive() | ||
| @app.route("/threads") | ||
| def threads(): # pyright: ignore[reportUnusedFunction] | ||
| num_threads = threading.active_count() | ||
| threads = threading.enumerate() | ||
|
|
||
| thread_list.append( | ||
| { | ||
| "name": thread_name, | ||
| "id": thread_id, | ||
| "is_alive": is_alive, | ||
| } | ||
| ) | ||
| thread_list = [] | ||
| for thread in threads: | ||
| thread_name = thread.name | ||
| thread_id = thread.ident | ||
| is_alive = thread.is_alive() | ||
|
|
||
| return { | ||
| "pid": os.getpid(), | ||
| "thread_num": num_threads, | ||
| "threads": thread_list, | ||
| } | ||
| thread_list.append( | ||
| { | ||
| "name": thread_name, | ||
| "id": thread_id, | ||
| "is_alive": is_alive, | ||
| } | ||
| ) | ||
|
|
||
| @app.route("/db-pool-stat") | ||
| def pool_stat(): # pyright: ignore[reportUnusedFunction] | ||
| from extensions.ext_database import db | ||
| return { | ||
| "pid": os.getpid(), | ||
| "thread_num": num_threads, | ||
| "threads": thread_list, | ||
| } | ||
|
|
||
| engine = db.engine | ||
| # TODO: Fix the type error | ||
| # FIXME maybe its sqlalchemy issue | ||
| return { | ||
| "pid": os.getpid(), | ||
| "pool_size": engine.pool.size(), # type: ignore | ||
| "checked_in_connections": engine.pool.checkedin(), # type: ignore | ||
| "checked_out_connections": engine.pool.checkedout(), # type: ignore | ||
| "overflow_connections": engine.pool.overflow(), # type: ignore | ||
| "connection_timeout": engine.pool.timeout(), # type: ignore | ||
| "recycle_time": db.engine.pool._recycle, # type: ignore | ||
| } | ||
| @app.route("/db-pool-stat") | ||
| def pool_stat(): # pyright: ignore[reportUnusedFunction] | ||
| from extensions.ext_database import db | ||
|
|
||
| engine = db.engine | ||
| # TODO: Fix the type error | ||
| # FIXME maybe its sqlalchemy issue | ||
| return { | ||
| "pid": os.getpid(), | ||
| "pool_size": engine.pool.size(), # type: ignore | ||
| "checked_in_connections": engine.pool.checkedin(), # type: ignore | ||
| "checked_out_connections": engine.pool.checkedout(), # type: ignore | ||
| "overflow_connections": engine.pool.overflow(), # type: ignore | ||
| "connection_timeout": engine.pool.timeout(), # type: ignore | ||
| "recycle_time": db.engine.pool._recycle, # type: ignore | ||
|
Contributor
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. Accessing the protected member "recycle_time": db.engine.pool.recycle, # type: ignore |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop to build
thread_listcan be simplified into a more concise and Pythonic list comprehension. This improves readability by reducing boilerplate code.