mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Allow raw PG tracing to be enabled only for sidekiq processes
This commit is contained in:
parent
42729e6a27
commit
cd3fab9ccc
@ -4,6 +4,9 @@
|
|||||||
# to be streamed to files for debugging. The filenames are formatted
|
# to be streamed to files for debugging. The filenames are formatted
|
||||||
# like tmp/pgtrace/{{PID}}_{{CONNECTION_OBJECT_ID}}.txt
|
# like tmp/pgtrace/{{PID}}_{{CONNECTION_OBJECT_ID}}.txt
|
||||||
#
|
#
|
||||||
|
# Setting TRACE_PG_CONNECTIONS=SIDEKIQ will only trace connections
|
||||||
|
# on in sidekiq (safer, because there will be minimal user-facing perf impact)
|
||||||
|
#
|
||||||
# Files will be automatically deleted when the connection is closed gracefully
|
# Files will be automatically deleted when the connection is closed gracefully
|
||||||
# (e.g. when activerecord closes it after a period of inactivity)
|
# (e.g. when activerecord closes it after a period of inactivity)
|
||||||
# Files will not be automatically deleted when closed abruptly
|
# Files will not be automatically deleted when closed abruptly
|
||||||
@ -17,6 +20,7 @@ if ENV["TRACE_PG_CONNECTIONS"]
|
|||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super(*args).tap do
|
super(*args).tap do
|
||||||
|
next if ENV["TRACE_PG_CONNECTIONS"] == "SIDEKIQ" && !Sidekiq.server?
|
||||||
FileUtils.mkdir_p(TRACE_DIR)
|
FileUtils.mkdir_p(TRACE_DIR)
|
||||||
@trace_filename = "#{TRACE_DIR}/#{Process.pid}_#{self.object_id}.txt"
|
@trace_filename = "#{TRACE_DIR}/#{Process.pid}_#{self.object_id}.txt"
|
||||||
trace File.new(@trace_filename, "w")
|
trace File.new(@trace_filename, "w")
|
||||||
@ -25,6 +29,7 @@ if ENV["TRACE_PG_CONNECTIONS"]
|
|||||||
|
|
||||||
def close
|
def close
|
||||||
super.tap do
|
super.tap do
|
||||||
|
next if ENV["TRACE_PG_CONNECTIONS"] == "SIDEKIQ" && !Sidekiq.server?
|
||||||
File.delete(@trace_filename)
|
File.delete(@trace_filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user