Skip to content

Overhaul stats: Extract events package (part 2) #1480

Closed

Description

@josecelano

Relates to: #1478

This is the continuation of issue #1478.

There is code in these three modules is practically equal:

  • packages/http-tracker-core/src/event
  • packages/udp-tracker-core/src/event
  • packages/udp-tracker-server/src/event

We only need to make the Sender trait and the Broadcaster generic over the Event type. The duplicated code:

pub trait Sender: Sync + Send {
    fn send_event(&self, event: Event) -> BoxFuture<'_, Option<Result<usize, SendError<Event>>>>;
}

pub struct Broadcaster {
    pub(crate) sender: broadcast::Sender<Event>,
}

Subtasks

  • Create a new workspace package events.
  • Move the code from packages/http-tracker-core/src/event and make it generic.
  • Use the new generic types in the packages:
    • http-tracker-core
    • udp-tracker-core
    • udp-tracker-server

Activity

  1. added
    - Developer -
    Code Cleanup / Refactoring
    on Apr 25, 2025
  2. self-assigned this
    on Apr 25, 2025
  3. added theissue type on Apr 25, 2025
  4. josecelano commented on Apr 25, 2025

    @josecelano
    MemberAuthor

    We should also consider adding the Receiver trait; otherwise, the senders are not coupled to the tokio broadcast implementation, but the listeners are.

    The original reason to add the Sender trait was not to decouple the implementation from the tokio broadcast channel, but to be able to mock the sender in tests. Anyway, it would be good to have both advantages:

    • Mock the Receiver
    • Decouple the receiver from the tokio broadcast implementation, so we can replace it in the future with other channel libraries.

    cc @da2ce7

  5. josecelano commented on Apr 25, 2025

    @josecelano
    MemberAuthor

    I've just realised the Sender is also coupled to tokio broadcast channels because of the error type:

    pub trait Sender: Sync + Send {
        fn send_event(&self, event: Event) -> BoxFuture<'_, Option<Result<usize, SendError<Event>>>>;
    }

    SendError is tokio::sync::broadcast::error.

    Perhaps we can simply add the trait to enable mocking when needed and leave the coupling to the broadcast channel for now. It's not an enormous debt since we only have three listeners now.

  6. added 5 commits that reference this issue on Apr 25, 2025
  7. added 5 commits that reference this issue on Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- Developer -Code Cleanup / Refactoring

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions