Class GrpcChaosRegistry
GrpcToHttpRequestHandler Netty
handler to probabilistically return gRPC error statuses (UNAVAILABLE,
DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED, INTERNAL, etc.) on matched gRPC
method calls.
The design mirrors TcpChaosRegistry — a singleton backed by a
ConcurrentHashMap, with optional TTL-based auto-expiry, service name
normalisation (lower-cased, trimmed), and lazy eviction on lookup.
An empty-string key ("") serves as a default profile that applies
to all services unless overridden by a service-specific registration,
following the same pattern as GrpcHealthRegistry.
State is cleared on server reset (see HttpState.reset()).
Fleet-awareness (G11): when a clustered StateBackend is
wired via setStateBackend(StateBackend), mutations are replicated
via the backend's crudEntities("chaos-grpc") store, and an
InvalidationListener rebuilds the node-local map on remote writes.
The get(String) path remains purely node-local. When no backend is
set or the backend is not clustered, behaviour is identical to the pre-G11
node-local-only registry.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe gRPC chaos fault types reported byactiveCountByFaultType(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of non-expired entries.For each fault type, the number of currently-active (non-expired) registrations whose profile includes that fault.entries()Returns a snapshot copy of the current, non-expired service to profile mappings.Returns the gRPC chaos profile for the given service, falling back to the default ("") profile if no service-specific one exists.static GrpcChaosRegistryintincrementMatchCount(String service) Atomically increments and returns the per-service match counter.patch(String service, GrpcChaosProfile partial) Applies JSON Merge Patch semantics to the gRPC chaos profile for the given service.voidput(String service, GrpcChaosProfile profile) Register (or replace) the gRPC chaos profile for the given service with no expiry.voidput(String service, GrpcChaosProfile profile, long ttlMillis) Register (or replace) the gRPC chaos profile for the given service, optionally with a time-to-live after which it auto-expires.voidRebuilds the node-local map from the backend store.voidRemoves the gRPC chaos profile for the given service (no-op if absent).voidreset()Clear all gRPC chaos profiles and match counters.voidsetStateBackend(StateBackend backend) Wires the clustered state backend for fleet-wide chaos replication.Returns, for each currently-active registration that carries a TTL, the remaining milliseconds until it auto-reverts.
-
Field Details
-
FAULT_TYPES
The gRPC chaos fault types reported byactiveCountByFaultType().
-
-
Constructor Details
-
GrpcChaosRegistry
-
-
Method Details
-
getInstance
-
setStateBackend
Wires the clustered state backend for fleet-wide chaos replication. When the backendisClustered(), mutations are replicated via the backend's CRUD entity store, and anInvalidationListeneris registered to rebuild the node-local map on remote writes. When the backend is not clustered, this method is a no-op — the registry stays purely node-local. -
put
Register (or replace) the gRPC chaos profile for the given service with no expiry. -
put
Register (or replace) the gRPC chaos profile for the given service, optionally with a time-to-live after which it auto-expires.- Parameters:
ttlMillis- milliseconds until the profile auto-expires;<= 0means no expiry
-
get
Returns the gRPC chaos profile for the given service, falling back to the default ("") profile if no service-specific one exists. Returnsnullif neither exists (or both have expired). Expired entries are lazily removed. -
patch
Applies JSON Merge Patch semantics to the gRPC chaos profile for the given service. Only non-null fields frompartialare applied to the existing profile; unset fields in the partial are left unchanged. -
remove
Removes the gRPC chaos profile for the given service (no-op if absent). -
entries
Returns a snapshot copy of the current, non-expired service to profile mappings. -
ttlRemainingMillis
Returns, for each currently-active registration that carries a TTL, the remaining milliseconds until it auto-reverts. -
activeCountByFaultType
For each fault type, the number of currently-active (non-expired) registrations whose profile includes that fault. -
activeCount
public int activeCount()Returns the number of non-expired entries. -
incrementMatchCount
Atomically increments and returns the per-service match counter. Used by the fault decision logic to track how many times a given service has been matched for the count-window check. -
reset
public void reset()Clear all gRPC chaos profiles and match counters. Called on server reset. -
reconcileFromBackend
public void reconcileFromBackend()Rebuilds the node-local map from the backend store. Called by theInvalidationListenerwhen a remote write is detected.
-