]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Do not count sending and loading time in rspamc
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 1 Apr 2017 11:05:25 +0000 (12:05 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 1 Apr 2017 11:05:25 +0000 (12:05 +0100)
src/client/rspamc.c
src/client/rspamdclient.c
src/client/rspamdclient.h

index d58310de6a2e38e86975611b2ddd42d3385e0912..839fd2ff03ba4577e08e6a6253a3dc056f214d9a 100644 (file)
@@ -324,7 +324,6 @@ struct rspamc_command {
 struct rspamc_callback_data {
        struct rspamc_command *cmd;
        gchar *filename;
-       gdouble start;
 };
 
 gboolean
@@ -1392,9 +1391,10 @@ rspamc_client_execute_cmd (struct rspamc_command *cmd, ucl_object_t *result,
 
 static void
 rspamc_client_cb (struct rspamd_client_connection *conn,
-       struct rspamd_http_message *msg,
-       const gchar *name, ucl_object_t *result, GString *input,
-       gpointer ud, GError *err)
+               struct rspamd_http_message *msg,
+               const gchar *name, ucl_object_t *result, GString *input,
+               gpointer ud, gdouble start_time, gdouble send_time,
+               GError *err)
 {
        gchar *ucl_out;
        struct rspamc_callback_data *cbdata = (struct rspamc_callback_data *)ud;
@@ -1405,7 +1405,13 @@ rspamc_client_cb (struct rspamd_client_connection *conn,
        gsize body_len;
 
        cmd = cbdata->cmd;
-       diff = finish - cbdata->start;
+
+       if (send_time > 0) {
+               diff = finish - send_time;
+       }
+       else {
+               diff = finish - start_time;
+       }
 
        if (execute) {
                /* Pass all to the external command */
@@ -1526,7 +1532,6 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd,
                cbdata = g_slice_alloc (sizeof (struct rspamc_callback_data));
                cbdata->cmd = cmd;
                cbdata->filename = g_strdup (name);
-               cbdata->start = rspamd_get_ticks ();
 
                if (cmd->need_input) {
                        rspamd_client_command (conn, cmd->path, attrs, in, rspamc_client_cb,
index 4691ce5ec5e8a599b8607addacc90a338ccec084..6ccdce5f5440ac00c75ae47f7e6a2ad19468f1b7 100644 (file)
@@ -41,6 +41,8 @@ struct rspamd_client_connection {
        struct timeval timeout;
        struct rspamd_http_connection *http_conn;
        gboolean req_sent;
+       gdouble start_time;
+       gdouble send_time;
        struct rspamd_client_request *req;
        struct rspamd_keypair_cache *keys_cache;
 };
@@ -92,7 +94,9 @@ rspamd_client_error_handler (struct rspamd_http_connection *conn, GError *err)
        struct rspamd_client_connection *c;
 
        c = req->conn;
-       req->cb (c, NULL, c->server_name->str, NULL, req->input, req->ud, err);
+       req->cb (c, NULL, c->server_name->str, NULL,
+                       req->input, req->ud,
+                       c->start_time, c->send_time, err);
 }
 
 static gint
@@ -110,6 +114,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
 
        if (!c->req_sent) {
                c->req_sent = TRUE;
+               c->send_time = rspamd_get_ticks ();
                rspamd_http_connection_reset (c->http_conn);
                rspamd_http_connection_read_message (c->http_conn,
                        c->req,
@@ -123,7 +128,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
                        err = g_error_new (RCLIENT_ERROR, msg->code, "HTTP error: %d, %.*s",
                                        msg->code,
                                        (gint)msg->status->len, msg->status->str);
-                       req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err);
+                       req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud,
+                                       c->start_time, c->send_time, err);
                        g_error_free (err);
 
                        return 0;
@@ -169,7 +175,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
                                                                "Decompression error: %s",
                                                                ZSTD_getErrorName (r));
                                                req->cb (c, msg, c->server_name->str, NULL,
-                                                               req->input, req->ud, err);
+                                                               req->input, req->ud, c->start_time,
+                                                               c->send_time, err);
                                                g_error_free (err);
                                                ZSTD_freeDStream (zstream);
                                                g_free (out);
@@ -191,7 +198,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
                                        err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s",
                                                        ucl_parser_get_error (parser));
                                        ucl_parser_free (parser);
-                                       req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err);
+                                       req->cb (c, msg, c->server_name->str, NULL, req->input,
+                                                       req->ud, c->start_time, c->send_time, err);
                                        g_error_free (err);
                                        g_free (zout.dst);
 
@@ -204,7 +212,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
                                err = g_error_new (RCLIENT_ERROR, 500,
                                                "Invalid compression method");
                                req->cb (c, msg, c->server_name->str, NULL,
-                                               req->input, req->ud, err);
+                                               req->input, req->ud, c->start_time, c->send_time, err);
                                g_error_free (err);
 
                                return 0;
@@ -216,7 +224,8 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
                                err = g_error_new (RCLIENT_ERROR, msg->code, "Cannot parse UCL: %s",
                                                ucl_parser_get_error (parser));
                                ucl_parser_free (parser);
-                               req->cb (c, msg, c->server_name->str, NULL, req->input, req->ud, err);
+                               req->cb (c, msg, c->server_name->str, NULL,
+                                               req->input, req->ud, c->start_time, c->send_time, err);
                                g_error_free (err);
 
                                return 0;
@@ -224,7 +233,7 @@ rspamd_client_finish_handler (struct rspamd_http_connection *conn,
                }
 
                req->cb (c, msg, c->server_name->str, ucl_parser_get_object (
-                               parser), req->input, req->ud, NULL);
+                               parser), req->input, req->ud, c->start_time, c->send_time, NULL);
                ucl_parser_free (parser);
        }
 
@@ -425,6 +434,7 @@ rspamd_client_command (struct rspamd_client_connection *conn,
        req->msg->url = rspamd_fstring_append (req->msg->url, command, strlen (command));
 
        conn->req = req;
+       conn->start_time = rspamd_get_ticks ();
 
        if (compressed) {
                rspamd_http_connection_write_message (conn->http_conn, req->msg, NULL,
index 5313bb88bdf5c648cd508707d34cfe36f82b4ab5..e5fe64d9138dad7f2485fd260187a9860b891aa5 100644 (file)
@@ -37,13 +37,15 @@ struct rspamd_http_client_header {
  * @param err error pointer
  */
 typedef void (*rspamd_client_callback) (
-       struct rspamd_client_connection *conn,
-       struct rspamd_http_message *msg,
-       const gchar *name,
-       ucl_object_t *result,
-       GString *input,
-       gpointer ud,
-       GError *err);
+               struct rspamd_client_connection *conn,
+               struct rspamd_http_message *msg,
+               const gchar *name,
+               ucl_object_t *result,
+               GString *input,
+               gpointer ud,
+               gdouble start_time,
+               gdouble send_time,
+               GError *err);
 
 /**
  * Start rspamd worker or controller command