Interface AccessLogFilter

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface AccessLogFilter
Decides which finished exchanges and flows an access log writes, with the semantics of Envoy's access-log filters: statusCode(org.microproxy.extras.AccessLogFilter.Comparison, int), duration(org.microproxy.extras.AccessLogFilter.Comparison, long), notHealthCheck(), responseFlag(org.microproxy.ResponseFlag...), header(java.lang.String), runtime(double) sampling, and the allOf(org.microproxy.extras.AccessLogFilter...) and anyOf(org.microproxy.extras.AccessLogFilter...) combinators. Build one in Java,

 AccessLogFilter errors = AccessLogFilter.statusCode(Comparison.GE, 500)
         .or(AccessLogFilter.responseFlag())
         .and(AccessLogFilter.notHealthCheck());
 

or parse(java.lang.String) the compact syntax the command line and properties use: status>=500 || response_flag && not_health_check. See parse(java.lang.String) for the grammar.

  • Field Details

  • Method Details

    • test

      boolean test(FlowRecord record)
      Whether record is to be logged.
      Parameters:
      record - the finished exchange or flow
      Returns:
      whether to log it
    • and

      default AccessLogFilter and(AccessLogFilter other)
      Both this filter and other.
      Parameters:
      other - the other filter
      Returns:
      a filter that passes what both pass
    • or

      default AccessLogFilter or(AccessLogFilter other)
      This filter or other.
      Parameters:
      other - the other filter
      Returns:
      a filter that passes what either passes
    • negate

      default AccessLogFilter negate()
      Returns a filter that passes what this one does not.
      Returns:
      a filter that passes what this one does not
    • statusCode

      static AccessLogFilter statusCode(AccessLogFilter.Comparison comparison, int value)
      Compares the status of the response the client got (0 for none) with value.
      Parameters:
      comparison - how to compare
      value - the status to compare with
      Returns:
      the filter
    • duration

      static AccessLogFilter duration(AccessLogFilter.Comparison comparison, long millis)
      Compares the duration of the exchange or flow, in milliseconds, with millis. A record whose duration is unknown never passes.
      Parameters:
      comparison - how to compare
      millis - the duration to compare with
      Returns:
      the filter
    • notHealthCheck

      static AccessLogFilter notHealthCheck()
      Leaves out health checks: requests for DEFAULT_HEALTH_CHECK_PATH, and requests from Envoy's health checker (User-Agent: Envoy/HC).
      Returns:
      the filter
    • notHealthCheckPath

      static AccessLogFilter notHealthCheckPath(String path)
      Leaves out health checks: requests for path (its query aside), and requests from Envoy's health checker (User-Agent: Envoy/HC).
      Parameters:
      path - the health-check path
      Returns:
      the filter
    • notHealthCheckHeader

      static AccessLogFilter notHealthCheckHeader(String header)
      Leaves out health checks: requests that carry the field header.
      Parameters:
      header - the field that marks a health check
      Returns:
      the filter
    • responseFlag

      static AccessLogFilter responseFlag(ResponseFlag... flags)
      Passes records with any of flags, or with any flag at all when none is given.
      Parameters:
      flags - the flags to look for
      Returns:
      the filter
    • header

      static AccessLogFilter header(String name)
      Passes requests that carry the field name (or the pseudo-header, such as :path).
      Parameters:
      name - the field name
      Returns:
      the filter
    • header

      static AccessLogFilter header(String name, String regex)
      Passes requests whose field name matches regex as a whole.
      Parameters:
      name - the field name
      regex - the regular expression
      Returns:
      the filter
    • headerEquals

      static AccessLogFilter headerEquals(String name, String value)
      Passes requests whose field name is exactly value.
      Parameters:
      name - the field name
      value - the value
      Returns:
      the filter
    • runtime

      static AccessLogFilter runtime(double percent)
      Passes percent percent of records, as Envoy's runtime filter does: chosen by the request's X-Request-ID when it has one (so every log samples the same requests), else at random.
      Parameters:
      percent - from 0 to 100
      Returns:
      the filter
    • allOf

      static AccessLogFilter allOf(AccessLogFilter... filters)
      Passes what all of filters pass.
      Parameters:
      filters - the filters
      Returns:
      the filter
    • anyOf

      static AccessLogFilter anyOf(AccessLogFilter... filters)
      Passes what any of filters passes.
      Parameters:
      filters - the filters
      Returns:
      the filter
    • parse

      static AccessLogFilter parse(String expression)
      Parses the compact syntax:
       expr   := term (('||' | 'or') term)*
       term   := factor (('&&' | 'and') factor)*
       factor := ('!' | 'not') factor | '(' expr ')' | filter
       filter := ('status' | 'status_code') op INT
               | 'duration' op INT ['ms' | 's']
               | 'not_health_check' ['(' (path | 'header=' name) ')']
               | 'response_flag' ['(' flag (',' flag)* ')']
               | 'header' '(' name [('~' regex) | ('=' value)] ')'
               | ('runtime' | 'sample') '(' percent ['%'] ')'
       op     := '=' | '==' | '!=' | '>=' | '<=' | '>' | '<'
       

      For example status>=500 || response_flag(UF,UO), not_health_check(/ready) && sample(10%), header(user-agent~curl/.*). Flags are short codes or long names.

      Parameters:
      expression - the filter expression
      Returns:
      the filter
      Throws:
      IllegalArgumentException - if the expression is malformed