diff options
| author | 刘畅 <[email protected]> | 2023-03-31 08:28:37 +0000 |
|---|---|---|
| committer | 刘畅 <[email protected]> | 2023-03-31 08:28:37 +0000 |
| commit | 2c4e75718d0c1a90754dea86ad7f4ba51372dc46 (patch) | |
| tree | 80ad744d1529a67d9e9849b4eea776f2f8021880 | |
| parent | 5436e343bbce831d500732873bb525a0a7d8505c (diff) | |
| parent | afb82fe1c3ac886578648fa7bc17fe191bea6e7c (diff) | |
Merge branch 'new_format_metric' into 'rel'v1.1.3
New format metric
See merge request liuchang/shaping-engine!4
| -rw-r--r-- | shaping/src/shaper_stat.cpp | 34 | ||||
| -rw-r--r-- | shaping/test/gtest_shaper.cpp | 34 |
2 files changed, 42 insertions, 26 deletions
diff --git a/shaping/src/shaper_stat.cpp b/shaping/src/shaper_stat.cpp index b340995..6b49182 100644 --- a/shaping/src/shaper_stat.cpp +++ b/shaping/src/shaper_stat.cpp @@ -10,6 +10,8 @@ #include "shaper.h" #include "shaper_stat.h" +#define SHAPER_STAT_ROW_NAME "traffic_shaping_rule_hits" + struct shaper_stat_conf { int enable_backgroud_thread; int output_interval_ms; @@ -136,9 +138,9 @@ void shaper_stat_drop_inc(struct shaping_stat *stat, int rule_id, int profile_id shaper_stat_tags_build(rule_id, profile_id, priority, SHAPING_PROFILE_TYPE_PRIMARY); if (direction == SHAPING_DIR_IN) { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_DROP_PKTS_IDX], "shaping_metric_row", 1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_DROP_PKTS_IDX], SHAPER_STAT_ROW_NAME, 1, tags, TAG_IDX_MAX, thread_id); } else { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_DROP_PKTS_IDX], "shaping_metric_row", 1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_DROP_PKTS_IDX], SHAPER_STAT_ROW_NAME, 1, tags, TAG_IDX_MAX, thread_id); } return; @@ -150,11 +152,11 @@ void shaper_stat_forward_inc(struct shaping_stat *stat, int rule_id, int profile shaper_stat_tags_build(rule_id, profile_id, priority, profile_type); if (direction == SHAPING_DIR_IN) { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_PKTS_IDX], "shaping_metric_row", 1, tags, TAG_IDX_MAX, thread_id); - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_BYTES_IDX], "shaping_metric_row", pkt_len, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_PKTS_IDX], SHAPER_STAT_ROW_NAME, 1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_BYTES_IDX], SHAPER_STAT_ROW_NAME, pkt_len, tags, TAG_IDX_MAX, thread_id); } else { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_PKTS_IDX], "shaping_metric_row", 1, tags, TAG_IDX_MAX, thread_id); - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_BYTES_IDX], "shaping_metric_row", pkt_len, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_PKTS_IDX], SHAPER_STAT_ROW_NAME, 1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_BYTES_IDX], SHAPER_STAT_ROW_NAME, pkt_len, tags, TAG_IDX_MAX, thread_id); } return; @@ -176,14 +178,14 @@ void shaper_stat_forward_all_rule_inc(struct shaping_stat *stat, struct shaping_ void shaper_stat_queueing_session_inc(struct shaping_stat *stat, int rule_id, int profile_id, int priority, int profile_type, int thread_id) { shaper_stat_tags_build(rule_id, profile_id, priority, profile_type); - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[QUEUEING_SESSIONS_IDX], "shaping_metric_row", 1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[QUEUEING_SESSIONS_IDX], SHAPER_STAT_ROW_NAME, 1, tags, TAG_IDX_MAX, thread_id); return; } void shaper_stat_queueing_session_dec(struct shaping_stat *stat, int rule_id, int profile_id, int priority, int profile_type, int thread_id) { shaper_stat_tags_build(rule_id, profile_id, priority, profile_type); - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[QUEUEING_SESSIONS_IDX], "shaping_metric_row", -1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[QUEUEING_SESSIONS_IDX], SHAPER_STAT_ROW_NAME, -1, tags, TAG_IDX_MAX, thread_id); return; } @@ -192,9 +194,9 @@ void shaper_stat_queueing_pkt_inc(struct shaping_stat *stat, int rule_id, int pr { shaper_stat_tags_build(rule_id, profile_id, priority, profile_type); if (direction == SHAPING_DIR_IN) { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_QUEUE_LEN_IDX], "shaping_metric_row", 1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_QUEUE_LEN_IDX], SHAPER_STAT_ROW_NAME, 1, tags, TAG_IDX_MAX, thread_id); } else { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_QUEUE_LEN_IDX], "shaping_metric_row", 1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_QUEUE_LEN_IDX], SHAPER_STAT_ROW_NAME, 1, tags, TAG_IDX_MAX, thread_id); } return; @@ -205,9 +207,9 @@ void shaper_stat_queueing_pkt_dec(struct shaping_stat *stat, int rule_id, int pr { shaper_stat_tags_build(rule_id, profile_id, priority, profile_type); if (direction == SHAPING_DIR_IN) { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_QUEUE_LEN_IDX], "shaping_metric_row", -1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_QUEUE_LEN_IDX], SHAPER_STAT_ROW_NAME, -1, tags, TAG_IDX_MAX, thread_id); } else { - fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_QUEUE_LEN_IDX], "shaping_metric_row", -1, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_QUEUE_LEN_IDX], SHAPER_STAT_ROW_NAME, -1, tags, TAG_IDX_MAX, thread_id); } return; @@ -220,14 +222,14 @@ void shaper_stat_max_latency_update(struct shaping_stat *stat, int rule_id, int shaper_stat_tags_build(rule_id, profile_id, priority, profile_type); if (direction == SHAPING_DIR_IN) { - old_latency = fieldstat_dynamic_table_metric_value_get(stat->instance, stat->table_id, stat->column_ids[IN_MAX_LATENCY_IDX], "shaping_metric_row", tags, TAG_IDX_MAX, thread_id); + old_latency = fieldstat_dynamic_table_metric_value_get(stat->instance, stat->table_id, stat->column_ids[IN_MAX_LATENCY_IDX], SHAPER_STAT_ROW_NAME, tags, TAG_IDX_MAX, thread_id); if (latency > old_latency) { - fieldstat_dynamic_table_metric_value_set(stat->instance, stat->table_id, stat->column_ids[IN_MAX_LATENCY_IDX], "shaping_metric_row", latency, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_set(stat->instance, stat->table_id, stat->column_ids[IN_MAX_LATENCY_IDX], SHAPER_STAT_ROW_NAME, latency, tags, TAG_IDX_MAX, thread_id); } } else { - old_latency = fieldstat_dynamic_table_metric_value_get(stat->instance, stat->table_id, stat->column_ids[OUT_MAX_LATENCY_IDX], "shaping_metric_row", tags, TAG_IDX_MAX, thread_id); + old_latency = fieldstat_dynamic_table_metric_value_get(stat->instance, stat->table_id, stat->column_ids[OUT_MAX_LATENCY_IDX], SHAPER_STAT_ROW_NAME, tags, TAG_IDX_MAX, thread_id); if (latency > old_latency) { - fieldstat_dynamic_table_metric_value_set(stat->instance, stat->table_id, stat->column_ids[OUT_MAX_LATENCY_IDX], "shaping_metric_row", latency, tags, TAG_IDX_MAX, thread_id); + fieldstat_dynamic_table_metric_value_set(stat->instance, stat->table_id, stat->column_ids[OUT_MAX_LATENCY_IDX], SHAPER_STAT_ROW_NAME, latency, tags, TAG_IDX_MAX, thread_id); } } diff --git a/shaping/test/gtest_shaper.cpp b/shaping/test/gtest_shaper.cpp index 23d91a9..6106e11 100644 --- a/shaping/test/gtest_shaper.cpp +++ b/shaping/test/gtest_shaper.cpp @@ -106,56 +106,70 @@ static void shaping_stat_judge(char *file_line, int rule_id, int profile_id, int int queueing_sessions, unsigned char direction, char profile_type[]) { cJSON *json = NULL; + cJSON *fields_json = NULL; + cJSON *tags_json = NULL; cJSON *tmp_obj = NULL; char attr_name[32] = {0}; json = cJSON_Parse(file_line); ASSERT_TRUE(json != NULL); - tmp_obj = cJSON_GetObjectItem(json, "rule_id"); + tmp_obj = cJSON_GetObjectItem(json, "name"); + ASSERT_TRUE(tmp_obj != NULL); + EXPECT_STREQ("traffic_shaping_rule_hits", tmp_obj->valuestring); + + /******************parse tags***********************************/ + tags_json = cJSON_GetObjectItem(json, "tags"); + ASSERT_TRUE(tags_json != NULL); + + tmp_obj = cJSON_GetObjectItem(tags_json, "rule_id"); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(rule_id, atoi(tmp_obj->valuestring)); - tmp_obj = cJSON_GetObjectItem(json, "profile_id"); + tmp_obj = cJSON_GetObjectItem(tags_json, "profile_id"); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(profile_id, atoi(tmp_obj->valuestring)); - tmp_obj = cJSON_GetObjectItem(json, "priority"); + tmp_obj = cJSON_GetObjectItem(tags_json, "priority"); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(priority, atoi(tmp_obj->valuestring)); - tmp_obj = cJSON_GetObjectItem(json, "profile_type"); + tmp_obj = cJSON_GetObjectItem(tags_json, "profile_type"); ASSERT_TRUE(tmp_obj != NULL); EXPECT_STREQ(tmp_obj->valuestring, profile_type); - tmp_obj = cJSON_GetObjectItem(json, "queueing_sessions"); + /******************parse fields**********************************/ + fields_json = cJSON_GetObjectItem(json, "fields"); + ASSERT_TRUE(fields_json != NULL); + + tmp_obj = cJSON_GetObjectItem(fields_json, "queueing_sessions"); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(queueing_sessions, tmp_obj->valueint); snprintf(attr_name, sizeof(attr_name), "%s_pkts", direction == SHAPING_DIR_OUT ? "out" : "in"); - tmp_obj = cJSON_GetObjectItem(json, attr_name); + tmp_obj = cJSON_GetObjectItem(fields_json, attr_name); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(tx_pkts, tmp_obj->valueint); snprintf(attr_name, sizeof(attr_name), "%s_bytes", direction == SHAPING_DIR_OUT ? "out" : "in"); - tmp_obj = cJSON_GetObjectItem(json, attr_name); + tmp_obj = cJSON_GetObjectItem(fields_json, attr_name); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(tx_bytes, tmp_obj->valueint); snprintf(attr_name, sizeof(attr_name), "%s_drop_pkts", direction == SHAPING_DIR_OUT ? "out" : "in"); - tmp_obj = cJSON_GetObjectItem(json, attr_name); + tmp_obj = cJSON_GetObjectItem(fields_json, attr_name); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(drop_pkts, tmp_obj->valueint); if (max_latency != -1) { snprintf(attr_name, sizeof(attr_name), "%s_max_latency_us", direction == SHAPING_DIR_OUT ? "out" : "in"); - tmp_obj = cJSON_GetObjectItem(json, attr_name); + tmp_obj = cJSON_GetObjectItem(fields_json, attr_name); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(max_latency, tmp_obj->valueint); } snprintf(attr_name, sizeof(attr_name), "%s_queue_len", direction == SHAPING_DIR_OUT ? "out" : "in"); - tmp_obj = cJSON_GetObjectItem(json, attr_name); + tmp_obj = cJSON_GetObjectItem(fields_json, attr_name); ASSERT_TRUE(tmp_obj != NULL); EXPECT_EQ(queue_len, tmp_obj->valueint); |
