Skip to content

Overhaul stats: Refactor metrics (part 1) #1445

Closed

Description

@josecelano

There is a bug in the Torrust Demo with the new metrics that I can't reproduce locally.

I will introduce some changes to the metrics package to help me find the problem.

I will also make other minor changes in that package and other packages.

Subtasks

metrics package:

  • Return errors instead of panicking in the MetricCollection struct.
  • Add tracing crate.
  • Return an optional in get_counter_value and get_gauge_value. They are returning the default value for that metric type if the metric does not exist. That the behavior we want for increase_counter and set_gauge but not for these methods. They are currently used only in tests.

http-tracker-code, udp-tracker-core, udp-tracker-server packages:

  • Add logs to listeners initialization

Change this:

pub fn run_event_listener(&mut self, receiver: Receiver<Event>) {
    let stats_repository = self.repository.clone();

    tokio::spawn(async move { dispatch_events(receiver, stats_repository).await });
}

To something like this:

pub fn run_event_listener(&mut self, receiver: Receiver<Event>) {
    let stats_repository = self.repository.clone();

    // TARGET should be HTTP_TRACKER_CORE
    tracing::info!(TARGET, "Starting event listener");

    tokio::spawn(async move {
        dispatch_events(receiver, stats_repository).await;

        tracing::info!(TARGET, "Event listener finished");
    });
}

NOTE: This won't help identify a panic inside the dispatch_events function. We should log the error returned by tokio::spawn, but the function is not async. We need to move the function call from the app setup to the app start as described here.

Activity

  1. self-assigned this
    on Apr 11, 2025
  2. added theissue type on Apr 11, 2025
  3. added 2 commits that reference this issue on Apr 15, 2025
  4. linked a pull request that will close this issueOverhaul stats: Refactor metrics (part 1) #1467on Apr 15, 2025
  5. added 11 commits that reference this issue on Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Code Cleanup / Refactoring

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions