fieldstat增加health check功能的计数

This commit is contained in:
luwenpeng
2023-02-24 14:43:47 +08:00
parent 57cd21ae53
commit 7dd877cea8
7 changed files with 77 additions and 11 deletions

View File

@@ -5,11 +5,13 @@
#include <MESA/Maat_rule.h>
#include <MESA/MESA_prof_load.h>
#include "global_metrics.h"
#include "health_check.h"
#include "raw_packet.h"
#include "policy.h"
#include "utils.h"
#include "log.h"
#include "sce.h"
/******************************************************************************
* Struct policy_enforcer
@@ -206,6 +208,8 @@ const char *session_action_reason_to_string(enum session_action_reason session_a
return "bypass_due_failure_action";
case ACTION_BYPASS_DUE_INVALID_POLICY:
return "bypass_due_invalid_policy";
case ACTION_BYPASS_DUE_INVALID_SF_MAC:
return "bypass_due_invalid_sf_mac";
case ACTION_BLOCK_DUE_UNAVAILABLE_ACTION:
return "block_due_unavailable_action";
case ACTION_BLOCK_DUE_FAILURE_ACTION:
@@ -1037,8 +1041,11 @@ static void select_sf_by_nearby_and_active(struct policy_enforcer *enforcer, str
// return : SESSION_ACTION_BYPASS, not care selected_sf_profile_id
// return : SESSION_ACTION_BLOCK, not care selected_sf_profile_id
// return : SESSION_ACTION_FORWARD, care selected_sf_profile_id
static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sff_param, struct fixed_num_array *array, int *selected_sf_profile_id, enum session_action_reason *sf_action_reason)
static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sff_param, struct fixed_num_array *array, int *selected_sf_profile_id, enum session_action_reason *sf_action_reason, struct session_ctx *s_ctx)
{
struct thread_ctx *thread = (struct thread_ctx *)s_ctx->ref_thread_ctx;
struct global_metrics *g_metrics = thread->ref_metrics;
*selected_sf_profile_id = -1;
int sf_is_active = 0;
int sf_profile_id = 0;
@@ -1055,12 +1062,16 @@ static enum session_action select_sf_by_ldbc(uint64_t hash, struct sff_param *sf
if (sf_is_active)
{
__atomic_fetch_add(&g_metrics->sf_active_times, 1, __ATOMIC_RELAXED);
*selected_sf_profile_id = sf_profile_id;
*sf_action_reason = ACTION_FORWAED_DUE_SELECTED_AVAILABLE_SF;
return SESSION_ACTION_FORWARD;
}
else
{
__atomic_fetch_add(&g_metrics->sf_inactive_times, 1, __ATOMIC_RELAXED);
if (sff_param->sff_exception.fail_action == FAILURE_ACTION_RE_DISPATCH)
{
fixed_num_array_del_elem(array, sf_profile_id);
@@ -1403,8 +1414,11 @@ void selected_chaining_bref(struct selected_chaining *chaining)
LOG_DEBUG("%s: selected_chaining_bref: %s}", LOG_TAG_POLICY, buff);
}
void policy_enforce_select_chaining(struct selected_chaining *chaining, struct policy_enforcer *enforcer, struct raw_pkt_parser *parser, int policy_id, int dir_is_internal)
void policy_enforce_select_chaining(struct selected_chaining *chaining, struct policy_enforcer *enforcer, struct raw_pkt_parser *parser, int policy_id, int dir_is_internal, struct session_ctx *s_ctx)
{
struct thread_ctx *thread = (struct thread_ctx *)s_ctx->ref_thread_ctx;
struct global_metrics *g_metrics = thread->ref_metrics;
uint64_t hash_value = 0;
char buffer[16] = {0};
struct sf_param *sf_param = NULL;
@@ -1460,7 +1474,7 @@ void policy_enforce_select_chaining(struct selected_chaining *chaining, struct p
}
hash_value = raw_packet_parser_get_hash_value(parser, sff_param->sff_ldbc.method, dir_is_internal);
item->sf_action = select_sf_by_ldbc(hash_value, sff_param, &array, &(item->sf_profile_id), &(item->sf_action_reason));
item->sf_action = select_sf_by_ldbc(hash_value, sff_param, &array, &(item->sf_profile_id), &(item->sf_action_reason), s_ctx);
LOG_DEBUG("%s: chaining policy %d -> sff_profile %d sf_profile_ids_num %d (after filter ldbc)", LOG_TAG_POLICY, policy_id, item->sff_profile_id, fixed_num_array_count_elem(&array));
if (item->sf_action != SESSION_ACTION_FORWARD)
{
@@ -1495,7 +1509,22 @@ void policy_enforce_select_chaining(struct selected_chaining *chaining, struct p
}
else
{
health_check_session_get_mac(item->sf_profile_id, item->sf_dst_mac);
if (health_check_session_get_mac(item->sf_profile_id, item->sf_dst_mac) == 0)
{
__atomic_fetch_add(&g_metrics->sf_mac_exist_times, 1, __ATOMIC_RELAXED);
}
else
{
__atomic_fetch_add(&g_metrics->sf_mac_noexist_times, 1, __ATOMIC_RELAXED);
LOG_ERROR("%s: failed to get sf mac address of selected profile %d, bypass current sff !!!", LOG_TAG_POLICY, item->sf_profile_id);
item->sf_action = SESSION_ACTION_BYPASS;
item->sf_action_reason = ACTION_BYPASS_DUE_INVALID_SF_MAC;
chaining->chaining_used++;
sff_param_free(sff_param);
sf_param_free(sf_param);
continue;
}
}
chaining->chaining_used++;