This is an automated email from the ASF dual-hosted git repository. gsim pushed a commit to branch dev-protocol-adaptors-2 in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git
commit eeb828e39391abf401e16b32e247715bec292658 Author: Gordon Sim <g...@redhat.com> AuthorDate: Wed Nov 18 19:17:55 2020 +0000 DISPATCH-1847: use remote host in stats for ingress --- src/adaptors/http1/http1_request_info.c | 16 +--------------- src/adaptors/http2/http2_adaptor.c | 18 +++++++++++++++++- src/adaptors/http_common.c | 15 +++++++++++++++ src/adaptors/http_common.h | 1 + 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/adaptors/http1/http1_request_info.c b/src/adaptors/http1/http1_request_info.c index a2f4f38..2ea239f 100644 --- a/src/adaptors/http1/http1_request_info.c +++ b/src/adaptors/http1/http1_request_info.c @@ -24,20 +24,6 @@ #include "dispatch_private.h" #include <inttypes.h> -static char *_get_host_from_host_port(const char *host_port) -{ - char *end = strchr(host_port, ':'); - if (end == NULL) { - return 0; - } else { - size_t len = end - host_port; - char *host = malloc(len + 1); - strncpy(host, host_port, len); - host[len] = '\0'; - return host; - } -} - static void _http1_record_request_info(qdr_http1_adaptor_t *adaptor, qdr_http1_request_base_t *request, const char *host, bool ingress) { uint64_t in_octets, out_octets; @@ -49,7 +35,7 @@ static void _http1_record_request_info(qdr_http1_adaptor_t *adaptor, qdr_http1_r void qdr_http1_record_client_request_info(qdr_http1_adaptor_t *adaptor, qdr_http1_request_base_t *request) { - char *host = _get_host_from_host_port(request->hconn->client.client_ip_addr); + char *host = qd_get_host_from_host_port(request->hconn->client.client_ip_addr); _http1_record_request_info(adaptor, request, host ? host : request->hconn->client.client_ip_addr, true); if (host) free(host); } diff --git a/src/adaptors/http2/http2_adaptor.c b/src/adaptors/http2/http2_adaptor.c index dd2638b..8e1b74a 100644 --- a/src/adaptors/http2/http2_adaptor.c +++ b/src/adaptors/http2/http2_adaptor.c @@ -790,10 +790,26 @@ static void send_settings_frame(qdr_http2_connection_t *conn) static void _http_record_request(qdr_http2_connection_t *conn, qdr_http2_stream_data_t *stream_data) { stream_data->stop = qd_timer_now(); + + bool free_remote_addr = false; + char *remote_addr; + if (conn->ingress) { + remote_addr = qd_get_host_from_host_port(conn->remote_address); + if (remote_addr) { + free_remote_addr = true; + } else { + remote_addr = conn->remote_address; + } + } else { + remote_addr = conn->config->host; + } qd_http_record_request(http2_adaptor->core, stream_data->method, stream_data->request_status, - conn->config->address, conn->config->host, conn->config->site, + conn->config->address, remote_addr, conn->config->site, stream_data->remote_site, conn->ingress, stream_data->bytes_in, stream_data->bytes_out, stream_data->stop && stream_data->start ? stream_data->stop - stream_data->start : 0); + if (free_remote_addr) { + free(remote_addr); + } } static int on_frame_recv_callback(nghttp2_session *session, diff --git a/src/adaptors/http_common.c b/src/adaptors/http_common.c index 60648ad..3d1d023 100644 --- a/src/adaptors/http_common.c +++ b/src/adaptors/http_common.c @@ -673,3 +673,18 @@ void qd_http_record_request(qdr_core_t *core, const char * method, uint32_t stat qd_log(qd_log_source(QD_HTTP_LOG_SOURCE), QD_LOG_DEBUG, "Adding http request info %s", record->key); _add_http_request_info(core, record); } + +char *qd_get_host_from_host_port(const char *host_port) +{ + char *end = strchr(host_port, ':'); + if (end == NULL) { + return 0; + } else { + size_t len = end - host_port; + char *host = malloc(len + 1); + strncpy(host, host_port, len); + host[len] = '\0'; + return host; + } +} + diff --git a/src/adaptors/http_common.h b/src/adaptors/http_common.h index 603e979..1fa5fd5 100644 --- a/src/adaptors/http_common.h +++ b/src/adaptors/http_common.h @@ -104,6 +104,7 @@ extern const char *qdr_http_request_info_columns[QDR_HTTP_REQUEST_INFO_COLUMN_CO void qd_http_record_request(qdr_core_t *core, const char * method, uint32_t status_code, const char *address, const char *host, const char *local_site, const char *remote_site, bool ingress, uint64_t bytes_in, uint64_t bytes_out, uint64_t latency); +char *qd_get_host_from_host_port(const char *host_port); // // These functions are defined in their respective HTTP adaptors: --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org