diff --git a/plugin/business/pangu-http/CMakeLists.txt b/plugin/business/pangu-http/CMakeLists.txt index a11a0fe..c8ab3a2 100644 --- a/plugin/business/pangu-http/CMakeLists.txt +++ b/plugin/business/pangu-http/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(pangu-http src/pangu_logger.cpp src/pangu_http.cpp src/pattern_replace.cpp src/pangu_web_cache.cpp) target_link_libraries(pangu-http PUBLIC common http tango-cache-client) -target_link_libraries(pangu-http PUBLIC librdkafka ctemplate-static cjson pcre2-static libdablooms pthread) +target_link_libraries(pangu-http PUBLIC librdkafka ctemplate-static cjson pcre2-static ratelimiter-static libdablooms pthread) target_link_libraries(pangu-http PUBLIC maatframe) add_executable(test_pattern_replace src/test_pattern_replace.cpp src/pattern_replace.cpp) diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp index 4197fb7..b7053a4 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/pangu-http/src/pangu_http.cpp @@ -987,7 +987,7 @@ error_out: Ratelimiter_handle_t ratelimit_handle_create(const char* profile_path, const char* static_section) { - int ret=0; + int ret=0, field_stat=0; int redis_port = 0, interval_sec = 0; char redis_server[TFE_STRING_MAX] = {0}; char token_name[TFE_STRING_MAX] = {0}; @@ -1000,13 +1000,27 @@ Ratelimiter_handle_t ratelimit_handle_create(const char* profile_path, const cha MESA_load_profile_string_def(profile_path, static_section, "token_name", token_name, sizeof(token_name), ""); MESA_load_profile_int_def(profile_path, static_section, "interval_sec", &(interval_sec), 1); - + if (g_pangu_rt->enable_rate != 1) + { + return NULL; + } ratelimit=Ratelimiter_create(token_name, g_pangu_rt->local_logger); - Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_INTERVAL_SEC, &interval_sec, sizeof(interval_sec)); Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_REDIS_IP, redis_server, strlen(redis_server) + 1); Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_REDIS_PORT, &redis_port, sizeof(redis_port)); + /*field stata for debug test**/ + MESA_load_profile_int_def(profile_path, static_section, "field_stat", &(field_stat), 0); + if (field_stat == 1) + { + MESA_load_profile_int_def(profile_path, static_section, "stat_port", &(redis_port), 6379); + MESA_load_profile_string_def(profile_path, static_section, "stat_server", redis_server, sizeof(redis_server), ""); + Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_FIELD_STAT, &field_stat, sizeof(field_stat)); + Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_STAT_IP, redis_server, strlen(redis_server)); + Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_STAT_PORT, &redis_port, sizeof(redis_port)); + Ratelimiter_set_opt(ratelimit, RATELIMITER_OPT_STAT_PATH, token_name, sizeof(token_name)); + Ratelimiter_stat_init(ratelimit); + } ret = Ratelimiter_start(ratelimit); if (ret < 0) { diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index dd2c413..5e61b95 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -97,7 +97,7 @@ set_property(TARGET nghttp2-static APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ### ratelimiter ExternalProject_Add(ratelimiter PREFIX ratelimiter URL ${CMAKE_CURRENT_SOURCE_DIR}/ratelimiter-1.1.0-x86_64.tar.gz - URL_MD5 54cc36713c2aaa8ff378ca342778e57d + URL_MD5 4e5d01586fef4165c4dfd1f1a3595e61 CONFIGURE_COMMAND "" BUILD_COMMAND make BUILD_IN_SOURCE 1) diff --git a/vendor/ratelimiter-1.1.0-x86_64.tar.gz b/vendor/ratelimiter-1.1.0-x86_64.tar.gz index 1435650..d127dcc 100644 Binary files a/vendor/ratelimiter-1.1.0-x86_64.tar.gz and b/vendor/ratelimiter-1.1.0-x86_64.tar.gz differ