diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-05-12 09:23:57 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-05-12 09:23:57 +0100 |
commit | b2452e7281c4a8ef0520f458487c5b4809d60c9d (patch) | |
tree | 7c31d90c22792cdc49e723d3c7d552d55f074421 /src | |
parent | 9c6373baf65808a50c7ba0163e8b00c0b8fda6b6 (diff) | |
download | rspamd-b2452e7281c4a8ef0520f458487c5b4809d60c9d.tar.gz rspamd-b2452e7281c4a8ef0520f458487c5b4809d60c9d.zip |
[Minor] Fix fuzzy stats
Diffstat (limited to 'src')
-rw-r--r-- | src/fuzzy_storage.c | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index dac76e6a4..8a5b43017 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -699,8 +699,8 @@ rspamd_fuzzy_update_key_stat(gboolean matched, guint64 nchecked = key_stat->checked - key_stat->last_checked_count; guint64 nmatched = key_stat->matched - key_stat->last_matched_count; - rspamd_set_counter_ema (&key_stat->checked_ctr, nchecked, 0.5); - rspamd_set_counter_ema (&key_stat->checked_ctr, nmatched, 0.5); + rspamd_set_counter_ema (&key_stat->checked_ctr, nchecked, 0.5f); + rspamd_set_counter_ema (&key_stat->checked_ctr, nmatched, 0.5f); key_stat->last_checked_time = timestamp; key_stat->last_checked_count = key_stat->checked; key_stat->last_matched_count = key_stat->matched; @@ -742,20 +742,22 @@ rspamd_fuzzy_update_stats (struct rspamd_fuzzy_storage_ctx *ctx, if (key) { rspamd_fuzzy_update_key_stat(matched, key->stat, cmd, res, timestamp); - /* Update per flag stats */ - khiter_t k; - struct fuzzy_key_stat *flag_stat; - k = kh_get(fuzzy_key_flag_stat, key->flags_stat, res->v1.flag); + if (matched || ((cmd == FUZZY_WRITE || cmd == FUZZY_DEL) && res->v1.value == 0)) { + /* Update per flag stats */ + khiter_t k; + struct fuzzy_key_stat *flag_stat; + k = kh_get(fuzzy_key_flag_stat, key->flags_stat, res->v1.flag); - if (k == kh_end(key->flags_stat)) { - /* Insert new flag */ - int r; - k = kh_put(fuzzy_key_flag_stat, key->flags_stat, res->v1.flag, &r); - memset(&kh_value(key->flags_stat, k), 0, sizeof(struct fuzzy_key_stat)); - } + if (k == kh_end(key->flags_stat)) { + /* Insert new flag */ + int r; + k = kh_put(fuzzy_key_flag_stat, key->flags_stat, res->v1.flag, &r); + memset(&kh_value(key->flags_stat, k), 0, sizeof(struct fuzzy_key_stat)); + } - flag_stat = &kh_value(key->flags_stat, k); - rspamd_fuzzy_update_key_stat(matched, flag_stat, cmd, res, timestamp); + flag_stat = &kh_value(key->flags_stat, k); + rspamd_fuzzy_update_key_stat(matched, flag_stat, cmd, res, timestamp); + } } if (ip_stat) { @@ -798,21 +800,10 @@ rspamd_fuzzy_make_reply (struct rspamd_fuzzy_cmd *cmd, result->v1.tag = cmd->tag; memcpy (&session->reply.rep, result, sizeof (*result)); - rspamd_fuzzy_update_stats (session->ctx, - session->epoch, - result->v1.prob > 0.5, - flags & RSPAMD_FUZZY_REPLY_SHINGLE, - flags & RSPAMD_FUZZY_REPLY_DELAY, - session->key, - session->ip_stat, - cmd->cmd, - result, - session->timestamp); - if (flags & RSPAMD_FUZZY_REPLY_DELAY) { /* Hash is too fresh, need to delay it */ session->reply.rep.ts = 0; - session->reply.rep.v1.prob = 0.0; + session->reply.rep.v1.prob = 0.0f; session->reply.rep.v1.value = 0; } @@ -882,6 +873,17 @@ rspamd_fuzzy_make_reply (struct rspamd_fuzzy_cmd *cmd, session->reply.rep.v1.value = 0; session->reply.rep.v1.flag = 0; } + + rspamd_fuzzy_update_stats (session->ctx, + session->epoch, + session->reply.rep.v1.prob > 0.5f, + flags & RSPAMD_FUZZY_REPLY_SHINGLE, + flags & RSPAMD_FUZZY_REPLY_DELAY, + session->key, + session->ip_stat, + cmd->cmd, + &session->reply.rep, + session->timestamp); } rspamd_fuzzy_write_reply (session); |