From 899b856ad694518770806ee87caaf474526fe73d Mon Sep 17 00:00:00 2001 From: Michael Kolupaev Date: Tue, 26 Mar 2024 09:14:20 +0000 Subject: [PATCH] Add profile events for number of HTTP requests and bytes read --- src/Common/ProfileEvents.cpp | 3 +++ src/IO/ReadWriteBufferFromHTTP.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Common/ProfileEvents.cpp b/src/Common/ProfileEvents.cpp index af4faa16780..ba3b94b8790 100644 --- a/src/Common/ProfileEvents.cpp +++ b/src/Common/ProfileEvents.cpp @@ -722,6 +722,9 @@ The server successfully detected this situation and will download merged part fr M(AddressesDiscovered, "Total count of new addresses in dns resolve results for http connections") \ M(AddressesExpired, "Total count of expired addresses which is no longer presented in dns resolve results for http connections") \ M(AddressesMarkedAsFailed, "Total count of addresses which has been marked as faulty due to connection errors for http connections") \ + \ + M(ReadWriteBufferFromHTTPRequestsSent, "Number of HTTP requests sent by ReadWriteBufferFromHTTP") \ + M(ReadWriteBufferFromHTTPBytes, "Total size of payload bytes received and sent by ReadWriteBufferFromHTTP. Doesn't include HTTP headers.") \ #ifdef APPLY_FOR_EXTERNAL_EVENTS diff --git a/src/IO/ReadWriteBufferFromHTTP.cpp b/src/IO/ReadWriteBufferFromHTTP.cpp index c0bb5a14fd9..61c40c5a8fc 100644 --- a/src/IO/ReadWriteBufferFromHTTP.cpp +++ b/src/IO/ReadWriteBufferFromHTTP.cpp @@ -8,6 +8,8 @@ namespace ProfileEvents { extern const Event ReadBufferSeekCancelConnection; + extern const Event ReadWriteBufferFromHTTPRequestsSent; + extern const Event ReadWriteBufferFromHTTPBytes; } @@ -245,6 +247,8 @@ ReadWriteBufferFromHTTP::CallResult ReadWriteBufferFromHTTP::callImpl( auto session = makeHTTPSession(connection_group, uri_, timeouts, proxy_config); + ProfileEvents::increment(ProfileEvents::ReadWriteBufferFromHTTPRequestsSent); + auto & stream_out = session->sendRequest(request); if (out_stream_callback) out_stream_callback(stream_out); @@ -480,6 +484,8 @@ bool ReadWriteBufferFromHTTP::nextImpl() BufferBase::set(impl->buffer().begin(), impl->buffer().size(), impl->offset()); offset_from_begin_pos += working_buffer.size(); + + ProfileEvents::increment(ProfileEvents::ReadWriteBufferFromHTTPBytes, working_buffer.size()); }, /*on_retry=*/ [&] () { @@ -528,6 +534,8 @@ size_t ReadWriteBufferFromHTTP::readBigAt(char * to, size_t n, size_t offset, co copyFromIStreamWithProgressCallback(*result.response_stream, to, n, progress_callback, &bytes_copied, &is_canceled); + ProfileEvents::increment(ProfileEvents::ReadWriteBufferFromHTTPBytes, bytes_copied); + offset += bytes_copied; total_bytes_copied += bytes_copied; to += bytes_copied; @@ -536,6 +544,8 @@ size_t ReadWriteBufferFromHTTP::readBigAt(char * to, size_t n, size_t offset, co }, /*on_retry=*/ [&] () { + ProfileEvents::increment(ProfileEvents::ReadWriteBufferFromHTTPBytes, bytes_copied); + offset += bytes_copied; total_bytes_copied += bytes_copied; to += bytes_copied;