[Rt-commit] rt branch 5.0/add-rest2-timelog-middleware created. rt-5.0.3-125-ga13e3c1e27

BPS Git Server git at git.bestpractical.com
Thu Oct 13 11:46:34 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/add-rest2-timelog-middleware has been created
        at  a13e3c1e27c10a6fe742193bc30f9490e46ed45d (commit)

- Log -----------------------------------------------------------------
commit a13e3c1e27c10a6fe742193bc30f9490e46ed45d
Author: Jason Crome <jcrome at bestpractical.com>
Date:   Thu Oct 13 07:41:37 2022 -0400

    Plack middleware to log time to complete REST2 requests

diff --git a/lib/RT/REST2.pm b/lib/RT/REST2.pm
index b0b8512527..c526033980 100644
--- a/lib/RT/REST2.pm
+++ b/lib/RT/REST2.pm
@@ -1458,6 +1458,7 @@ sub to_app {
         enable '+RT::REST2::Middleware::CleanupRequest';
         enable '+RT::REST2::Middleware::ErrorAsJSON';
         enable '+RT::REST2::Middleware::Log';
+        enable '+RT::REST2::Middleware::TimeLog';
         enable '+RT::REST2::Middleware::Auth';
         RT::REST2::Dispatcher->to_psgi_app;
     };
diff --git a/lib/RT/REST2/Middleware/TimeLog.pm b/lib/RT/REST2/Middleware/TimeLog.pm
new file mode 100644
index 0000000000..31a9f29c4d
--- /dev/null
+++ b/lib/RT/REST2/Middleware/TimeLog.pm
@@ -0,0 +1,81 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
+#                                          <sales at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::REST2::Middleware::TimeLog;
+
+use strict;
+use warnings;
+use Time::HiRes;
+
+use base 'Plack::Middleware';
+
+sub call {
+    my ( $self, $env ) = @_;
+
+    my $start = [ Time::HiRes::time() ];
+    my $res   = $self->app->( $env );
+
+    if( RT->Config->Get( 'REST2TimeLog' ) ) {
+        my $time = Time::HiRes::tv_interval( $start );
+        my $message =
+            '[REST2] ' .
+            'Endpoint=' . $env->{ REQUEST_URI } .
+            ', Method=' . $env->{ REQUEST_METHOD } .
+            ', User=' . $env->{ 'rt.current_user' }{ values }{ name } .
+            ", Response=${time}s";
+
+        RT->Logger->warn( $message );
+
+        if( RT->Config->Get( 'REST2TimeLogDetail' ) ) {
+            RT->Logger->debug( $message );
+        }
+    }
+    return $res;
+}
+
+1;

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list