Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[init] persistent feature #43

Open
wants to merge 52 commits into
base: live
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
cd61cea
[init] persistent feature
shabicheng Aug 27, 2020
346053b
[add] support log_producer_client_add_log_with_len_int32
shabicheng Sep 3, 2020
6aa5687
[modify] refine codes
shabicheng Sep 14, 2020
677965a
[modify] refine codes
shabicheng Sep 15, 2020
90737a3
[modify] fix replay fail
shabicheng Sep 16, 2020
522c4aa
[fix] invalid checkpoint when replay and stop immediately
shabicheng Sep 16, 2020
270bdc5
[modify] do not update checkpoint when replay nothing
shabicheng Sep 21, 2020
20f97d8
[modify] refine code as tingtao's review comments
shabicheng Sep 21, 2020
5935759
[modify] use native rfc822 time
shabicheng Oct 15, 2020
b733738
[modify] remove libcurl
shabicheng Dec 2, 2020
a4cb176
[modify] refine log http interface
shabicheng Dec 2, 2020
effc27b
[fix] time offset not work
shabicheng Dec 2, 2020
b773cf0
[modify] refine doc
shabicheng Dec 4, 2020
bf21122
[modify] refine
shabicheng Dec 9, 2020
0cd96c4
Merge branch 'persistent' of git+ssh://github.com/aliyun/aliyun-log-c…
shabicheng Dec 9, 2020
fdc6713
[modify] refine retry params
shabicheng Dec 15, 2020
b280b2c
[add] dropUnauthorizedLog param, default value is do not drop
shabicheng Dec 17, 2020
63f4b8c
[modify] refine readme
shabicheng Dec 17, 2020
e46091f
[add] add log with time
shabicheng Dec 23, 2020
79a3727
[modify] refine ring file write
shabicheng Jan 5, 2021
6bb07d4
[add] support register time function to get server time
shabicheng Jan 20, 2021
5c46f49
[modify] rebuild log time when local time is invalid
shabicheng Mar 10, 2021
009083f
[modify] refine params to reduce wakeup
shabicheng Mar 25, 2021
cb679aa
[modify] refine send log directly
shabicheng Apr 14, 2021
838744d
chore: persitent build
Aug 25, 2021
48879b2
chore: android build
Aug 25, 2021
b6f3082
feat: log_producer_config support set_callback_from_sender_thread option
Aug 25, 2021
6e47ab5
fix: __pack_id__ may duplicative issues
Aug 25, 2021
e3c4a58
feat: remove file info when print log
Aug 25, 2021
7f125a8
Revert "[modify] refine send log directly" because of android issues
Aug 30, 2021
7976bd4
feat: support dynamic endpoint、project、logstore、accesskeyId、accesskey…
Sep 23, 2021
319f7a7
feat: refine android publish script
Sep 23, 2021
1696d9d
[fix] crash caused by too large log size
shabicheng Sep 24, 2021
7c4b395
Merge remote-tracking branch 'origin/persistent' into persistent
Nov 25, 2021
f08216e
feat: refine inner_log
Nov 25, 2021
0839a19
feat: support send log data through PutWebtracking
Nov 30, 2021
6499c9d
feat: escape json
Dec 28, 2021
72a1349
[fix] change gmtime to gmtime_r
shabicheng Jan 26, 2022
72dbe7b
feat: check threadid while destroy producer
Mar 18, 2022
f5b10a2
Merge branch 'feature/webtracking' into persistent
Mar 18, 2022
2557e87
feat: android support armeabi
Mar 31, 2022
2eade3e
fix: mem leak
Apr 22, 2022
17bafb7
feat: refine flusher & sender interval
Jun 27, 2022
a52be96
feat: return LOG_PRODUCER_PARAMETERS_INVALID if parameters invalid
Jun 30, 2022
7ed941b
feat: refine clock get time func and support osx
Jul 7, 2022
35f0a16
feat: support key-hash mode
Aug 2, 2022
911553a
feat: support inject http header
Sep 23, 2022
80a1e71
[modify] change in_buffer_log_sizes to in_buffer_log_offsets
shabicheng Feb 3, 2023
645bc6a
[modify] refine inner_logs
shabicheng Feb 3, 2023
0d71d30
fix network panic log
Jul 3, 2023
a29886b
Merge pull request #68 from EvanLjp/persistent-fix-network-panic
shabicheng Sep 27, 2023
51feee6
persistent support Windows (#81)
crimson-gao Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(PRODUCER_SAMPLE_SOURCE_FILES log_producer_sample.c)

set(PRODUCER_BENCHMARK_SOURCE_FILES log_producer_benchmark.c)

set(PRODUCER_FRAME_SOURCE_FILES video_frame_producer_sample.c)
set(PRODUCER_PERSISTENT_SAMPLE_SOURCE_FILES log_producer_persistent_sample.c)

include_directories (${CURL_INCLUDE_DIR})
include_directories ("${CMAKE_SOURCE_DIR}/src")
Expand All @@ -19,8 +19,8 @@ find_library(CURL_LIBRARY curl)
find_library(PTHREAD_LIBRARY pthread)
find_library(RT_LIBRARY rt)
find_library(M_LIBRARY m)
find_library(SSL_LIBRARY ssl)
find_library(CRYPTO_LIBRARY crypto)
#find_library(SSL_LIBRARY ssl)
#find_library(CRYPTO_LIBRARY crypto)
find_library(ZLIB_LIBRARY z)
find_library(DL_LIBRARY dl)

Expand All @@ -31,8 +31,8 @@ function(_TARGET_SAMPLE_LIBRARIES SAMPLE_BIN_NAME SOURCE_FILES)
target_link_libraries(${SAMPLE_BIN_NAME} ${PTHREAD_LIBRARY})
target_link_libraries(${SAMPLE_BIN_NAME} ${M_LIBRARY})
target_link_libraries(${SAMPLE_BIN_NAME} ${DL_LIBRARY})
target_link_libraries(${SAMPLE_BIN_NAME} ${SSL_LIBRARY})
target_link_libraries(${SAMPLE_BIN_NAME} ${CRYPTO_LIBRARY})
#target_link_libraries(${SAMPLE_BIN_NAME} ${SSL_LIBRARY})
#target_link_libraries(${SAMPLE_BIN_NAME} ${CRYPTO_LIBRARY})
target_link_libraries(${SAMPLE_BIN_NAME} ${ZLIB_LIBRARY})
endfunction()

Expand All @@ -42,4 +42,5 @@ _TARGET_SAMPLE_LIBRARIES(log_post_logs_sample "${POST_LOGS_SOURCE_FILES}")

_TARGET_SAMPLE_LIBRARIES(log_producer_benchmark "${PRODUCER_BENCHMARK_SOURCE_FILES}")

_TARGET_SAMPLE_LIBRARIES(video_frame_producer_sample "${PRODUCER_FRAME_SOURCE_FILES}")
_TARGET_SAMPLE_LIBRARIES(log_producer_persistent_sample "${PRODUCER_PERSISTENT_SAMPLE_SOURCE_FILES}")

7 changes: 6 additions & 1 deletion sample/log_post_logs_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ void post_logs_with_http_cont_lz4_log_option()
printf("serialize_to_proto_buf_with_malloc_lz4 failed\n");
exit(1);
}
log_post_option option;
memset(&option, 0, sizeof(log_post_option));
option.connect_timeout = 10;
option.operation_timeout = 15;
option.compress_type = 0;
post_log_result * rst = post_logs_from_lz4buf(LOG_ENDPOINT, ACCESS_KEY_ID,
ACCESS_KEY_SECRET, NULL,
PROJECT_NAME, LOGSTORE_NAME,
pLZ4Buf);
pLZ4Buf, &option);
printf("result %d %d \n", i, rst->statusCode);
if (rst->errorMessage != NULL)
{
Expand Down
4 changes: 2 additions & 2 deletions sample/log_producer_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void builder_speed_test(int32_t logsPerGroup)
aos_error_log("total time sec %d ", (time(NULL) - startTime));
}

