mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [mesos] 02/03: Introduced `logResponse` for http handlers.
Date Tue, 16 Oct 2018 12:17:43 GMT
This is an automated email from the ASF dual-hosted git repository.

alexr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 7df7e4d35ec1c6cce87c629fac0b32149a4830d2
Author: Alexander Rukletsov <alexr@apache.org>
AuthorDate: Thu Oct 11 15:40:37 2018 +0200

    Introduced `logResponse` for http handlers.
    
    Currently we use `logRequest` function to log requests to endpoints
    in Mesos `MasterProcess`, `SlaveProcess`, and `FilesProcess`. Each
    request is logged when it is first fetched from the actor mailbox.
    However this obviously does not allow for logging the request
    processing time.
    
    This patch introduces a `logResponse` function which logs the request
    together with the corresponding response status and the time spent
    generating the response.
    
    Review: https://reviews.apache.org/r/68993
---
 src/common/http.cpp | 15 +++++++++++++++
 src/common/http.hpp | 11 +++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/common/http.cpp b/src/common/http.cpp
index 9070071..80848aa 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -32,6 +32,7 @@
 #include <mesos/quota/quota.hpp>
 
 #include <process/authenticator.hpp>
+#include <process/clock.hpp>
 #include <process/collect.hpp>
 #include <process/dispatch.hpp>
 #include <process/future.hpp>
@@ -1186,4 +1187,18 @@ void logRequest(const process::http::Request& request)
                 : "");
 }
 
+
+void logResponse(
+    const process::http::Request& request,
+    const process::http::Response& response)
+{
+  LOG(INFO) << "HTTP " << request.method << " for " << request.url
+            << (request.client.isSome()
+                ? " from " + stringify(request.client.get())
+                : "")
+            << ": '" << response.status << "'"
+            << " after " << (process::Clock::now() - request.received).ms()
+            << Milliseconds::units();
+}
+
 }  // namespace mesos {
diff --git a/src/common/http.hpp b/src/common/http.hpp
index 4f994a0..6ca54a6 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -345,6 +345,17 @@ Try<Nothing> initializeHttpAuthenticators(
 // desired request handler to get consistent request logging.
 void logRequest(const process::http::Request& request);
 
+
+// Log the response for the corresponding request together with the request
+// processing time. Route handlers can compose this with the desired request
+// handler to get consistent request/response logging.
+//
+// TODO(alexr): Consider taking `response` as a future to allow logging for
+// cases when response has not been generated.
+void logResponse(
+    const process::http::Request& request,
+    const process::http::Response& response);
+
 } // namespace mesos {
 
 #endif // __COMMON_HTTP_HPP__


Mime
View raw message