summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2024-07-26 16:50:51 +0800
committerfengweihao <[email protected]>2024-07-26 16:50:51 +0800
commit83f51432b1b86d6d35eb5c3e10e6cbca29a1a45a (patch)
tree923c63905a9746f8979d58de3885a80ef025adae /plugin
parenta59b9390336dafa0ee1f05e74e52411d175b9843 (diff)
TSG-21854 TFE使用fieldstat4序列化Manipulation Policy的metric并输出到kafka
Diffstat (limited to 'plugin')
-rw-r--r--plugin/business/doh/src/doh.cpp26
-rw-r--r--plugin/business/tsg-http/src/tsg_http.cpp28
-rw-r--r--plugin/business/tsg-http/src/tsg_logger.cpp2
3 files changed, 20 insertions, 36 deletions
diff --git a/plugin/business/doh/src/doh.cpp b/plugin/business/doh/src/doh.cpp
index ca99c44..f51e9ce 100644
--- a/plugin/business/doh/src/doh.cpp
+++ b/plugin/business/doh/src/doh.cpp
@@ -824,7 +824,12 @@ int doh_on_data(const struct tfe_stream *stream, const struct tfe_http_session *
void doh_send_metric_log(const struct tfe_stream * stream, struct doh_ctx *ctx, unsigned int thread_id)
{
size_t c2s_byte_num = 0, s2c_byte_num =0;
- struct tfe_fieldstat_easy_t *fieldstat = tfe_get_fieldstat_handle();
+
+ struct filedstat_easy_manipulation *fieldstat = tfe_get_fieldstat_handle()->manipulation;
+ if(fieldstat == NULL)
+ {
+ return;
+ }
fieldstat->tags[thread_id][TAG_VSYS_ID].value_longlong = ctx->result->vsys_id;
fieldstat->tags[thread_id][TAG_RULE_ID].value_longlong = ctx->result->config_id;
@@ -860,23 +865,10 @@ void doh_send_metric_log(const struct tfe_stream * stream, struct doh_ctx *ctx,
out_bytes = c2s_byte_num;
}
- tfe_fieldstat_easy_incrby(fieldstat, fieldstat->counter_array[COLUMN_HIT_COUNT], 1, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
- tfe_fieldstat_easy_incrby(fieldstat, fieldstat->counter_array[COLUMN_IN_BYTES], in_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
- tfe_fieldstat_easy_incrby(fieldstat, fieldstat->counter_array[COLUMN_OUT_BYTES], out_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
-
- char **payload = NULL;
- size_t payload_len = 0;
+ tfe_fieldstat_manipulation_incrby(fieldstat, fieldstat->counter_array[COLUMN_HIT_COUNT], 1, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
+ tfe_fieldstat_manipulation_incrby(fieldstat, fieldstat->counter_array[COLUMN_IN_BYTES], in_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
+ tfe_fieldstat_manipulation_incrby(fieldstat, fieldstat->counter_array[COLUMN_OUT_BYTES], out_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
- fieldstat_easy_output_array(fieldstat->fseasy, &payload, &payload_len);
- if (payload)
- {
- for (size_t i = 0; i < payload_len; i++)
- {
- kafka_send(tfe_get_kafka_handle(), TOPIC_RULE_HITS, payload[i], strlen(payload[i]));
- FREE(&payload[i]);
- }
- FREE(&payload);
- }
return;
}
diff --git a/plugin/business/tsg-http/src/tsg_http.cpp b/plugin/business/tsg-http/src/tsg_http.cpp
index 47dc44b..9a684ad 100644
--- a/plugin/business/tsg-http/src/tsg_http.cpp
+++ b/plugin/business/tsg-http/src/tsg_http.cpp
@@ -1404,7 +1404,12 @@ void proxy_send_metric_log(const struct tfe_stream * stream, struct proxy_http_c
proxy_action_map[PX_ACTION_REJECT]="deny";
proxy_action_map[PX_ACTION_WHITELIST]="allow";
const char *manipulate_action_map[]= {"redirect","block","replace","hijack","insert","edit_element","run_script"};
- struct tfe_fieldstat_easy_t *fieldstat = tfe_get_fieldstat_handle();
+
+ struct filedstat_easy_manipulation *fieldstat = tfe_get_fieldstat_handle()->manipulation;
+ if(fieldstat == NULL)
+ {
+ return;
+ }
for(i=0; i< ctx->n_enforce; i++)
{
@@ -1463,25 +1468,12 @@ void proxy_send_metric_log(const struct tfe_stream * stream, struct proxy_http_c
in_bytes=0;
out_bytes=0;
}
-
- tfe_fieldstat_easy_incrby(fieldstat, fieldstat->counter_array[COLUMN_HIT_COUNT], hit_cnt, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
- tfe_fieldstat_easy_incrby(fieldstat, fieldstat->counter_array[COLUMN_IN_BYTES], in_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
- tfe_fieldstat_easy_incrby(fieldstat, fieldstat->counter_array[COLUMN_OUT_BYTES], out_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
- }
- char **payload = NULL;
- size_t payload_len = 0;
-
- fieldstat_easy_output_array(fieldstat->fseasy, &payload, &payload_len);
- if (payload)
- {
- for (size_t i = 0; i < payload_len; i++)
- {
- kafka_send(tfe_get_kafka_handle(), TOPIC_RULE_HITS, payload[i], strlen(payload[i]));
- FREE(&payload[i]);
- }
- FREE(&payload);
+ tfe_fieldstat_manipulation_incrby(fieldstat, fieldstat->counter_array[COLUMN_HIT_COUNT], hit_cnt, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
+ tfe_fieldstat_manipulation_incrby(fieldstat, fieldstat->counter_array[COLUMN_IN_BYTES], in_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
+ tfe_fieldstat_manipulation_incrby(fieldstat, fieldstat->counter_array[COLUMN_OUT_BYTES], out_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
}
+
return;
}
diff --git a/plugin/business/tsg-http/src/tsg_logger.cpp b/plugin/business/tsg-http/src/tsg_logger.cpp
index 348e011..b3a324b 100644
--- a/plugin/business/tsg-http/src/tsg_logger.cpp
+++ b/plugin/business/tsg-http/src/tsg_logger.cpp
@@ -90,7 +90,7 @@ size_t file_bucket_upload_once(struct proxy_logger* handle, char *uuid, struct e
{
TFE_LOG_ERROR(handle->local_logger, "Mpack writer destroy is error(%s), uuid: %s", mpack_error_to_string(errorno), uuid);
}
- kafka_send(tfe_get_kafka_handle(), TOPIC_FILE_STREAM, mpack_data, mpack_size);
+ kafka_send2(tfe_get_kafka_handle(), TOPIC_FILE_STREAM, mpack_data, mpack_size);
free(mpack_data);
mpack_data = NULL;