Sign in

    moonbitstack/moonzero/window does not have a README file

    Bucket

    pub struct Bucket {
    sum : Int64
    succ : Int64
    fail : Int64
    drop : Int64
    }

    One time slice of a Window. sum counts every call that landed in the slice including the shed ones, so a slice being throttled still reads as busy rather than idle.

    Outcome

    pub(all) enum Outcome {
    Succ
    Fail
    Drop
    } derive(Eq,
    Debug
    )

    How a call recorded in a Window ended (← the success/fail/drop markers go-zero's breaker writes into its window). A Drop is a call that was shed before it ran: traffic, but neither a success nor a failure of whatever is downstream.

    Outcome::equal

    fn Outcome::equal(Outcome, Outcome) -> Bool

    Outcome::not_equal

    fn Outcome::not_equal(x : Outcome, y : Outcome) -> Bool

    Outcome::to_repr

    Window

    pub struct Window {
    size : Int
    bucket_ms : Int64
    buckets : Array[Bucket]
    offset : Int
    bucket_start : Int64
    }

    A rolling window of size buckets covering bucket_ms milliseconds each (← go-zero's collection.RollingWindow), which is how the breaker reads a backend's recent health: forty 250ms slices, so the last ten seconds and nothing older.

    Time never moves on its own — every call carries the now it happens at, as the other resilience cores here do. Writing at a later now clears the buckets the gap swept past before recording; reading at a later now skips them without clearing, so a window nobody writes to still ages out, and two reads at the same now agree.

    Window::add

    fn Window::add(self : Window, o : Outcome, now : Int64) -> Unit

    Record one call ending as o at time now.

    Window::each

    fn Window::each(self : Window, now : Int64, f : (Bucket) -> Unit) -> Unit

    Visit the buckets still inside the window at now, oldest first (← go-zero's Reduce). Stale buckets are skipped, not cleared: reading leaves the window exactly as it was.

    Window::new

    fn Window::new(size? : Int, bucket_ms? : Int64, now? : Int64) -> Window

    An empty window of size buckets of bucket_ms each, its first bucket starting at now. The defaults are go-zero's ten seconds in forty slices. A size or duration below one is raised to one, the way the other cores here clamp their bounds rather than rejecting them.

    Source Files