You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2020/10/06 13:30:43 UTC

[qpid-dispatch] branch dev-protocol-adaptors updated: DISPATCH-1790: add read and write octet counters to HTTP/1.x codec

This is an automated email from the ASF dual-hosted git repository.

kgiusti pushed a commit to branch dev-protocol-adaptors
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/dev-protocol-adaptors by this push:
     new 38b243d  DISPATCH-1790: add read and write octet counters to HTTP/1.x codec
38b243d is described below

commit 38b243d6bf2de7ee6965b99ff347a1b0d0bcb560
Author: Kenneth Giusti <kg...@apache.org>
AuthorDate: Mon Oct 5 13:29:00 2020 -0400

    DISPATCH-1790: add read and write octet counters to HTTP/1.x codec
    
    This closes #861
---
 include/qpid/dispatch/http1_codec.h |  5 +++++
 src/adaptors/http1/http1_client.c   |  8 ++++++--
 src/adaptors/http1/http1_codec.c    | 25 ++++++++++++++++++++++++-
 src/adaptors/http1/http1_server.c   | 10 +++++++---
 4 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/include/qpid/dispatch/http1_codec.h b/include/qpid/dispatch/http1_codec.h
index 62e70fb..ccb8864 100644
--- a/include/qpid/dispatch/http1_codec.h
+++ b/include/qpid/dispatch/http1_codec.h
@@ -187,6 +187,11 @@ bool h1_codec_request_complete(const h1_codec_request_state_t *hrs);
 // true when codec has encoded/decoded a complete response message
 bool h1_codec_response_complete(const h1_codec_request_state_t *hrs);
 
+// query the amount of octets read (in) and written (out) for a request
+void h1_codec_request_state_counters(const h1_codec_request_state_t *hrs,
+                                     uint64_t *in_octets,
+                                     uint64_t *out_octets);
+
 // Utility for iterating over a list of HTTP tokens.
 //
 // start - begin search
diff --git a/src/adaptors/http1/http1_client.c b/src/adaptors/http1/http1_client.c
index 0a81df4..1a7c3c8 100644
--- a/src/adaptors/http1/http1_client.c
+++ b/src/adaptors/http1/http1_client.c
@@ -838,9 +838,13 @@ static void _client_request_complete_cb(h1_codec_request_state_t *lib_rs, bool c
         hreq->cancelled = hreq->cancelled || cancelled;
         hreq->codec_completed = !hreq->cancelled;
 
+        uint64_t in_octets, out_octets;
+        h1_codec_request_state_counters(lib_rs, &in_octets, &out_octets);
         qd_log(qdr_http1_adaptor->log, QD_LOG_TRACE,
-               "[C%"PRIu64"] HTTP request/response %s.", hreq->base.hconn->conn_id,
-               cancelled ? "cancelled!" : "codec done");
+               "[C%"PRIu64"] HTTP request/response %s. Octets read: %"PRIu64" written: %"PRIu64,
+               hreq->base.hconn->conn_id,
+               cancelled ? "cancelled!" : "codec done",
+               in_octets, out_octets);
     }
 }
 
