Class HttpReferrerAuditHeader

java.lang.Object
org.apache.hadoop.fs.store.audit.HttpReferrerAuditHeader

@Private @Unstable public final class HttpReferrerAuditHeader extends Object
Contains all the logic for generating an HTTP "Referer" entry; includes escaping query params. Tests for this are in org.apache.hadoop.fs.s3a.audit.TestHttpReferrerAuditHeader so as to verify that header generation in the S3A auditors, and S3 log parsing, all work.

This header may be shared across multiple threads at the same time. so some methods are marked as synchronized, specifically those reading or writing the attribute map.

For the same reason, maps and lists passed down during construction are copied into thread safe structures.

  • Field Details

    • REFERRER_PATH_FORMAT

      public static final String REFERRER_PATH_FORMAT
      Format of path to build: "/hadoop/1/%3$s/%2$s/". the params passed in are (context ID, span ID, op). Update TestHttpReferrerAuditHeader.SAMPLE_LOG_ENTRY on changes
      See Also:
  • Method Details

    • buildHttpReferrer

      public String buildHttpReferrer()
      Build the referrer string. This includes dynamically evaluating all of the evaluated attributes. If there is an error creating the string it will be logged once per entry, and "" returned.
      Returns:
      a referrer string or ""
    • set

      public void set(String key, String value)
      Set an attribute. If the value is non-null/empty, it will be used as a query parameter.
      Parameters:
      key - key to set
      value - value.
    • getContextId

      public String getContextId()
    • getOperationName

      public String getOperationName()
    • getSpanId

      public String getSpanId()
    • getPath1

      public String getPath1()
    • getPath2

      public String getPath2()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • escapeToPathElement

      public static String escapeToPathElement(CharSequence source)
      Perform any escaping to valid path elements in advance of new URI() doing this itself. Only path separators need to be escaped/converted at this point.
      Parameters:
      source - source string
      Returns:
      an escaped path element.
    • maybeStripWrappedQuotes

      public static String maybeStripWrappedQuotes(String header)
      Strip any quotes from around a header. This is needed when processing log entries.
      Parameters:
      header - field.
      Returns:
      field without quotes.
    • extractQueryParameters

      public static Map<String,String> extractQueryParameters(String header) throws URISyntaxException
      Split up the string. Uses httpClient: make sure it is on the classpath. Any query param with a name but no value, e.g ?something is returned in the map with an empty string as the value.
      Parameters:
      header - URI to parse
      Returns:
      a map of parameters.
      Throws:
      URISyntaxException - failure to build URI from header.
    • builder

      public static HttpReferrerAuditHeader.Builder builder()
      Get a builder.
      Returns:
      a new builder.