-
Notifications
You must be signed in to change notification settings - Fork 1.8k
log: Update log related metrics with a certian interval #11084
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -463,6 +463,70 @@ static inline const char *flb_log_message_type_str(int type) | |
| } | ||
| } | ||
|
|
||
| #ifdef WIN32 | ||
| static uint64_t monotonic_now_ns(void) | ||
| { | ||
| static LARGE_INTEGER s_freq = {0}; | ||
| LARGE_INTEGER cnt, freq; | ||
| uint64_t q = 0; | ||
| uint64_t f = 0; | ||
| uint64_t rem = 0; | ||
| uint64_t sec = 0; | ||
|
|
||
| if (s_freq.QuadPart == 0) { | ||
| QueryPerformanceFrequency(&s_freq); | ||
| } | ||
| freq = s_freq; | ||
| QueryPerformanceCounter(&cnt); | ||
|
|
||
| /* integer math: ns = cnt * 1e9 / freq */ | ||
| /* avoid 128-bit: split to microseconds first if you prefer */ | ||
| q = (uint64_t)cnt.QuadPart; | ||
| f = (uint64_t)freq.QuadPart; | ||
| /* Use MulDiv-like scaling to reduce precision loss */ | ||
| /* Use 128-bit intermediate or chunk the calculation to avoid overflow */ | ||
| sec = q / f; | ||
| rem = q % f; | ||
| return (sec * 1000000000ULL) + ((rem * 1000000000ULL) / f); | ||
| } | ||
|
|
||
| #else | ||
| static uint64_t monotonic_now_ns(void) | ||
| { | ||
| struct timespec ts; | ||
| clock_gettime(CLOCK_MONOTONIC, &ts); | ||
| return (uint64_t)ts.tv_sec * 1000000000ULL + ts.tv_nsec; | ||
| } | ||
| #endif | ||
|
|
||
| static void flb_log_metrics_heartbeat(struct flb_log *log, uint64_t wall_now_ns) | ||
| { | ||
| uint64_t now_mono = 0; | ||
| int log_message_type; | ||
| char *message_type_str; | ||
|
|
||
| if (!log || !log->metrics || !log->metrics->logs_total_counter) { | ||
| return; | ||
| } | ||
|
|
||
| now_mono = monotonic_now_ns(); | ||
| if (now_mono < log->next_hb_ns) { | ||
| return; | ||
| } | ||
|
|
||
| for (log_message_type = FLB_LOG_ERROR; log_message_type <= FLB_LOG_TRACE; log_message_type++) { | ||
| message_type_str = flb_log_message_type_str(log_message_type); | ||
| if (!message_type_str) { | ||
| break; | ||
| } | ||
| cmt_counter_add(log->metrics->logs_total_counter, | ||
| wall_now_ns, | ||
| 0, 1, (char*[]){message_type_str}); | ||
| } | ||
|
|
||
| log->next_hb_ns = now_mono + log->hb_interval_ns; | ||
| } | ||
cosmo0920 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| int flb_log_set_file(struct flb_config *config, char *out) | ||
| { | ||
| struct flb_log *log = config->log; | ||
|
|
@@ -577,6 +641,8 @@ struct flb_log *flb_log_create(struct flb_config *config, int type, | |
| log->out = out; | ||
| log->evl = evl; | ||
| log->tid = 0; | ||
| log->hb_interval_ns = 60ULL * 1000000000ULL; | ||
| log->next_hb_ns = 0; | ||
|
Comment on lines
+644
to
+645
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded heartbeat interval should be configurable. The heartbeat interval is hardcoded to 60 seconds (line 641), but the PR test configuration uses Consider:
Initial heartbeat fires immediately. Setting 🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a draft proposal so we wouldn't be needed to make configurable for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cosmo0920, understood! Since this is a draft proposal, keeping the hardcoded 60-second interval is perfectly reasonable for now. You can make it configurable later if needed once the approach is validated. Thanks for clarifying! 👍 |
||
|
|
||
| ret = flb_pipe_create(log->ch_mng); | ||
| if (ret == -1) { | ||
|
|
@@ -826,6 +892,7 @@ void flb_log_print(int type, const char *file, int line, const char *fmt, ...) | |
| } | ||
|
|
||
| ts = cfl_time_now(); | ||
| flb_log_metrics_heartbeat(config->log, ts); | ||
| ret = cmt_counter_inc(config->log->metrics->logs_total_counter, | ||
| ts, | ||
| 1, (char *[]) {msg_type_str}); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.