API reference
The public declarations of @chrismichaelps/pudu-lang-resilience 0.1.0.
PuduLangResilience
One sentence saying what went wrong.
Failuretype@Resilience.Root.Failure — why a guarded execution produced no value
Whether the failure is a cancellation.
Whether the failure is a rejection by a strategy rather than the callback's own error.
The outcome of a callback that answers a plain
Result.Outcometype@Resilience.Root.Outcome — the value or failure of one execution
An outcome holding the callback's own error.
The callback's own error, when the failure is one.
An outcome holding a value.
One line naming an outcome, for telemetry.
PuduLangResilience.Chaos
Enabled, injecting into every execution.
The arguments chaos generators receive for one execution.
Argumentstype@Resilience.Chaos.Arguments — what a chaos generator decides from
Enabled, injecting into the given share of executions, from 0 to 1.
Enabled, injecting into one execution in a thousand.
Injectiontype@Resilience.Chaos.Injection — how often, and whether, chaos is injected
Whether to inject into the execution holding
context: never while disabled, otherwise withthe probability the rate names. A generated rate outside 0 to 1 is taken as the nearer bound.
Every reason the injection settings cannot be followed.
PuduLangResilience.Chaos.Behavior
The default injection with no behavior chosen yet.
Runs
behaviorat the given injection settings.Optionstype@Chaos.Behavior.Options — what to run and how often
strategy: PuduLangResilience.Chaos.Behavior.Options[E] -> PuduLangResilience.Strategy.Strategy[T, E]fnA behavior injection strategy following the options. A behavior that fails answers its
failure without running the callback.
Every reason the options cannot be followed.
PuduLangResilience.Chaos.Fault
The default injection with no failure chosen yet.
Injectedtype@Chaos.Fault.Injected — the failure injected into one execution
Injects
failureat the given injection settings.Optionstype@Chaos.Fault.Options — which failure to inject and how often
A fault injection strategy following the options. The generator is used when given; a
generator answering nothing injects nothing.
Every reason the options cannot be followed.
PuduLangResilience.Chaos.Latency
Thirty seconds at the default injection.
Injectedtype@Chaos.Latency.Injected — the delay injected into one execution
Injects
millisof delay at the given injection settings.Optionstype@Chaos.Latency.Options — how long to delay and how often
A latency injection strategy following the options. A delay of zero or less injects
nothing; a token firing during the delay answers
Cancelledwithout running the callback.Every reason the options cannot be followed.
PuduLangResilience.Chaos.Outcome
The default injection with no outcome chosen yet.
Injectedtype@Chaos.Outcome.Injected — the outcome injected into one execution
Injects
outcomeat the given injection settings.Optionstype@Chaos.Outcome.Options — which outcome to inject and how often
An outcome injection strategy following the options. The generator is used when given; a
generator answering nothing injects nothing.
Every reason the options cannot be followed.
PuduLangResilience.Chaos.Weighted
A generator answering each value with a chance in proportion to its weight. Weights below
one are never chosen; with no positive weight it answers nothing.
PuduLangResilience.CircuitBreaker
BreakArgumentstype@Resilience.CircuitBreaker.BreakArguments — the health a break duration is chosen from
CircuitStatetype@Resilience.CircuitBreaker.CircuitState — which executions a circuit admits
Closes every circuit the control holds.
Closingtype@Resilience.CircuitBreaker.Closing — what closed a circuit
Opens at a tenth of at least 100 executions failing within 30 seconds, for 5 seconds.
Whether the control last isolated its circuits.
Isolates every circuit the control holds, and every circuit attached to it later, until closed.
The last outcome the provider's circuit handled, while the circuit is not closed.
A manual control holding no circuit, not isolated.
ManualControltype@Resilience.CircuitBreaker.ManualControl — isolates and closes circuits by hand
Openingtype@Resilience.CircuitBreaker.Opening — why and for how long a circuit opened
Optionstype@Resilience.CircuitBreaker.Options — when a circuit opens and for how long
The state of the provider's circuit, or
Nonebefore it is attached.A state provider attached to no circuit.
StateProvidertype@Resilience.CircuitBreaker.StateProvider — reads the state of one circuit
A circuit breaker strategy following the options. Every pipeline holding the same strategy
shares its one circuit.
Every reason the options cannot be followed, not counting an attached state provider.
PuduLangResilience.Clock
Moves a manual clock forward by
millis; a negative amount moves it by nothing.Clocktype@Resilience.Clock.Clock — reads time and waits in milliseconds
A manual clock reading
startmilliseconds until it is advanced.Manualtype@Resilience.Clock.Manual — time that moves only when told
The clock's reading, in milliseconds.
A clock driven by a manual clock. Waiting records the requested wait and advances the manual
clock by it at once; it answers the token's reason when the token has fired.
Waits
millison the clock, or until the token fires; the token's reason when it fired.Every wait requested of a manual clock, oldest first.
The monotonic clock of the running program. Waiting ends early when the token fires.
PuduLangResilience.Constants.Events
Reported after each attempt a retry or hedging strategy makes.
ON_BEHAVIOR: StrconstReported when a behavior is injected.
Reported when a circuit closes.
Reported when a circuit admits its half-open probe.
Reported when a circuit opens.
ON_FALLBACK: StrconstReported before a fallback strategy produces its substitute.
ON_FAULT: StrconstReported when a fault is injected.
ON_HEDGING: StrconstReported before a hedging strategy starts a hedged attempt.
ON_LATENCY: StrconstReported when latency is injected.
ON_OUTCOME: StrconstReported when an outcome is injected.
Reported when a rate limiter strategy rejects an execution.
ON_RETRY: StrconstReported before a retry strategy waits for its next attempt.
ON_TIMEOUT: StrconstReported when a timeout strategy cancels an execution.
Reported when a pipeline finishes an execution.
Reported when a pipeline starts an execution.
PuduLangResilience.Constants.Messages
BROKEN_CIRCUIT: StrconstAn open circuit;
<1>is the wait in milliseconds before it may be tried again.CANCELLED: StrconstA cancellation;
<1>is its reason.CRASHED: StrconstA callback that stopped its thread;
<1>is what it said.An isolated circuit.
A pipeline refused at build time;
<1>is its problems.What separates problems listed in one sentence.
RAISED: StrconstA failure raised by the callback;
<1>is the error.RATE_LIMITED: StrconstA rate limiter rejection without a known wait.
A rate limiter rejection with a known wait;
<1>is the wait in milliseconds.A registry key whose pipeline is refused;
<1>is the key and<2>its problems.A registry key without a builder;
<1>is the key.SUCCEEDED: StrconstAn outcome holding a value;
<1>is the value.TIMED_OUT: StrconstA timeout;
<1>is the timeout in milliseconds.
PuduLangResilience.Context
Copies every property of
sourceintotarget, replacing properties of the same name.A key holding a truth value.
Asks the execution holding this context to stop. The first reason given is kept.
A fresh context whose execution stops when
tokenfires.Okwhile the token has not fired, andCancelledonce it has, so a callback stops with?.Contexttype@Resilience.Context.Context — what one execution carries through a pipeline
A context with no operation key, a token that fires only when cancelled, and no properties.
A copy of the context observing another token, with a separate copy of its properties.
The property under a key, when it is present and reads back as the key's type.
The property under a key, or
fallbackwhen it is absent or unreadable.Whether a property is stored under the key's name.
A key holding a whole number.
A key whose values are written with
encodeand read back withdecode.Keytype@Resilience.Context.Key — a typed name for one property
A fresh context naming the operation it runs.
The names of every stored property, in order.
Sleeps
millison the system clock, or answersCancelledas soon as the token fires.Removes the property under a key.
Stores a property, replacing any value under the same name.
Whether the context's token has fired.
A key holding text.
The same context observing another token; properties stay shared with the original.
PuduLangResilience.Domain.Algorithms
Buckettype@Domain.Algorithms.Bucket — tokens left and when they were last topped up
Permits held while an execution runs and handed back when it ends.
At most
limitpermits in each window ofwindowmilliseconds, the window moving by itselfwhen
automaticand otherwise only when replenished by hand.Segmentstype@Domain.Algorithms.Segments — permits used per segment, oldest first
Segment counts after
stepssegments have passed: the oldest drop out and empty ones join.At most
limitpermits in anywindowmilliseconds, counted insegmentsequal segments;the segments move by themselves when
automaticand otherwise only when replenished by hand.A bucket of at most
limittokens gainingperPeriodtokens everyperiodmilliseconds,by itself when
automaticand otherwise only when replenished by hand.Windowtype@Domain.Algorithms.Window — permits used since the window began
PuduLangResilience.Domain.Backoff
The delay before retry
attempt, counting from 0, and the jitter state for the next one.statestarts at 0.0 for a run of retries;drawis a uniform number from 0 up to 1.Plantype@Domain.Backoff.Plan — the inputs every delay is computed from
Shapetype@Domain.Backoff.Shape — how the delay grows with each retry
The delay before retry
attemptwithout jitter.
PuduLangResilience.Domain.Circuit
Admissiontype@Domain.Circuit.Admission — the answer to one execution asking to run
Whether an execution may run at
now. An open circuit past its deadline turns half-open andadmits this one execution as its probe, pushing the deadline
breakDurationfurther; everyother execution waits for the probe's outcome.
The circuit closed, with its counts and half-open attempts cleared.
A closed circuit counting over a sampling period of
samplingmilliseconds.The circuit after a handled outcome at
now, and whether it must now open: always fromhalf-open, and from closed once the thresholds are met. The failure is counted except while
half-open.
The circuit held open until closed by hand.
Machinetype@Domain.Circuit.Machine — the circuit's phase, deadline, and counts
The circuit opened at
nowfordurationmilliseconds.Phasetype@Domain.Circuit.Phase — which executions the circuit admits
Milliseconds until the circuit may admit a probe, never below zero.
The circuit after an unhandled outcome at
now, and whether it closed. A half-open circuitcloses; the outcome is counted in every phase.
Thresholdstype@Domain.Circuit.Thresholds — when a closed circuit opens
PuduLangResilience.Domain.Health
Empty counts over a sampling period of
samplingmilliseconds.The share of failures in the totals, to six places; zero without throughput.
Healthtype@Domain.Health.Health — the windows covering one sampling period
The totals of the windows still inside the sampling period at
now.Infotype@Domain.Health.Info — totals over the sampling period
The counts with one more outcome recorded at
now.The counts emptied.
Whether the totals reach the minimum throughput and a failure share of at least
ratio.Windowtype@Domain.Health.Window — the counts of one slice of the sampling period
PuduLangResilience.Domain.Permits
Algorithmtype@Domain.Permits.Algorithm — how one kind of limiter counts permits
The permits available at
now.Booktype@Domain.Permits.Book — a limiter's counts and queue
Decisiontype@Domain.Permits.Decision — the answer to a new request
The book with
permitshanded back.A book with no waiters over the algorithm state
held.Ordertype@Domain.Permits.Order — which waiter is served first
The book at
nowafter the waiter holdingticketasks again. It takes its permits when itis next in order and they are available.
The permits all waiters are asking for.
The book after one replenishment by hand, and whether the algorithm allows it.
The book at
nowafter a request forpermits. The request is granted when the permits areavailable and no waiter comes first; otherwise it joins the queue when
mayQueueand thequeue has room, evicting the oldest waiters when newest requests are served first; otherwise
it is denied. A request for more than the permit limit is always denied, and a request for no
permits is granted while any permit is available.
Turntype@Domain.Permits.Turn — the answer to a waiter asking again
Waitertype@Domain.Permits.Waiter — one queued request
The book without the waiter holding
ticket, counted as failed.
PuduLangResilience.Fallback
Handles every failure except a cancellation; the action must still be given.
Optionstype@Resilience.Fallback.Options — what to handle and what to answer instead
A fallback strategy following the options.
Every reason the options cannot be followed.
Answers
valuein place of every failure except a cancellation.
PuduLangResilience.Hedging
Actiontype@Resilience.Hedging.Action — what a hedged attempt is generated from
One hedged attempt, started after two seconds, for every failure except a cancellation.
DelayArgumentstype@Resilience.Hedging.DelayArguments — the attempt a hedging delay is chosen for
@Resilience.Hedging.Hedged — the hedged attempt about to start
Optionstype@Resilience.Hedging.Options — how many attempts to race and when to start them
A hedging strategy following the options.
Every reason the options cannot be followed.
A delay that starts the next hedged attempt only once an earlier attempt's outcome is handled.
PuduLangResilience.Hedging.Attempts
Attempttype@Hedging.Attempts.Attempt — one running execution of a hedged callback
FOREVER: IntconstA wait that ends only when an attempt finishes.
Starts
callbackon a thread of its own withcontext. When it finishes, its outcome isstored and
indexis sent tofinished; a callback that stops its thread finishes asCrashed, and one that cannot be started finishes at once asCrashed.The index of the next attempt to finish, or
Nonewhenwaitmilliseconds pass on the clockfirst. A
waitofFOREVERwaits for as long as it takes.The outcome of a finished attempt.
Asks every attempt to stop and waits until each thread has ended.
PuduLangResilience.Limiter
Requests
permits, waiting in the limiter's queue while it has room; the lease isAbandonedwhen the token fires first.Requests
permitswithout waiting.A limiter granting a request only when every limiter in order grants it. A refusal releases
the leases already taken and answers that refusal.
Granttype@Resilience.Limiter.Grant — whether a request was given its permits
@Resilience.Limiter.Grant — whether a request was given its permits
A lease granted with
handBackrun on its first release only.Whether the lease holds its permits.
Leasetype@Resilience.Limiter.Lease — the answer to one request and how to hand its permits back
Limitertype@Resilience.Limiter.Limiter — leases permits, waiting or at once
QueueOrdertype@Resilience.Limiter.QueueOrder — which queued request is served first
A lease that holds nothing and releases nothing.
Hands a lease's permits back. Releasing twice hands them back once.
Adds one period's permits to a limiter replenished by hand; whether it did.
The limiter's counts now.
Statisticstype@Resilience.Limiter.Statistics — a limiter's counts at one moment
PuduLangResilience.Limiter.Concurrency
A concurrency limiter following the options, or every reason it cannot be made.
A thousand permits, no queue, oldest first, on the system clock.
Optionstype@Limiter.Concurrency.Options — permits held at once and the queue behind them
Every reason the options cannot be followed.
PuduLangResilience.Limiter.Engine
A limiter over
algorithm, starting fromheld, reading time fromclock.Queueingtype@Limiter.Engine.Queueing — the limits every engine enforces
PuduLangResilience.Limiter.FixedWindow
A fixed window limiter whose first window starts now, or every reason it cannot be made.
A hundred permits a second, moving by itself, with no queue.
Optionstype@Limiter.FixedWindow.Options — permits per window and the queue behind them
Every reason the options cannot be followed.
PuduLangResilience.Limiter.Partitioned
Requests
permitsfrom the partition of the context, waiting as that limiter allows.Requests
permitsfrom the partition of the context without waiting.A partitioned limiter choosing each execution's partition with
partitionOf.The keys of every partition used so far, in order.
Partitiontype@Limiter.Partitioned.Partition — the key of a partition and how to make its limiter
Partitionedtype@Limiter.Partitioned.Partitioned — limiters made on first use, one per key
The counts of a partition's limiter, once it has been used.
PuduLangResilience.Limiter.SlidingWindow
A sliding window limiter whose first segment starts now, or every reason it cannot be made.
A hundred permits in any second, counted in ten segments, with no queue.
Optionstype@Limiter.SlidingWindow.Options — permits per window, its segments, and the queue
Every reason the options cannot be followed.
PuduLangResilience.Limiter.TokenBucket
A token bucket limiter starting full, or every reason it cannot be made.
A full bucket of ten tokens gaining ten every second by itself, with no queue.
Optionstype@Limiter.TokenBucket.Options — the bucket's size, refill, and queue
Every reason the options cannot be followed.
PuduLangResilience.Pipeline
The pipeline as one strategy of another. It keeps its own clock and telemetry.
A pipeline of
strategieswith the default options. The first strategy is the outermost.A pipeline of
strategieswith the given options, or every problem found in the options ofits strategies and every strategy name used twice.
No name, the system clock and randomizer, and no listeners.
The name, instance, and strategies of a pipeline, outermost first.
Describedtype@Resilience.Pipeline.Described — one strategy of a built pipeline
Descriptortype@Resilience.Pipeline.Descriptor — what a built pipeline is made of
A pipeline with no strategies: it runs every callback once, as given.
Runs a callback through the pipeline with a fresh context.
Runs a callback through the pipeline with the given context, reporting the execution's start
and, with its duration and outcome, its end.
One line per problem.
Invalidtype@Resilience.Pipeline.Invalid — every reason a pipeline could not be built
Invalid: Str -> PuduLangResilience.Pipeline.Invalid -> PuduLangResilience.Registry.RegistryErrortype@Resilience.Pipeline.Invalid — every reason a pipeline could not be built
Optionstype@Resilience.Pipeline.Options — identity, effects, and telemetry of a pipeline
Pipelinetype@Resilience.Pipeline.Pipeline — strategies composed outermost first
Runs a callback that answers a plain
Resultthrough the pipeline with a fresh context; itserror becomes
Raised.runwith the given context.
PuduLangResilience.Predicate
Outcomes that any of
testshandles; none whentestsis empty.Every error the callback raises itself.
The arguments for judging one outcome.
attemptcounts from 0 for the first execution.Argumentstype@Resilience.Predicate.Arguments — the outcome being judged and where it arose
Rejections by an open or isolated circuit.
The failures, of any kind, that
testaccepts.Every failure except a cancellation; no value. The default of every reactive strategy.
Whether
testhandles the outcome.Handles nothing.
Predicatetype@Resilience.Predicate.Predicate — answers whether a strategy handles an outcome
The callback's own errors that
testaccepts.Rejections by a rate limiter.
The values equal to
expected.The values that
testaccepts.Rejections by a timeout strategy.
PuduLangResilience.Randomizer
A whole number from zero up to, but not including,
bound; zero for a bound below one.Whether a draw falls below
rate, a ratio from 0 to 1. A rate of 1 always holds and a rateof 0 never does.
A randomizer whose every draw is
ratioof the bound, rounded down.ratiois clamped tothe range from 0 up to just below 1.
A fraction of one in parts of
SCALE, from zero up to but not includingSCALE.Randomizertype@Resilience.Randomizer.Randomizer — answers a whole number below a bound
SCALE: IntconstThe number of parts one unit is divided into by
fraction.A randomizer that draws the same sequence for the same seed.
A randomizer seeded from the clock, safe to share between threads.
A float from zero up to but not including one.
PuduLangResilience.RateLimiter
One permit per execution from a concurrency limiter of
permitLimitpermits and a queue ofqueueLimit.One permit per execution from a concurrency limiter of a thousand permits and no queue.
Optionstype@Resilience.RateLimiter.Options — where permits come from and who hears of rejections
One permit per execution from the limiter of its partition.
@Resilience.RateLimiter.Rejected — the execution a limiter turned away
A rate limiter strategy following the options. Every pipeline holding the same strategy
shares its default limiter.
One permit per execution from
limiter, waiting as it allows.
PuduLangResilience.Registry
Buildertype@Resilience.Registry.Builder — the strategies of the pipeline for one key
BuilderContexttype@Resilience.Registry.BuilderContext — the key a pipeline is being built for
An empty registry with the default options.
An empty registry with the given options.
The default pipeline settings, each key as its builder name, and no instance name.
One sentence saying why a pipeline could not be answered.
The pipeline for a key, built from its builder on first use and shared afterwards.
The pipeline for a key, registering
builderfirst when the key has none.Every key with a builder, in order.
Optionstype@Resilience.Registry.Options — shared pipeline settings and how keys become names
Registrytype@Resilience.Registry.Registry — builders and the pipelines built from them
RegistryErrortype@Resilience.Registry.RegistryError — why a pipeline could not be answered
A new pipeline for a key, built again from its builder; later
getcalls answer it. Statesuch as an open circuit starts afresh in the new pipeline.
Registers the builder for a key;
false, changing nothing, when the key already has one.The pipeline for a key, or
Nonewhen the key has no builder or its pipeline is invalid.
PuduLangResilience.Retry
Backofftype@Resilience.Retry.Backoff — how the delay grows with each retry
Three retries of every failure except a cancellation, two seconds apart, without jitter.
Optionstype@Resilience.Retry.Options — when to retry and how long to wait
@Resilience.Retry.Retrying — the attempt that failed and the wait before the next
A retry strategy following the options.
UNLIMITED: IntconstA retry count that never runs out.
Every reason the options cannot be followed.
PuduLangResilience.Strategy
Callbacktype@Resilience.Strategy.Callback — the work a layer guards
A strategy of the given kind that runs
executearound every callback.nameidentifies itin telemetry and must be unique within one pipeline.
Keeps nothing of the runtime; the
attachof a strategy that holds no state between calls.Executetype@Resilience.Strategy.Execute — runs a callback under one layer's policy
Runtimetype@Resilience.Strategy.Runtime — the effects a pipeline lends its layers
A runtime on the system clock and randomizer that reports nothing.
Strategytype@Resilience.Strategy.Strategy — a named, validated policy layer
PuduLangResilience.Telemetry
Detailtype@Resilience.Telemetry.Detail — what each kind of event measured
Eventtype@Resilience.Telemetry.Event — one reported occurrence
The same reporter naming another strategy as the source.
Listenertype@Resilience.Telemetry.Listener — receives every reported event
The rank of a severity, from 0 for
Silentto 5 forCritical.Reports one event from the reporter's source about the execution holding
context.A reporter for
sourcethat gives each event the severityseverityOfanswers, when given,and hands every event not
Silentto each listener in order.Reportertype@Resilience.Telemetry.Reporter — where one strategy's events go
Severitytype@Resilience.Telemetry.Severity — how much an event matters
The severity's name.
A reporter that drops every event.
Sourcetype@Resilience.Telemetry.Source — the pipeline and strategy reporting
The source as one dotted name, leaving out the parts it lacks.
PuduLangResilience.Telemetry.Log
One line naming an event's severity, name, source, operation, detail, and outcome.
A listener writing every event of at least the
leastseverity as one line.
PuduLangResilience.Telemetry.Meter
How many events of the given name were counted, over every series.
A meter naming each series by event name and source.
Every duration recorded for events of the given name, in the order they were reported.
A meter that also names each series by the tags
enrichanswers for its event.listener: &PuduLangResilience.Telemetry.Meter.Meter -> fn(PuduLangResilience.Telemetry.Event) -> ()fnA listener counting every event into the meter, and recording the duration of every attempt
and every finished execution.
Metertype@Telemetry.Meter.Meter — event counts and durations by series
Every series and its count, in order.
PuduLangResilience.Timeout
PuduLangResilience.Utils.Numeric
left + right, orLARGESTwhen the sum would exceed it. Both are at least zero.LARGEST: IntconstThe largest count or duration the package represents.
left * right, orLARGESTwhen the product would exceed it. Both are at least zero.The count of parts per
wholethatrationames, rounded down.ratiois between 0 and 1.The float nearest to an integer.
The whole part of a float, clamped to zero below and to
LARGESTabove;LARGESTfor avalue that is not finite.
PuduLangResilience.Utils.Template
The template with each
<n>replaced by thenth value, counting from 1, in one pass: texttaken from a value is never filled again. A slot without a value is kept as written.
