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

Overhaul stats: decouple events from stats #1395

Closed
josecelano opened this issue Mar 19, 2025 · 0 comments · Fixed by #1400
Closed

Overhaul stats: decouple events from stats #1395

josecelano opened this issue Mar 19, 2025 · 0 comments · Fixed by #1400
Assignees
Labels
- Developer - Torrust Improvement Experience

Comments

@josecelano
Copy link
Member

To implement the segregated metrics for each server we need to create one event listeners and metrics repository for each service. That means the stats setup function will not work anymore. For example, the stats setup function for the HTTP core is

pub fn factory(
    tracker_usage_statistics: bool,
) -> (
    Option<Box<dyn statistics::event::sender::Sender>>,
    statistics::repository::Repository,
) {
    let mut stats_event_sender: Option<Box<dyn statistics::event::sender::Sender>> = None;

    let mut keeper = statistics::keeper::Keeper::new();

    if tracker_usage_statistics {
        let (sender, _) = broadcast::channel(CHANNEL_CAPACITY);

        let receiver = sender.subscribe();

        stats_event_sender = Some(Box::new(ChannelSender { sender }));

        keeper.run_event_listener(receiver);
    }

    (stats_event_sender, keeper.repository)
}

It creates the channel and subscriber one event listener. we need to separate the channel creation from the listeners subscriptions. My plan is to:

  • Move the event enums, sender trait and channel creation to a new "pure" events module.
  • Leave the listener subscription in the statistics module.

The new events are "generic" events that can be used for any purpose, not only generating stats.

This will allow later to create one listener and repo per server (socket address).

In this issue, I'm going to only split the modules internally, the statistics::setup::factory(...) function signature will be the same. We can removed it when we introduce the new listeners.

@josecelano josecelano added the - Developer - Torrust Improvement Experience label Mar 19, 2025
@josecelano josecelano self-assigned this Mar 19, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Mar 19, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Mar 19, 2025
Events are now generic even if they are only used for stats for now.
@josecelano josecelano linked a pull request Mar 19, 2025 that will close this issue
josecelano added a commit that referenced this issue Mar 19, 2025
9eba80f refactor: [#1395] rename send_stats_event to send_event (Jose Celano)
055db4e docs: [#1395] minor changes in comments (Jose Celano)
d8f1696 refactor: [#1398] extract event module in UDP server (Jose Celano)
ed93836 refactor: [#1397] extract event module in UDP core (Jose Celano)
7e364d1 refactor: [#1396] move event channel creation to events mod in HTTP tracker core (Jose Celano)
3d2243b refactor: [#1396] extract event module in HTTP core (Jose Celano)

Pull request description:

  The new events are "generic" events that can be used for any purpose, not only generating stats. This will allow later to create one listener and metrics repository per server (socket address). See #1395.

ACKs for top commit:
  josecelano:
    ACK 9eba80f

Tree-SHA512: a88a6eeea28d08f3537704452056c086494a906da375de19fe4671ca7e74f6e00168543e4d4bdd9924da19b22b83aa307f6ff337a9fe6b33b1f3cd9c7e918bb6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Developer - Torrust Improvement Experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant