-
Notifications
You must be signed in to change notification settings - Fork 897
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
Set database application name in workers and server #13856
Set database application name in workers and server #13856
Conversation
def self.name=(name) | ||
# TODO: this is postgresql specific | ||
ENV['PGAPPNAME'] = name | ||
ActiveRecord::Base.connection_pool.disconnect! |
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.
We set this ENV variable and disconnect because:
- we probably have already established at least one connection
- any new thread/connection needs to use this value
Unfortunately, we need to query the db to determine the name so we can't module prepend establish_connection (and call super).
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.
Note, postgresql will look for an application name in this ENV variable, so just setting it before establishing a connection is enough to get this set.
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.
Instead of disconnecting, maybe you can set the env var but still go through each connection in the pool and explicitly set the name with the query. This way it will update preexisting connections and handle new ones.
@@ -0,0 +1,14 @@ | |||
module ArSetApplicationName |
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.
Naming.
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.
Maybe just ArApplicationName
?
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.
I'm good with the form of this.
Probably should work out a better name than ar_set_application_name.rb
, but looks good otherwise.
Discussing this with @jrafanie and thinking that maybe this format would be better -
This format lends itself to being both human and machine readable. |
but what does it mean? |
Also, If we put user configurable strings in there, we have to make sure we don't hit the limit. For example, zone name can be just about anything, so maybe we should limit to the first 10 or 15 characters or something. |
Last point...might want to toss an |
@Fryguy Forgot to put in a legend -
|
75a5ee6
to
b739429
Compare
682d1c1
to
2b72400
Compare
@Fryguy @carbonin @gtanzillo updated the description and pushed the changes. Note: I STILL need to disconnect the server process's connection so it can re-establish the connection with the right application_name. I don't need to do this for the workers themselves, |
lib/workers/evm_server.rb
Outdated
name = database_application_name | ||
|
||
# disconnect! after querying the information needed to set the application name | ||
ActiveRecord::Base.connection_pool.disconnect! |
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 happens only once in the server process. I'm not quite sure why SET application_name ...
doesn't work here on the existing connection.
2b72400
to
3722ace
Compare
Previously, pg_stat_activity would look like this: ``` vmdb_production=# select pid, application_name from pg_stat_activity; pid | application_name ------+-------------------------------------------------- 13770 | /var/www/miq/vmdb/lib/workers/bin/evm_server.rb 13950 | /var/www/miq/vmdb/lib/workers/bin/evm_server.rb 13957 | /var/www/miq/vmdb/lib/workers/bin/evm_server.rb 13969 | /var/www/miq/vmdb/lib/workers/bin/evm_server.rb 13975 | /var/www/miq/vmdb/lib/workers/bin/evm_server.rb 13984 | /var/www/miq/vmdb/lib/workers/bin/evm_server.rb ``` It now looks like this: ``` vmdb_development=# select pid, application_name from pg_stat_activity; pid | application_name ------------------+------+-------------+---------------------- 5844 | MIQ 5835 Server[1r2], default[1r1] 5888 | MIQ 5886 Generic[1r1111], s[1r2], default[1r1] 5891 | MIQ 5889 Generic[1r1112], s[1r2], default[1r1] 5894 | MIQ 5892 Priority[1r1113], s[1r2], default[1r1] 5897 | MIQ 5895 Priority[1r1114], s[1r2], default[1r1] 5900 | MIQ 5898 Schedule[1r1115], s[1r2], default[1r1] 5928 | MIQ 5926 EventHandler[1r1116], s[1r2], default[1r1] 5932 | MIQ 5929 Reporting[1r1117], s[1r2], default[1r1] 5934 | MIQ 5931 Reporting[1r1118], s[1r2], default[1r1] 5943 | MIQ 5941 Ui[1r1120], s[1r2], default[1r1] 5940 | MIQ 5935 Websocket[1r1119], s[1r2], default[1r1] 5946 | MIQ 5944 WebService[1r1121], s[1r2], default[1r1] 5964 | MIQ 5935 Websocket[1r1119], s[1r2], default[1r1] 5965 | MIQ 5941 Ui[1r1120], s[1r2], default[1r1] 5966 | MIQ 5944 WebService[1r1121], s[1r2], default[1r1] ```
3722ace
to
b0d765d
Compare
Checked commits jrafanie/manageiq@242af70~...b0d765d with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 app/models/embedded_ansible_worker/runner.rb
|
Fixes a bug in ManageIQ#13856 when you run rake evm:start on a database without a server row for the current server: undefined method database_application_name for nil:NilClass.
…ion_name Set database application name in workers and server (cherry picked from commit f241df4)
…ion_name Set database application name in workers and server (cherry picked from commit f241df4)
Backported to Euwe via #14909 |
Set database application name in workers and server (cherry picked from commit f241df4) https://bugzilla.redhat.com/show_bug.cgi?id=1458339
Fine backport details:
|
https://bugzilla.redhat.com/show_bug.cgi?id=1445928
When we need to do database lock or connection triaging, it's really hard to tell where each connection originated from because we don't specify an application_name. It looks something like this:
The much debated format of the application_name now looks like this:
MIQ <worker pid> <worker class>[<worker id>], s[<server id>], <zone name>[<zone id>]
OR:
MIQ <server pid> Server[<server id>], <zone name>[<zone id>]
Note, the pg backend pid isn't needed in
application_name
since thepid
column inpg_stat_activity
is the backend pid. Plus, each of our processes can have more than one spid.It now looks like this: