Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NEETzsche
pleroma
Commits
6e27fc9c
Commit
6e27fc9c
authored
3 years ago
by
Alex Gleason
Browse files
Options
Downloads
Plain Diff
Merge branch 'log-slow-queries' into 'develop'
Log slow Ecto queries See merge request
!3553
parents
3b8eaadb
08c0f09b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/config.exs
+9
-0
9 additions, 0 deletions
config/config.exs
lib/pleroma/telemetry/logger.ex
+68
-2
68 additions, 2 deletions
lib/pleroma/telemetry/logger.ex
with
77 additions
and
2 deletions
config/config.exs
+
9
−
0
View file @
6e27fc9c
...
...
@@ -149,6 +149,8 @@
]
# Configures Elixir's Logger
config
:logger
,
truncate:
65536
config
:logger
,
:console
,
level:
:debug
,
format:
"
\n
$time $metadata[$level] $message
\n
"
,
...
...
@@ -853,6 +855,13 @@
{
Pleroma
.
Web
.
ActivityPub
.
MRF
.
MediaProxyWarmingPolicy
,
[
max_running:
5
,
max_waiting:
5
]}
]
config
:pleroma
,
:telemetry
,
slow_queries_logging:
[
enabled:
false
,
min_duration:
500_000
,
exclude_sources:
[
nil
,
"oban_jobs"
]
]
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config
"
#{
Mix
.
env
()
}
.exs"
This diff is collapsed.
Click to expand it.
lib/pleroma/telemetry/logger.ex
+
68
−
2
View file @
6e27fc9c
...
...
@@ -12,10 +12,16 @@ defmodule Pleroma.Telemetry.Logger do
[
:pleroma
,
:connection_pool
,
:reclaim
,
:stop
],
[
:pleroma
,
:connection_pool
,
:provision_failure
],
[
:pleroma
,
:connection_pool
,
:client
,
:dead
],
[
:pleroma
,
:connection_pool
,
:client
,
:add
]
[
:pleroma
,
:connection_pool
,
:client
,
:add
],
[
:pleroma
,
:repo
,
:query
]
]
def
attach
do
:telemetry
.
attach_many
(
"pleroma-logger"
,
@events
,
&
handle_event
/
4
,
[])
:telemetry
.
attach_many
(
"pleroma-logger"
,
@events
,
&
Pleroma
.
Telemetry
.
Logger
.
handle_event
/
4
,
[]
)
end
# Passing anonymous functions instead of strings to logger is intentional,
...
...
@@ -87,4 +93,64 @@ def handle_event(
end
def
handle_event
([
:pleroma
,
:connection_pool
,
:client
,
:add
],
_
,
_
,
_
),
do
:
:ok
def
handle_event
(
[
:pleroma
,
:repo
,
:query
]
=
_name
,
%{
query_time:
query_time
}
=
measurements
,
%{
source:
source
}
=
metadata
,
config
)
do
logging_config
=
Pleroma
.
Config
.
get
([
:telemetry
,
:slow_queries_logging
],
[])
if
logging_config
[
:enabled
]
&&
logging_config
[
:min_duration
]
&&
query_time
>
logging_config
[
:min_duration
]
and
(
is_nil
(
logging_config
[
:exclude_sources
])
or
source
not
in
logging_config
[
:exclude_sources
])
do
log_slow_query
(
measurements
,
metadata
,
config
)
else
:ok
end
end
defp
log_slow_query
(
%{
query_time:
query_time
}
=
_measurements
,
%{
source:
_source
,
query:
query
,
params:
query_params
,
repo:
repo
}
=
_metadata
,
_config
)
do
sql_explain
=
with
{
:ok
,
%{
rows:
explain_result_rows
}}
<-
repo
.
query
(
"EXPLAIN "
<>
query
,
query_params
,
log:
false
)
do
Enum
.
map_join
(
explain_result_rows
,
"
\n
"
,
&
&1
)
end
{
:current_stacktrace
,
stacktrace
}
=
Process
.
info
(
self
(),
:current_stacktrace
)
pleroma_stacktrace
=
Enum
.
filter
(
stacktrace
,
fn
{
__MODULE__
,
_
,
_
,
_
}
->
false
{
mod
,
_
,
_
,
_
}
->
mod
|>
to_string
()
|>
String
.
starts_with?
(
"Elixir.Pleroma."
)
end
)
Logger
.
warn
(
fn
->
"""
Slow query!
Total time: #{round(query_time / 1_000)} ms
#{query}
#{inspect(query_params, limit: :infinity)}
#{sql_explain}
#{Exception.format_stacktrace(pleroma_stacktrace)}
"""
end
)
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment