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

Incorrect Usage of Global Config in Metric Log Initialization #139

Open
flearc opened this issue Mar 18, 2024 · 1 comment
Open

Incorrect Usage of Global Config in Metric Log Initialization #139

flearc opened this issue Mar 18, 2024 · 1 comment

Comments

@flearc
Copy link
Contributor

flearc commented Mar 18, 2024

The global config in the sentinel-core module is defined as a thread-local variable:

thread_local! {
    static GLOBAL_CONFIG : RefCell<ConfigEntity> = RefCell::new(ConfigEntity::new());
}

However, during the initialization of metric logs in the init_core_components function, a new thread is spawned to perform the task, which will use the default value of the global config:

// `init_core_components` init core components with global config
#[inline]
fn init_core_components() -> Result<()> {
    if config::metric_log_flush_interval_sec() > 0 {
        #[cfg(feature = "metric_log")]
        metric::init_task();
    }
    ...
}
pub fn init_task() {
    INIT_ONCE.call_once(|| {
        std::thread::spawn(|| loop {
            do_aggregate();
            sleep_for_ms((config::metric_log_flush_interval_sec() * 1000).into());
        });
    });
}

Functions like remove_deprecated_files and roll_file_size_exceeded in the metric log writer module will not behave as expected when users define a custom config.

@Forsworns
Copy link
Member

I think a lazy_static variable may be more suitable for the configuration items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants