]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats plugin: Don't send any stats before CONNECT was successfully sent.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Sep 2016 17:23:35 +0000 (20:23 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 9 Sep 2016 11:22:29 +0000 (14:22 +0300)
After stats write failures this fixes warnings like:
Warning: stats: Couldn't find session ID: smqAXQE8pIp/AAAB

src/plugins/stats/mail-stats-connection.c
src/plugins/stats/mail-stats-connection.h
src/plugins/stats/stats-plugin.c
src/plugins/stats/stats-plugin.h

index f3103be80e16b01fc974158417a86d2d6dd28cc0..a768eb470bbe5fe241f800c8ff4b040031a7bca7 100644 (file)
@@ -11,8 +11,8 @@
 #include "stats-plugin.h"
 #include "mail-stats-connection.h"
 
-void mail_stats_connection_connect(struct stats_connection *conn,
-                                  struct mail_user *user)
+int mail_stats_connection_connect(struct stats_connection *conn,
+                                 struct mail_user *user)
 {
        struct stats_user *suser = STATS_USER_CONTEXT(user);
        string_t *str = t_str_new(128);
@@ -36,7 +36,7 @@ void mail_stats_connection_connect(struct stats_connection *conn,
                str_append(str, net_ip2addr(user->remote_ip));
        }
        str_append_c(str, '\n');
-       stats_connection_send(conn, str);
+       return stats_connection_send(conn, str);
 }
 
 void mail_stats_connection_disconnect(struct stats_connection *conn,
@@ -48,7 +48,10 @@ void mail_stats_connection_disconnect(struct stats_connection *conn,
        str_append(str, "DISCONNECT\t");
        str_append(str, suser->stats_session_id);
        str_append_c(str, '\n');
-       stats_connection_send(conn, str);
+       if (stats_connection_send(conn, str) < 0) {
+               /* we could retry this later, but stats process will forget it
+                  anyway after 15 minutes. */
+       }
 }
 
 void mail_stats_connection_send_session(struct stats_connection *conn,
@@ -68,5 +71,5 @@ void mail_stats_connection_send_session(struct stats_connection *conn,
        base64_encode(buf->data, buf->used, str);
 
        str_append_c(str, '\n');
-       stats_connection_send(conn, str);
+       (void)stats_connection_send(conn, str);
 }
index 3b3362b5806813c3630610ea464801d85c7a639f..f98b691b0f7b1344b9066fe3d1587660ab24613d 100644 (file)
@@ -6,8 +6,8 @@
 struct mail_stats;
 struct mail_user;
 
-void mail_stats_connection_connect(struct stats_connection *conn,
-                                  struct mail_user *user);
+int mail_stats_connection_connect(struct stats_connection *conn,
+                                 struct mail_user *user);
 void mail_stats_connection_disconnect(struct stats_connection *conn,
                                      struct mail_user *user);
 
index 283817b0bdaedfed2f322ce5be6932ed0842bc73..efb796690caefb752ffa6eda6d4dacf2c7f8375d 100644 (file)
@@ -125,7 +125,12 @@ static void session_stats_refresh(struct mail_user *user)
        time_t now = time(NULL);
        bool changed;
 
-       if (session_stats_need_send(suser, now, &changed, &to_next_secs)) {
+       if (!suser->stats_connected) {
+               if (mail_stats_connection_connect(suser->stats_conn, user) == 0)
+                       suser->stats_connected = TRUE;
+       }
+       if (session_stats_need_send(suser, now, &changed, &to_next_secs) &&
+           suser->stats_connected) {
                suser->session_sent_duplicate = !changed;
                suser->last_session_update = now;
                stats_copy(suser->last_sent_session_stats, suser->session_stats);
@@ -333,7 +338,8 @@ static void stats_user_deinit(struct mail_user *user)
                                         stats_io_deactivate, user);
        /* send final stats before disconnection */
        session_stats_refresh(user);
-       mail_stats_connection_disconnect(stats_conn, user);
+       if (suser->stats_connected)
+               mail_stats_connection_disconnect(stats_conn, user);
 
        if (suser->to_stats_timeout != NULL)
                timeout_remove(&suser->to_stats_timeout);
@@ -437,7 +443,8 @@ static void stats_user_created(struct mail_user *user)
        suser->last_sent_session_stats = stats_alloc(user->pool);
 
        MODULE_CONTEXT_SET(user, stats_user_module, suser);
-       mail_stats_connection_connect(suser->stats_conn, user);
+       if (mail_stats_connection_connect(suser->stats_conn, user) == 0)
+               suser->stats_connected = TRUE;
        suser->to_stats_timeout =
                timeout_add(suser->refresh_secs*1000,
                            session_stats_refresh_timeout, user);
index 776cc8f9e61f697248d1cfb5514404299433df83..bbf437fa293467455ba27d9d7048b54e740cd7aa 100644 (file)
@@ -14,6 +14,7 @@ struct stats_user {
        struct ioloop_context *ioloop_ctx;
        struct stats_connection *stats_conn;
        const char *stats_session_id;
+       bool stats_connected;
 
        unsigned int refresh_secs;
        bool track_commands;