LP#1492793: teach Clark Kent to set the Pg app name
authorGalen Charlton <gmc@esilibrary.com>
Tue, 16 Feb 2016 20:36:26 +0000 (15:36 -0500)
committerMike Rylander <mrylander@gmail.com>
Wed, 2 Mar 2016 20:58:31 +0000 (15:58 -0500)
Clark Kent can now also use the application_name
setting in the relevant sections of opensrf.xml to
set the Pg application name.

To test:

[1] Apply the patch, restarting opensrf.settings, and
    start Clark.
[2] Run a report that will take at least a minute to
    finish. While it is running, query the pg_stat_activity
    table. There should be at least one row where the
    application_name column is set to 'Clark Kent (reports)'.
[3] Note that since the master Clark process opens a database
    connection, checks whether there are any reports to run,
    then immediately closes the connection, it's unlikely that
    you'll catch a 'Clark Kent (state)' connection when
    querying pg_stat_activity.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/examples/opensrf.xml.example
Open-ILS/src/reporter/clark-kent.pl

index 7b6484c..87db4cc 100644 (file)
@@ -159,7 +159,7 @@ vim:et:ts=4:sw=4:
                     <db>evergreen</db>
                     <user>postgres</user>
                     <pw>postgres</pw>
-                    <application_name>open-ils.reporter</application_name>
+                    <application_name>Clark Kent (reports)</application_name>
                 </database>
                 <state_store>
                     <driver>Pg</driver>
@@ -168,7 +168,7 @@ vim:et:ts=4:sw=4:
                     <db>evergreen</db>
                     <user>postgres</user>
                     <pw>postgres</pw>
-                    <application_name>open-ils.reporter-state</application_name>
+                    <application_name>Clark Kent (state)</application_name>
                 </state_store>
                 <files>
                     <!-- successful report outputs go here -->
index fabd2db..9fbf602 100755 (executable)
@@ -67,6 +67,7 @@ if (!$data_db{db_name}) {
 }
 $data_db{db_user}   = $sc->config_value( reporter => setup => database => 'user' );
 $data_db{db_pw}     = $sc->config_value( reporter => setup => database => 'pw' );
+$data_db{db_app}    = $sc->config_value( reporter => setup => database => 'application_name' );
 
 
 
@@ -80,6 +81,8 @@ if (!$state_db{db_name}) {
 }
 $state_db{db_user}   = $sc->config_value( reporter => setup => state_store => 'user'   ) || $data_db{db_user};
 $state_db{db_pw}     = $sc->config_value( reporter => setup => state_store => 'pw'     ) || $data_db{db_pw};
+$state_db{db_app}    = $sc->config_value( reporter => setup => state_store => 'application_name' )
+                         || $data_db{db_app};
 
 
 die "Unable to retrieve database connection information from the settings server"
@@ -94,7 +97,9 @@ my $output_base      = $sc->config_value( reporter => setup => files => 'output_
 my $base_uri         = $sc->config_value( reporter => setup => 'base_uri' );
 
 my $state_dsn = "dbi:" . $state_db{db_driver} . ":dbname=" . $state_db{db_name} .';host=' . $state_db{db_host} . ';port=' . $state_db{db_port};
+$state_dsn .= ";application_name='$state_db{db_app}'" if $state_db{db_app};
 my $data_dsn  = "dbi:" .  $data_db{db_driver} . ":dbname=" .  $data_db{db_name} .';host=' .  $data_db{db_host} . ';port=' .  $data_db{db_port};
+$data_dsn .= ";application_name='$data_db{db_app}'" if $data_db{db_app};
 
 my $count               = $opt_count //
                           $sc->config_value( reporter => setup => 'parallel' ) //