Class GrpcChaosProfile


public class GrpcChaosProfile extends ObjectWithJsonToString
Declarative gRPC fault/chaos injection profile for probabilistically returning gRPC error statuses (UNAVAILABLE, DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED, INTERNAL, etc.) on matched gRPC method calls, with latency, quota, and count-window controls. This is distinct from the existing gRPC health-check serving-status feature (GrpcHealthRegistry).

Profiles are registered in the GrpcChaosRegistry keyed by gRPC service name, and applied by the GrpcToHttpRequestHandler Netty handler before normal gRPC request conversion. A default profile (keyed by empty string) applies to all services unless overridden by a service-specific profile.

Count-based stateful fault window: succeedFirst and failRequestCount define a window over the per-service 1-based match count where chaos is eligible:

  • Matches 1..succeedFirst are NOT eligible (chaos is suppressed).
  • Matches (succeedFirst+1)..(succeedFirst+failRequestCount) ARE eligible.
  • Matches beyond succeedFirst+failRequestCount recover (no chaos).
When both fields are null every match is eligible.

Stateful request quota: when quotaName, quotaLimit and quotaWindowMillis are set, requests beyond quotaLimit within the window are rejected with RESOURCE_EXHAUSTED — a deterministic, hard rate limit (see HttpQuotaRegistry).

Determinism: with errorProbability of 1.0 (always) or 0.0/null (never) the error decision is fully deterministic. A fractional probability draws once per request; set seed to make that draw reproducible (note: a fixed seed yields the same decision every time).

Follows the model field/withX/getter convention so it round-trips through Jackson without a bespoke (de)serializer.

  • Constructor Details

    • GrpcChaosProfile

      public GrpcChaosProfile()
  • Method Details

    • grpcChaosProfile

      public static GrpcChaosProfile grpcChaosProfile()
    • withErrorStatusCode

      public GrpcChaosProfile withErrorStatusCode(String errorStatusCode)
    • getErrorStatusCode

      public String getErrorStatusCode()
    • withErrorMessage

      public GrpcChaosProfile withErrorMessage(String errorMessage)
    • getErrorMessage

      public String getErrorMessage()
    • withErrorProbability

      public GrpcChaosProfile withErrorProbability(Double errorProbability)
    • getErrorProbability

      public Double getErrorProbability()
    • withSeed

      public GrpcChaosProfile withSeed(Long seed)
    • getSeed

      public Long getSeed()
    • withLatencyMs

      public GrpcChaosProfile withLatencyMs(Long latencyMs)
    • getLatencyMs

      public Long getLatencyMs()
    • withSucceedFirst

      public GrpcChaosProfile withSucceedFirst(Integer succeedFirst)
    • getSucceedFirst

      public Integer getSucceedFirst()
    • withFailRequestCount

      public GrpcChaosProfile withFailRequestCount(Integer failRequestCount)
    • getFailRequestCount

      public Integer getFailRequestCount()
    • withQuotaName

      public GrpcChaosProfile withQuotaName(String quotaName)
    • getQuotaName

      public String getQuotaName()
    • withQuotaLimit

      public GrpcChaosProfile withQuotaLimit(Integer quotaLimit)
    • getQuotaLimit

      public Integer getQuotaLimit()
    • withQuotaWindowMillis

      public GrpcChaosProfile withQuotaWindowMillis(Long quotaWindowMillis)
    • getQuotaWindowMillis

      public Long getQuotaWindowMillis()
    • withOmitGrpcStatus

      public GrpcChaosProfile withOmitGrpcStatus(Boolean omitGrpcStatus)
    • getOmitGrpcStatus

      public Boolean getOmitGrpcStatus()
    • withCorruptGrpcStatus

      public GrpcChaosProfile withCorruptGrpcStatus(Boolean corruptGrpcStatus)
    • getCorruptGrpcStatus

      public Boolean getCorruptGrpcStatus()
    • withCustomTrailers

      public GrpcChaosProfile withCustomTrailers(Map<String,String> customTrailers)
      Sets arbitrary trailer key/value pairs to inject on fault responses. Accepts null (meaning "no custom trailers"). Rejects any entry whose key or value contains \r or \n (header/response splitting risk), and rejects null or empty keys.
      Throws:
      IllegalArgumentException - if any key is null/empty or any key/value contains CR/LF
    • getCustomTrailers

      public Map<String,String> getCustomTrailers()
    • withAbortAfterMessages

      public GrpcChaosProfile withAbortAfterMessages(Integer abortAfterMessages)
      Sets the client-streaming message count threshold for abort injection. Only meaningful for client-streaming (multi-frame) requests: when the decoded gRPC frame count in the request body is >= this threshold, the handler responds with ABORTED. For unary (single-frame) requests the message count is always 1, so setting this to 1 aborts every request while values > 1 only trigger on multi-frame bodies.
      Throws:
      IllegalArgumentException - if abortAfterMessages is non-null and < 1
    • getAbortAfterMessages

      public Integer getAbortAfterMessages()
    • countWindowEligible

      public boolean countWindowEligible(int matchCount)
      Returns true when the given 1-based match count falls within the chaos-eligible window defined by succeedFirst and failRequestCount. When both fields are null this returns true for any matchCount (backward compatible).
      Parameters:
      matchCount - 1-based match count (0 when unknown)
      Returns:
      true if this match is eligible for chaos injection
    • hasAnyFault

      public boolean hasAnyFault()
      Returns true when this profile has at least one fault-producing field configured: an error probability, an error status code, a latency, quota fields, trailer faults (omit/corrupt/custom), or stream abort.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class ObjectWithReflectiveEqualsHashCodeToString
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class ObjectWithReflectiveEqualsHashCodeToString