View Source Plausible.Ingestion.Counters.Buffer (Plausible v0.0.1)
A buffer aggregating counters for internal metrics, within 10 seconds time buckets.
See Plausible.Ingestion.Counters
for integration.
Flushing is by default possible only once the 10s bucket is complete (its window has moved). This is to avoid race conditions when clearing up the buffer on dequeue - because there is no atomic "get and delete", and items are buffered concurrently, there is a gap between get and delete in which items written may disappear otherwise.
aggregate_bucket_fn
and flush_boundary_fn
control that semantics and
are configurable only for test purposes.
Summary
Types
@type bucket_fn_opt() :: {:aggregate_bucket_fn, (NaiveDateTime.t() -> unix_timestamp())} | {:flush_boundary_fn, (DateTime.t() -> unix_timestamp())}
@type unix_timestamp() :: pos_integer()
Functions
@spec aggregate(t(), binary(), binary(), timestamp :: NaiveDateTime.t()) :: t()
@spec bucket_10s(NaiveDateTime.t()) :: unix_timestamp()
@spec flush(t(), now :: DateTime.t()) :: [Plausible.Ingestion.Counters.Record.t()]
@spec new(atom(), [bucket_fn_opt()]) :: t()
@spec previous_10s(DateTime.t()) :: unix_timestamp()