Package com.tnsai.quality.sampling
Class TenantPolicySamplingPolicy
java.lang.Object
com.tnsai.quality.sampling.TenantPolicySamplingPolicy
- All Implemented Interfaces:
EventSamplingPolicy
EventSamplingPolicy that dispatches each call to a per-tenant
policy based on EventContext.tenantId() (issue #82).
Mirrors TenantPolicyRedactor's
shape — every call resolves the active policy from the framework's
correlation context. A multi-tenant agent group can therefore apply
different sampling rates per tenant without the publisher needing
to know tenant boundaries:
EventSamplingPolicy dispatcher = TenantPolicySamplingPolicy.builder()
.tenant("acme", SamplingPolicies.verbose()) // power user — keep everything
.tenant("globex", new ErrorAlwaysPolicy(0.001)) // chatty — aggressive sampling
.defaultPolicy(SamplingPolicies.production()) // everyone else
.build();
AgentEventPublisher publisher = new SamplingAgentEventPublisher(slf4j, dispatcher);
Resolution order:
EventContext.tenantId()— explicit tenant from the framework's correlation context- Configured default policy — fallback for unmatched / null / blank tenant ids
Composition: per-tenant values are themselves EventSamplingPolicys, so operators can compose nested dispatch —
e.g. wrap each per-tenant policy in something tail-based later
without changing the dispatcher.
Thread-safety: registry is immutable after construction;
dispatch is a single Map.get on each call. Per-tenant
policies must themselves be thread-safe (the SPI requires it).
- Since:
- 0.9.0 (issue #82)
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionTenantPolicySamplingPolicy(Map<String, EventSamplingPolicy> byTenant, EventSamplingPolicy defaultPolicy) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()resolve(com.tnsai.observability.events.EventContext ctx) Returns theEventSamplingPolicychosen forctx.sample(SamplingInput input) Inspect an event's metadata and return whether to capture, drop, or capture-with-downsampling marker.Snapshot of the registry for inspection / testing.
-
Constructor Details
-
TenantPolicySamplingPolicy
public TenantPolicySamplingPolicy(Map<String, EventSamplingPolicy> byTenant, EventSamplingPolicy defaultPolicy) - Parameters:
byTenant- immutable mapping of tenant id → policy; empty map makes every call fall through todefaultPolicydefaultPolicy- fallback when no tenant id is resolvable, or no override is registered- Throws:
NullPointerException- if either arg is null
-
-
Method Details
-
builder
-
sample
Description copied from interface:EventSamplingPolicyInspect an event's metadata and return whether to capture, drop, or capture-with-downsampling marker.- Specified by:
samplein interfaceEventSamplingPolicy
-
resolve
Returns theEventSamplingPolicychosen forctx. Public for test inspection; the dispatch path uses it on every sample call. -
tenantOverrides
Snapshot of the registry for inspection / testing. -
defaultPolicy
-