Package org.microproxy.stats
Class TagExtractor
java.lang.Object
org.microproxy.stats.TagExtractor
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 as0.0.0.0_8080or[__1]_8080)envoy_response_code_class: the digit of a name ending in_rq_<digit>xxmicroproxy_response_flag: the flag at the end ofdownstream_rq_response_flag.<flag>, a MicroProxy stat
and these for MicroProxy's per-protocol stats:
microproxy_direction:downstreamorupstreaminhttp2.<direction>.andhttp3.<direction>.microproxy_quic_scope:downstream,upstream,transparentormasqueinquic.<scope>.microproxy_quic_error: the error at the end ofhandshake_failures.<error>microproxy_congestion_controller: the controller at the end ofcongestion_controller.<name>microproxy_drop_reason: the reason at the end ofdropped_initials.<reason>microproxy_socks_version:v4orv5insocks.<version>.microproxy_socks_reply: the reply at the end ofreplies.<reply>microproxy_reject_reason: the reason at the end offlow_rejected.<reason>microproxy_tunnel_kind: the kind intunnel.<kind>.microproxy_close_code: the code at the end ofclose_codes.<code>microproxy_budget: the budget at the end ofbudget_exceeded.<kind>(steps,memory,time)microproxy_scriptandmicroproxy_script_hook: the script and the hook function inhooks.starlark.<script>.<hook>.<stat>microproxy_hook: the hook family inhooks.<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)).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA name with its tags taken out.static final recordOne rule. -
Method Summary
Modifier and TypeMethodDescriptionstatic TagExtractorReturns the rules for the tags Envoy gives MicroProxy's stats (see the class documentation).Takes the tags out ofname.static TagExtractornone()Returns an extractor with no rules, which leaves every name whole.rules()Returns the rules, in the order they run.static Stringvaluemade fit to be one element of a flat name: every character other than a letter, digit,_or-becomes_, so that it has no dots.This extractor with one more rule, which runs after the others.
-
Method Details
-
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
Returns an extractor with no rules, which leaves every name whole.- Returns:
- an extractor with no rules, which leaves every name whole
-
with
This extractor with one more rule, which runs after the others.- Parameters:
tagName- the name of the tag the rule findsregex- 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 groupsPatternSyntaxException- if it is not a valid expression
-
rules
Returns the rules, in the order they run.- Returns:
- the rules, in the order they run
-
extract
Takes the tags out ofname.- Parameters:
name- a flat stat name- Returns:
- the tag-extracted name and the tags
-
sanitize
valuemade 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-
-