summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuwentan <[email protected]>2024-01-08 19:27:44 +0800
committerliuwentan <[email protected]>2024-01-08 19:27:44 +0800
commit59fdd5b2ce187051261166c0d9c298a73e3d8175 (patch)
treeb9ebeb1055b9f861db704ee7d7046a7aca9790f3
parentc659bbd0da9b3f630c2666e5d4a83c2f90d9504a (diff)
[HTTP_DECODER]add fieldstat4
-rw-r--r--.gitlab-ci.yml2
-rw-r--r--src/http_decoder/CMakeLists.txt4
-rw-r--r--src/http_decoder/http_decoder.c109
-rw-r--r--src/http_decoder/http_decoder_half.c20
-rw-r--r--src/http_decoder/http_decoder_half.h2
5 files changed, 115 insertions, 22 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index da235f7..8b8a2ef 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,7 +6,7 @@ variables:
INSTALL_DEPENDENCY_LIBRARY: sapp sapp-devel framework_env libMESA_prof_load-devel
libMESA_htable-devel libMESA_jump_layer
libMESA_handle_logger-devel libMESA_field_stat2-devel
- libfieldstat3-devel libbreakpad_mini-devel libcjson-devel
+ libfieldstat3-devel libfieldstat4-devel libbreakpad_mini-devel libcjson-devel
zlib-devel brotli-devel
SYMBOL_TARGET: stellar-c
TEST_NAME: gtest_stellar-c
diff --git a/src/http_decoder/CMakeLists.txt b/src/http_decoder/CMakeLists.txt
index 34fb779..7ba1de5 100644
--- a/src/http_decoder/CMakeLists.txt
+++ b/src/http_decoder/CMakeLists.txt
@@ -1,9 +1,11 @@
add_definitions(-fPIC)
+include_directories(/opt/MESA/include/)
+
set(HTTP_SRC http_decoder.c http_decoder_utils.c http_decoder_half.c
http_decoder_table.c http_decoder_string.c http_content_decompress.c)
add_library(http_decoder SHARED ${HTTP_SRC})
#set_target_properties(http_decoder_shared PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
-target_link_libraries(http_decoder z brotlidec llhttp-static)
+target_link_libraries(http_decoder z brotlidec llhttp-static fieldstat4)
set_target_properties(http_decoder PROPERTIES PREFIX "") \ No newline at end of file
diff --git a/src/http_decoder/http_decoder.c b/src/http_decoder/http_decoder.c
index 3e4e973..b69887a 100644
--- a/src/http_decoder/http_decoder.c
+++ b/src/http_decoder/http_decoder.c
@@ -11,6 +11,7 @@
#include <assert.h>
#include <stdio.h>
+#include <unistd.h>
#include "stellar/utils.h"
#include "stellar/session.h"
@@ -20,13 +21,16 @@
#include "http_decoder_half.h"
#include "http_decoder_table.h"
#include "llhttp.h"
+#include "fieldstat/fieldstat_easy.h"
#define HTTP_IDENTIFY_LEN 16
-#define HTTP_DECODER_RESULT_QUEUE_SIZE 16
+#define HD_RESULT_QUEUE_SIZE 16
#define HD_IS_CACHE_BODY 1
const char *http_decoder_topic = "HTTP_DECODER_MESSAGE";
+const char *fs_file_name = "http_decoder.fs";
+const struct fieldstat_tag TEST_TAG_INT = {"INT_TAG ", TAG_INTEGER, {.value_longlong = 100}};
struct http_decoder_result {
struct http_decoder_half_data *req_data;
@@ -65,8 +69,12 @@ struct http_decoder_context {
int plugin_id;
int topic_id;
int ex_data_idx;
- struct stellar *st;
- struct http_decoder *decoder;
+ int fs_incoming_bytes_id;
+ int fs_incoming_pkts_id;
+ int fs_incoming_trans_id;
+ struct fieldstat_easy *fse;
+ struct stellar *st;
+ struct http_decoder *decoder;
struct http_event_context *http_ev_ctx;
};
@@ -395,7 +403,7 @@ int http_decoder_entry(struct session *sess, int events,
}
}
- queue = http_decoder_result_queue_new(HTTP_DECODER_RESULT_QUEUE_SIZE);
+ queue = http_decoder_result_queue_new(HD_RESULT_QUEUE_SIZE);
queue->ref_session = sess;
session_set_ex_data(sess, ctx->ex_data_idx, queue);
}
@@ -404,6 +412,8 @@ int http_decoder_entry(struct session *sess, int events,
return 0;
}
+
+
int dir = packet_get_direction(pkt);
if (dir < 0) {
return -1;
@@ -426,6 +436,15 @@ int http_decoder_entry(struct session *sess, int events,
http_decoder_half_parse(cur_half, ctx->http_ev_ctx, payload, payload_len);
+ long long trans_cnt = http_decoder_half_trans_count(cur_half);
+
+ fieldstat_easy_counter_incrby(ctx->fse, 0, ctx->fs_incoming_bytes_id,
+ &TEST_TAG_INT, 1, (long long)payload_len);
+ fieldstat_easy_counter_incrby(ctx->fse, 0, ctx->fs_incoming_pkts_id,
+ &TEST_TAG_INT, 1, 1);
+ fieldstat_easy_counter_incrby(ctx->fse, 0, ctx->fs_incoming_trans_id,
+ &TEST_TAG_INT, 1, trans_cnt);
+
return 0;
}
@@ -450,6 +469,35 @@ http_message_free(void *msg, void *cb_arg)
FREE(message);
}
+static void
+_http_decoder_context_free(struct http_decoder_context *ctx)
+{
+ if (NULL == ctx) {
+ return;
+ }
+
+ if (ctx->http_ev_ctx != NULL) {
+ FREE(ctx->http_ev_ctx);
+ }
+
+ if (ctx->fse != NULL) {
+ fieldstat_easy_free(ctx->fse);
+ ctx->fse = NULL;
+ }
+
+ if (ctx->topic_id >= 0) {
+ session_mq_destroy_topic(ctx->st, ctx->topic_id);
+ ctx->topic_id = -1;
+ }
+
+ if (ctx->decoder != NULL) {
+ http_decoder_free(ctx->decoder);
+ ctx->decoder = NULL;
+ }
+
+ FREE(ctx);
+}
+
void *http_decoder_init(struct stellar *st)
{
struct http_decoder_context *ctx = CALLOC(struct http_decoder_context, 1);
@@ -473,10 +521,48 @@ void *http_decoder_init(struct stellar *st)
}
ctx->topic_id = topic_id;
+ ctx->fse = fieldstat_easy_new(1, "http_decoder_statistics", NULL, 0);
+ if (NULL == ctx->fse) {
+ fprintf(stderr, "fieldstat_easy_new failed.");
+ goto failed;
+ }
+
+ ctx->fs_incoming_bytes_id =
+ fieldstat_easy_register_counter(ctx->fse, "incoming_bytes");
+ if (ctx->fs_incoming_bytes_id < 0) {
+ fprintf(stderr, "fieldstat_easy_register_counter incoming_bytes failed.");
+ goto failed;
+ }
+
+ ctx->fs_incoming_trans_id =
+ fieldstat_easy_register_counter(ctx->fse, "incoming_trans");
+ if (ctx->fs_incoming_trans_id < 0) {
+ fprintf(stderr, "fieldstat_easy_register_counter incoming_trans failed.");
+ goto failed;
+ }
+
+ ctx->fs_incoming_pkts_id =
+ fieldstat_easy_register_counter(ctx->fse, "incoming_pkts");
+ if (ctx->fs_incoming_pkts_id < 0) {
+ fprintf(stderr, "fieldstat_easy_register_counter incoming_pkts failed.");
+ goto failed;
+ }
+
+ int ret = fieldstat_easy_enable_auto_output(ctx->fse, fs_file_name, 3);
+ if (ret < 0) {
+ fprintf(stderr, "fieldstat_easy_enable_auto_output failed.");
+ goto failed;
+ }
+ sleep(3);
+
printf("http_decoder_init: ex_data_idx:%d, plugin_id:%d, topic_id:%d\n",
ctx->ex_data_idx, ctx->plugin_id, ctx->topic_id);
return ctx;
+
+failed:
+ _http_decoder_context_free(ctx);
+ return NULL;
}
void http_decoder_exit(void *decoder_ctx)
@@ -488,20 +574,9 @@ void http_decoder_exit(void *decoder_ctx)
struct http_decoder_context *ctx =
(struct http_decoder_context *)decoder_ctx;
- if (ctx->http_ev_ctx != NULL) {
- FREE(ctx->http_ev_ctx);
- }
-
- if (ctx->decoder != NULL) {
- http_decoder_free(ctx->decoder);
- ctx->decoder = NULL;
- }
-
- if (ctx->topic_id >= 0) {
- session_mq_destroy_topic(ctx->st, ctx->topic_id);
- }
+ _http_decoder_context_free(ctx);
- FREE(decoder_ctx);
+ FREE(ctx);
}
enum http_message_type
diff --git a/src/http_decoder/http_decoder_half.c b/src/http_decoder/http_decoder_half.c
index 7030036..a122cf4 100644
--- a/src/http_decoder/http_decoder_half.c
+++ b/src/http_decoder/http_decoder_half.c
@@ -43,6 +43,7 @@ struct http_decoder_half {
enum http_event event;
http_event_cb *http_ev_cb;
void *http_ev_ctx;
+ long long trans_counter;
};
// #define HTTP_DECODER_DEBUG
@@ -105,6 +106,7 @@ on_message_begin(llhttp_t *http)
half->event = HTTP_EVENT_INIT;
half->ref_data = NULL;
+ half->trans_counter++;
return 0;
}
@@ -733,9 +735,9 @@ http_decoder_half_parse(struct http_decoder_half *half, void *http_ev_ctx,
}
if (ret < 0) {
- fprintf(stderr,
- "llhttp_execute parse error: %s err_reason:%s\n",
- llhttp_errno_name(half->error), half->parser.reason);
+ // fprintf(stderr,
+ // "llhttp_execute parse error: %s err_reason:%s\n",
+ // llhttp_errno_name(half->error), half->parser.reason);
return -1;
}
@@ -779,6 +781,18 @@ http_decoder_half_parse(struct http_decoder_half *half, void *http_ev_ctx,
return 0;
}
+long long http_decoder_half_trans_count(struct http_decoder_half *half)
+{
+ if (NULL == half) {
+ return 0;
+ }
+
+ long long trans_cnt = half->trans_counter;
+ half->trans_counter = 0;
+
+ return trans_cnt;
+}
+
struct http_decoder_half_data *
http_decoder_half_data_new()
{
diff --git a/src/http_decoder/http_decoder_half.h b/src/http_decoder/http_decoder_half.h
index 0f62fdf..327a3fa 100644
--- a/src/http_decoder/http_decoder_half.h
+++ b/src/http_decoder/http_decoder_half.h
@@ -62,6 +62,8 @@ int
http_decoder_half_parse(struct http_decoder_half *half, void *ev_ctx,
const char *data, size_t len);
+long long http_decoder_half_trans_count(struct http_decoder_half *half);
+
//http decoder half data API
struct http_decoder_half_data *
http_decoder_half_data_new();