Class TagExtractor

java.lang.Object
org.microproxy.stats.TagExtractor

public final class TagExtractor extends Object
Takes tag values out of flat stat names, once, when a metric is registered, as Envoy's tag extraction does: cluster.direct.upstream_rq_2xx becomes cluster.upstream_rq_xx with the tags envoy_cluster_name="direct" and envoy_response_code_class="2".

Each rule is a tag name and a regular expression with two groups: the first is the part removed from the name, the second (inside it, or equal to it) the tag's value. The rules run in order, each on what the earlier ones left of the name; a rule that does not match adds nothing. The defaults give the tags Envoy gives the stats MicroProxy has:

  • envoy_http_conn_manager_prefix: http.<prefix>.
  • envoy_cluster_name: cluster.<name>.
  • envoy_listener_address: listener.<address>. (an address such as 0.0.0.0_8080 or [__1]_8080)
  • envoy_response_code_class: the digit of a name ending in _rq_<digit>xx
  • microproxy_response_flag: the flag at the end of downstream_rq_response_flag.<flag>, a MicroProxy stat

and these for MicroProxy's per-protocol stats:

  • microproxy_direction: downstream or upstream in http2.<direction>. and http3.<direction>.
  • microproxy_quic_scope: downstream, upstream, transparent or masque in quic.<scope>.
  • microproxy_quic_error: the error at the end of handshake_failures.<error>
  • microproxy_congestion_controller: the controller at the end of congestion_controller.<name>
  • microproxy_drop_reason: the reason at the end of dropped_initials.<reason>
  • microproxy_socks_version: v4 or v5 in socks.<version>.
  • microproxy_socks_reply: the reply at the end of replies.<reply>
  • microproxy_reject_reason: the reason at the end of flow_rejected.<reason>
  • microproxy_tunnel_kind: the kind in tunnel.<kind>.
  • microproxy_close_code: the code at the end of close_codes.<code>
  • microproxy_budget: the budget at the end of budget_exceeded.<kind> (steps, memory, time)
  • microproxy_script and microproxy_script_hook: the script and the hook function in hooks.starlark.<script>.<hook>.<stat>
  • microproxy_hook: the hook family in hooks.<family>.

Values in flat names cannot contain dots (except listener addresses): the proxy writes the cluster and prefix names it makes up with underscores instead (sanitize(java.lang.String)).

  • Method Details

    • envoyDefaults

      public static TagExtractor envoyDefaults()
      Returns the rules for the tags Envoy gives MicroProxy's stats (see the class documentation).
      Returns:
      the rules for the tags Envoy gives MicroProxy's stats (see the class documentation)
    • none

      public static TagExtractor none()
      Returns an extractor with no rules, which leaves every name whole.
      Returns:
      an extractor with no rules, which leaves every name whole
    • with

      public TagExtractor with(String tagName, String regex)
      This extractor with one more rule, which runs after the others.
      Parameters:
      tagName - the name of the tag the rule finds
      regex - the expression: group 1 is removed from the name, group 2 is the value
      Returns:
      a new extractor
      Throws:
      IllegalArgumentException - if the expression has fewer than two groups
      PatternSyntaxException - if it is not a valid expression
    • rules

      public List<TagExtractor.Rule> rules()
      Returns the rules, in the order they run.
      Returns:
      the rules, in the order they run
    • extract

      public TagExtractor.Result extract(String name)
      Takes the tags out of name.
      Parameters:
      name - a flat stat name
      Returns:
      the tag-extracted name and the tags
    • sanitize

      public static String sanitize(String value)
      value made fit to be one element of a flat name: every character other than a letter, digit, _ or - becomes _, so that it has no dots.
      Parameters:
      value - a cluster name, host name or similar
      Returns:
      the value with only letters, digits, _ and -