diff --git a/src/adaptors/http1/http1_codec.c b/src/adaptors/http1/http1_codec.c
index f91b1f2..d1fbea9 100644
--- a/src/adaptors/http1/http1_codec.c
+++ b/src/adaptors/http1/http1_codec.c
@@ -101,6 +101,9 @@ struct h1_codec_request_state_t {
     char                *method;
     uint32_t             response_code;
 
+    uint64_t in_octets;     // # encoded octets arriving from endpoint
+    uint64_t out_octets;    // # encoded octets written to endpoint
+
     bool no_body_method;    // true if request method is either HEAD or CONNECT
     bool request_complete;  // true when request message done encoding/decoding
     bool response_complete; // true when response message done encoding/decoding
@@ -365,6 +368,7 @@ static void write_string(struct encoder_t *encoder, const char *string)
     size_t needed = strlen(string);
     ensure_outgoing_capacity(encoder, needed);
 
+    encoder->hrs->out_octets += needed;
     qd_iterator_pointer_t *wptr = &encoder->write_ptr;
     while (needed) {
         if (qd_buffer_capacity(wptr->buffer) == 0) {
@@ -592,6 +596,7 @@ static bool parse_request_line(h1_codec_connection_t *conn, struct decoder_t *de
     qd_iterator_pointer_t method = {0};
     qd_iterator_pointer_t target = {0};
     qd_iterator_pointer_t version = {0};
+    int in_octets = line->remaining;
 
     if (!parse_token(line, &method) ||
         !parse_field(line, &target) ||
@@ -643,6 +648,7 @@ static bool parse_request_line(h1_codec_connection_t *conn, struct decoder_t *de
                            strcmp((char*)method_str, "CONNECT") == 0);
 
     hrs->method = qd_strdup((char*) method_str);
+    hrs->in_octets += in_octets;
 
     decoder->hrs = hrs;
     decoder->is_request = true;
@@ -662,6 +668,7 @@ static int parse_response_line(h1_codec_connection_t *conn, struct decoder_t *de
     qd_iterator_pointer_t version = {0};
     qd_iterator_pointer_t status_code = {0};
     qd_iterator_pointer_t reason = {0};
+    int in_octets = line->remaining;
 
     if (!parse_field(line, &version)
         || !parse_field(line, &status_code)
@@ -685,6 +692,7 @@ static int parse_response_line(h1_codec_connection_t *conn, struct decoder_t *de
     assert(!decoder->hrs);   // state machine violation
     assert(hrs->response_code == 0);
 
+    hrs->in_octets += in_octets;
     decoder->hrs = hrs;
 
     unsigned char code_str[4];
@@ -892,6 +900,8 @@ static bool parse_header(h1_codec_connection_t *conn, struct decoder_t *decoder)
     if (read_line(rptr, &line)) {
         debug_print_iterator_pointer("header:", &line);
 
+        hrs->in_octets += line.remaining;
+
         if (is_empty_line(&line)) {
             // end of headers
             return process_headers_done(conn, decoder);
@@ -964,6 +974,7 @@ static inline int consume_body_data(h1_codec_connection_t *conn, bool flush)
     // shortcut: if no more data to parse send the entire incoming chain
     if (rptr->remaining == 0) {
 
+        decoder->hrs->in_octets += body_ptr->remaining;
         decoder->error = conn->config.rx_body(decoder->hrs, &decoder->incoming,
                                               body_ptr->cursor - qd_buffer_base(body_ptr->buffer),
                                               body_ptr->remaining,
@@ -1011,8 +1022,10 @@ static inline int consume_body_data(h1_codec_connection_t *conn, bool flush)
         body_ptr->remaining = 0;
     }
 
-    if (octets)
+    if (octets) {
+        decoder->hrs->in_octets += octets;
         decoder->error = conn->config.rx_body(decoder->hrs, &blist, body_offset, octets, true);
+    }
     return decoder->error;
 }
 
@@ -1163,6 +1176,7 @@ static bool parse_body(h1_codec_connection_t *conn, struct decoder_t *decoder)
 
     // otherwise no explict body size, so just keep passing the entire unparsed
     // incoming chain along until the remote closes the connection
+    decoder->hrs->in_octets += decoder->read_ptr.remaining;
     decoder->error = conn->config.rx_body(decoder->hrs,
                                           &decoder->incoming,
                                           decoder->read_ptr.cursor
@@ -1477,6 +1491,7 @@ int h1_codec_tx_body(h1_codec_request_state_t *hrs, qd_message_body_data_t *body
         _flush_headers(hrs, encoder);
 
     // skip the outgoing queue and send directly
+    hrs->out_octets += qd_message_body_data_payload_length(body_data);
     conn->config.tx_body_data(hrs, body_data);
 
     return 0;
@@ -1540,6 +1555,14 @@ bool h1_codec_response_complete(const h1_codec_request_state_t *hrs)
 }
 
 
+void h1_codec_request_state_counters(const h1_codec_request_state_t *hrs,
+                                     uint64_t *in_octets, uint64_t *out_octets)
+{
+    *in_octets = (hrs) ? hrs->in_octets : 0;
+    *out_octets = (hrs) ? hrs->out_octets : 0;
+}
+
+
 const char *h1_codec_token_list_next(const char *start, size_t *len, const char **next)
 {
     static const char *SKIPME = ", \t";
diff --git a/src/adaptors/http1/http1_server.c b/src/adaptors/http1/http1_server.c
index 596f32b..2d11600 100644
--- a/src/adaptors/http1/http1_server.c
+++ b/src/adaptors/http1/http1_server.c
@@ -539,7 +539,7 @@ static void _handle_connection_events(pn_event_t *e, qd_server_t *qd_server, voi
                 if (!qdr_delivery_receive_complete(hreq->request_dlv))
                     return;
 
-                uint64_t dispo = hreq->request_dispo || PN_MODIFIED;
+                uint64_t dispo = hreq->request_dispo ? hreq->request_dispo : PN_MODIFIED;
                 qdr_delivery_remote_state_updated(qdr_http1_adaptor->core,
                                                   hreq->request_dlv,
                                                   dispo,
@@ -937,9 +937,13 @@ static void _server_request_complete_cb(h1_codec_request_state_t *hrs, bool canc
     hreq->cancelled = hreq->cancelled || cancelled;
     hreq->codec_completed = !hreq->cancelled;
 
+    uint64_t in_octets, out_octets;
+    h1_codec_request_state_counters(hrs, &in_octets, &out_octets);
     qd_log(qdr_http1_adaptor->log, QD_LOG_TRACE,
-           "[C%"PRIu64"] HTTP request/response %s.", hconn->conn_id,
-           cancelled ? "cancelled!" : "codec done");
+           "[C%"PRIu64"] HTTP request/response %s. Octets read: %"PRIu64" written: %"PRIu64,
+           hconn->conn_id,
+           cancelled ? "cancelled!" : "codec done",
+           in_octets, out_octets);
 }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org