moonquantilekit

Streaming quantile and latency summary primitives for MoonBit.

quantile
latency
summary
streaming
monitoring
moon add Gym-789/moonquantilekit@0.2.0
Download zip
Author
Version
0.2.0
License
Apache-2.0
Last updated
last month
Downloads
3
README

#MoonQuantileKit

MoonQuantileKit is a MoonBit foundation library for streaming quantile estimation and latency summary evaluation. It focuses on small, deterministic building blocks that can be embedded into benchmarks, service monitors, CLI tools, and reliability reports.

The initial implementation provides exact and bounded primitives first:

  • sorted sample summaries for P50, P90, P95, P99, and custom percentiles
  • latency bucket histograms for coarse-grained service dashboards
  • snapshot reports with min, max, count, and percentile values
  • JSON export helpers for CI logs and monitoring integrations
  • a CLI demo and regression tests

#Example

///|
let summary = SampleSummary::new("checkout").add(12).add(35).add(80)

///|
let p95 = summary.percentile(9500)

The public API uses integer milliseconds and basis-point percentiles to avoid floating-point drift in tests and CI gates.

#
BoundedSummary

pub(all) struct BoundedSummary {
name : String
config : SummaryConfig
centroids : Array[QuantileCentroid]
sample_count : Int
} derive(Eq,
Debug
)

#
BoundedSummary::add

fn BoundedSummary::add(self : BoundedSummary, value_ms : Int) -> BoundedSummary

#
BoundedSummary::capacity

fn BoundedSummary::capacity(self : BoundedSummary) -> Int

#
BoundedSummary::count

fn BoundedSummary::count(self : BoundedSummary) -> Int

#
BoundedSummary::merge

#
BoundedSummary::new

fn BoundedSummary::new(name : String, config : SummaryConfig) -> BoundedSummary

#
BoundedSummary::p95

fn BoundedSummary::p95(self : BoundedSummary) -> Int

#
BoundedSummary::percentile

fn BoundedSummary::percentile(self : BoundedSummary, percentile_bp : Int) -> Int

#
BoundedSummary::stored_centroids

fn BoundedSummary::stored_centroids(self : BoundedSummary) -> Int

#
LatencyBucket

pub(all) struct LatencyBucket {
upper_ms : Int
count : Int
} derive(Eq,
Debug
)

#
LatencyBucket::new

fn LatencyBucket::new(upper_ms : Int) -> LatencyBucket

#
LatencyBucket::to_json

fn LatencyBucket::to_json(self : LatencyBucket) -> String

#
QuantileCentroid

pub(all) struct QuantileCentroid {
mean_ms : Int
count : Int
} derive(Eq,
Debug
)

#
QuantileSnapshot

pub(all) struct QuantileSnapshot {
name : String
count : Int
min_ms : Int
max_ms : Int
p50_ms : Int
p90_ms : Int
p95_ms : Int
p99_ms : Int
} derive(Eq,
Debug
)

#
QuantileSnapshot::empty

fn QuantileSnapshot::empty(self : QuantileSnapshot) -> Bool

#
QuantileSnapshot::to_json

fn QuantileSnapshot::to_json(self : QuantileSnapshot) -> String

#
SampleSummary

pub(all) struct SampleSummary {
name : String
values : Array[Int]
} derive(Eq,
Debug
)

#
SampleSummary::add

fn SampleSummary::add(self : SampleSummary, value : Int) -> SampleSummary

#
SampleSummary::buckets

fn SampleSummary::buckets(self : SampleSummary, boundaries_ms : Array[Int]) -> Array[LatencyBucket]

#
SampleSummary::count

fn SampleSummary::count(self : SampleSummary) -> Int

#
SampleSummary::from_array

fn SampleSummary::from_array(name : String, samples : Array[Int]) -> SampleSummary

#
SampleSummary::is_empty

fn SampleSummary::is_empty(self : SampleSummary) -> Bool

#
SampleSummary::max

fn SampleSummary::max(self : SampleSummary) -> Int

#
SampleSummary::min

fn SampleSummary::min(self : SampleSummary) -> Int

#
SampleSummary::new

fn SampleSummary::new(name : String) -> SampleSummary

#
SampleSummary::p50

fn SampleSummary::p50(self : SampleSummary) -> Int

#
SampleSummary::p90

fn SampleSummary::p90(self : SampleSummary) -> Int

#
SampleSummary::p95

fn SampleSummary::p95(self : SampleSummary) -> Int

#
SampleSummary::p99

fn SampleSummary::p99(self : SampleSummary) -> Int

#
SampleSummary::percentile

fn SampleSummary::percentile(self : SampleSummary, percentile_bp : Int) -> Int

#
SampleSummary::snapshot

#
SummaryConfig

pub(all) struct SummaryConfig {
max_samples : Int
tolerated_error_bp : Int
} derive(Eq,
Debug
)

#
SummaryConfig::default

fn SummaryConfig::default() -> SummaryConfig

#
SummaryConfig::exact

#
SummaryConfig::is_exact

fn SummaryConfig::is_exact(self : SummaryConfig) -> Bool

#
SummaryConfig::new

fn SummaryConfig::new(max_samples : Int, tolerated_error_bp : Int) -> SummaryConfig

#
SummaryConfig::target_centroids

fn SummaryConfig::target_centroids(self : SummaryConfig) -> Int

#
bucketize

fn bucketize(samples : Array[Int], boundaries_ms : Array[Int]) -> Array[LatencyBucket]

#
clamp_percentile_bp

fn clamp_percentile_bp(value : Int) -> Int

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io