void on_log_send_done(const char * config_name, log_producer_result result, size_t log_bytes, size_t compressed_bytes, const char * req_id, const char * message)
void on_log_send_done(const char * config_name, log_producer_result result, size_t log_bytes, size_t compressed_bytes, const char * req_id, const char * message, const unsigned char * raw_buffer, void *user_param)
{
if (result == LOG_PRODUCER_OK)
{
Expand Down Expand Up @@ -161,7 +161,7 @@ log_producer * create_log_producer_wrapper(on_log_producer_send_done_function on
// set send thread
log_producer_config_set_send_thread_count(config, 16);

return create_log_producer(config, on_send_done);
return create_log_producer(config, on_send_done, NULL);
}

#define MUTLI_THREAD_COUNT 16
Expand Down
147 changes: 147 additions & 0 deletions sample/log_producer_persistent_sample.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// Created by ZhangCheng on 26/12/2017.
//

#include "log_api.h"
#include "log_producer_config.h"
#include "log_producer_client.h"
#include "inner_log.h"

void on_log_send_done(const char * config_name,
log_producer_result result,
size_t log_bytes,
size_t compressed_bytes,
const char * req_id,
const char * message,
const unsigned char * raw_buffer,
void * userparams)
{
if (result == LOG_PRODUCER_OK)
{
printf("send success, config : %s, result : %d, log bytes : %d, compressed bytes : %d, request id : %s \n",
config_name, (result),
(int)log_bytes, (int)compressed_bytes, req_id);

}
else
{
printf("send fail, config : %s, result : %d, log bytes : %d, compressed bytes : %d, request id : %s, error message : %s\n",
config_name, (result),
(int)log_bytes, (int)compressed_bytes, req_id, message);
}

}

log_producer * create_log_producer_wrapper(on_log_producer_send_done_function on_send_done)
{
log_producer_config * config = create_log_producer_config();
// endpoint list: https://help.aliyun.com/document_detail/29008.html
log_producer_config_set_endpoint(config, "${your_endpoint}");
log_producer_config_set_project(config, "${your_project}");
log_producer_config_set_logstore(config, "${your_logstore}");
log_producer_config_set_access_id(config, "${your_access_key_id}");
log_producer_config_set_access_key(config, "${your_access_key_secret}");


// if you do not need topic or tag, comment it
log_producer_config_set_topic(config, "test_topic");
log_producer_config_add_tag(config, "tag_1", "val_1");
log_producer_config_add_tag(config, "tag_2", "val_2");
log_producer_config_add_tag(config, "tag_3", "val_3");
log_producer_config_add_tag(config, "tag_4", "val_4");
log_producer_config_add_tag(config, "tag_5", "val_5");

// set resource params
log_producer_config_set_packet_log_bytes(config, 512*1024);
log_producer_config_set_packet_log_count(config, 4096);
log_producer_config_set_packet_timeout(config, 3000);
log_producer_config_set_max_buffer_limit(config, 4*1024*1024);

// @note only 1 thread count, persistent client only support 1 thread
log_producer_config_set_send_thread_count(config, 1);

// set persistent
log_producer_config_set_persistent(config, 1);
log_producer_config_set_persistent_file_path(config, "/Users/zhangcheng/Downloads/data/log.dat");
log_producer_config_set_persistent_force_flush(config, 1);
log_producer_config_set_persistent_max_file_count(config, 10);
log_producer_config_set_persistent_max_file_size(config, 1024*1024);
log_producer_config_set_persistent_max_log_count(config, 65536);


return create_log_producer(config, on_send_done, NULL);
}


void log_producer_post_logs()
{
if (log_producer_env_init() != LOG_PRODUCER_OK) {
exit(1);
}

log_producer * producer = create_log_producer_wrapper(on_log_send_done);
if (producer == NULL)
{
printf("create log producer by config fail \n");
exit(1);
}

log_producer_client * client = get_log_producer_client(producer, NULL);
if (client == NULL)
{
printf("create log producer client by config fail \n");
exit(1);
}

//sleep(30000000);
int i = 0;
for (; i < 100000; ++i)
{
char indexStr[32];
sprintf(indexStr, "%d", i);
while (1)
{
log_producer_result rst = log_producer_client_add_log(client, 20, "content_key_1", "1abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+",
"content_key_2", "2abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+",
"content_key_3", "3abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+",
"content_key_4", "4abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+",
"content_key_5", "5abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+",
"content_key_6", "6abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+",
"content_key_7", "7abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+",
"content_key_8", "davidzhangggggggg",
"content_key_9", "中文测试",
"index", indexStr);

if (rst != LOG_PRODUCER_OK)
{
printf("add log error %d \n", rst);
usleep(100000);
continue;
}
else
{
break;
}
}


usleep(1);
}
sleep(1000);
//_exit(0);




destroy_log_producer(producer);

log_producer_env_destroy();
}

int main(int argc, char *argv[])
{
aos_log_set_level(AOS_LOG_INFO);
log_producer_post_logs();
return 0;
}

11 changes: 9 additions & 2 deletions sample/log_producer_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
#include "log_producer_config.h"
#include "log_producer_client.h"

void on_log_send_done(const char * config_name, log_producer_result result, size_t log_bytes, size_t compressed_bytes, const char * req_id, const char * message)
void on_log_send_done(const char * config_name,
log_producer_result result,
size_t log_bytes,
size_t compressed_bytes,
const char * req_id,
const char * message,
const unsigned char * raw_buffer,
void * userparams)
{
if (result == LOG_PRODUCER_OK)
{
Expand Down Expand Up @@ -51,7 +58,7 @@ log_producer * create_log_producer_wrapper(on_log_producer_send_done_function on
// set send thread count
log_producer_config_set_send_thread_count(config, 4);

return create_log_producer(config, on_send_done);
return create_log_producer(config, on_send_done, NULL);
}


Expand Down
Loading