Class Guardrail

  • Direct Known Subclasses:
    EnableFlag, Predicates, Threshold, Values

    public abstract class Guardrail
    extends java.lang.Object
    General class defining a given guardrail that guards against some particular usage/condition.

    Some guardrails only emit warnings when triggered, while others abort the query that triggers them. Some may do one or the other based on specific threshold. The queries are aborted with an InvalidRequestException.

    Note that all the defined classes support live updates, which is why each guardrail class constructor takes suppliers of the condition the guardrail acts on rather than the condition itself. This implies that said suppliers should be fast and non-blocking to avoid surprises.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static NoSpamLogger logger  
      java.lang.String name
      A name identifying the guardrail (mainly for shipping with diagnostic events).
      java.lang.String reason
      An optional description of the reason for guarding the operation.
      protected static java.lang.String REDACTED  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean enabled()
      Checks whether this guardrail is enabled or not when the check is done for a background opperation that is not associated to a specific ClientState, such as compaction or other background processes.
      boolean enabled​(ClientState state)
      Checks whether this guardrail is enabled or not.
      protected void fail​(java.lang.String message, java.lang.String redactedMessage, ClientState state)  
      protected void fail​(java.lang.String message, ClientState state)  
      protected void warn​(java.lang.String message)  
      protected void warn​(java.lang.String message, java.lang.String redactedMessage)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • name

        public final java.lang.String name
        A name identifying the guardrail (mainly for shipping with diagnostic events).
      • reason

        @Nullable
        public final java.lang.String reason
        An optional description of the reason for guarding the operation.
    • Method Detail

      • enabled

        public boolean enabled()
        Checks whether this guardrail is enabled or not when the check is done for a background opperation that is not associated to a specific ClientState, such as compaction or other background processes. Operations that are associated to a ClientState, such as CQL queries, should use enabled(ClientState).
        Returns:
        true if this guardrail is enabled, false otherwise.
      • enabled

        public boolean enabled​(@Nullable
                               ClientState state)
        Checks whether this guardrail is enabled or not. This will be enabled if the database is initialized and the authenticated user (if specified) is not system nor superuser.
        Parameters:
        state - the client state, used to skip the check if the query is internal or is done by a superuser. A null value means that the check should be done regardless of the query.
        Returns:
        true if this guardrail is enabled, false otherwise.
      • warn

        protected void warn​(java.lang.String message)
      • warn

        protected void warn​(java.lang.String message,
                            java.lang.String redactedMessage)
      • fail

        protected void fail​(java.lang.String message,
                            @Nullable
                            ClientState state)
      • fail

        protected void fail​(java.lang.String message,
                            java.lang.String redactedMessage,
                            @Nullable
                            ClientState state)