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 core Tracker: extract stats #1184

Closed
Tracked by #1181
josecelano opened this issue Jan 15, 2025 · 0 comments · Fixed by #1186
Closed
Tracked by #1181

Overhaul core Tracker: extract stats #1184

josecelano opened this issue Jan 15, 2025 · 0 comments · Fixed by #1186
Assignees
Labels
Code Cleanup / Refactoring Tidying and Making Neat

Comments

@josecelano
Copy link
Member

Parent issue: #1181

Extract the responsibility for handling stats (send events and return metrics) from the core tracker.

These two methods (get_stats and get_stats) will be called directly exposing the stats_repository and stats_event_sender.

    /// It return the `Tracker` [`statistics::metrics::Metrics`].
    ///
    /// # Context: Statistics
    pub async fn get_stats(&self) -> tokio::sync::RwLockReadGuard<'_, statistics::metrics::Metrics> {
        self.stats_repository.get_stats().await
    }

    /// It allows to send a statistic events which eventually will be used to update [`statistics::metrics::Metrics`].
    ///
    /// # Context: Statistics
    pub async fn get_stats(
        &self,
        event: statistics::event::Event,
    ) -> Option<Result<(), SendError<statistics::event::Event>>> {
        match &self.stats_event_sender {
            None => None,
            Some(stats_event_sender) => stats_event_sender.send_event(event).await,
        }
    }

See the previous similar refactor for reference.

Since I'm extracting a lot of code from the core Tracker now the app bootstrapping is becoming more complex because the tracker dependencies are built before instantiating the tracker. At some point I think I will create a IoC container to store all the references to services (Arc<...>).

cc @da2ce7

@josecelano josecelano self-assigned this Jan 15, 2025
@josecelano josecelano added the Code Cleanup / Refactoring Tidying and Making Neat label Jan 15, 2025
@josecelano josecelano mentioned this issue Jan 15, 2025
26 tasks
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 16, 2025
…o the core tracker

This is part of a big refactor. We are extracting responsabilities from
the tracker. The first step is to inject the service into the tracker
and later we will use the extracted services directly. Finally we will
removed the injected service from the tracker when it's not used anymore
via the tracker.
@josecelano josecelano linked a pull request Jan 16, 2025 that will close this issue
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 17, 2025
josecelano added a commit that referenced this issue Jan 17, 2025
2a0bc47 refactor: [#1184] remove stats functionality from core tracker (Jose Celano)
c415430 refactor: [#1184] inject stats event sender and repository into the core tracker (Jose Celano)

Pull request description:

  Overhaul core Tracker: extract stats

ACKs for top commit:
  josecelano:
    ACK 2a0bc47

Tree-SHA512: b72acb6f25d5ea642d9889fa7da3e6602c7362c1b6381af94bac848eda5b4f1a1b1fd364660fa93f703a48bc874b883db2d14ce30e4c54352f754c72132fcac3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Cleanup / Refactoring Tidying and Making Neat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant