Package org.microproxy.extras
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.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AccessLogFilterLogs everything.static final StringThe health-check pathnotHealthCheck()looks for. -
Method Summary
Modifier and TypeMethodDescriptionstatic AccessLogFilterallOf(AccessLogFilter... filters) Passes what all offilterspass.default AccessLogFilterand(AccessLogFilter other) Both this filter andother.static AccessLogFilteranyOf(AccessLogFilter... filters) Passes what any offilterspasses.static AccessLogFilterduration(AccessLogFilter.Comparison comparison, long millis) Compares the duration of the exchange or flow, in milliseconds, withmillis.static AccessLogFilterPasses requests that carry the fieldname(or the pseudo-header, such as:path).static AccessLogFilterPasses requests whose fieldnamematchesregexas a whole.static AccessLogFilterheaderEquals(String name, String value) Passes requests whose fieldnameis exactlyvalue.default AccessLogFilternegate()Returns a filter that passes what this one does not.static AccessLogFilterLeaves out health checks: requests forDEFAULT_HEALTH_CHECK_PATH, and requests from Envoy's health checker (User-Agent: Envoy/HC).static AccessLogFilternotHealthCheckHeader(String header) Leaves out health checks: requests that carry the fieldheader.static AccessLogFilternotHealthCheckPath(String path) Leaves out health checks: requests forpath(its query aside), and requests from Envoy's health checker (User-Agent: Envoy/HC).default AccessLogFilteror(AccessLogFilter other) This filter orother.static AccessLogFilterParses the compact syntax:static AccessLogFilterresponseFlag(ResponseFlag... flags) Passes records with any offlags, or with any flag at all when none is given.static AccessLogFilterruntime(double percent) Passespercentpercent of records, as Envoy's runtime filter does: chosen by the request'sX-Request-IDwhen it has one (so every log samples the same requests), else at random.static AccessLogFilterstatusCode(AccessLogFilter.Comparison comparison, int value) Compares the status of the response the client got (0 for none) withvalue.booleantest(FlowRecord record) Whetherrecordis to be logged.
-
Field Details
-
ALL
Logs everything. -
DEFAULT_HEALTH_CHECK_PATH
The health-check pathnotHealthCheck()looks for.- See Also:
-
-
Method Details
-
test
Whetherrecordis to be logged.- Parameters:
record- the finished exchange or flow- Returns:
- whether to log it
-
and
Both this filter andother.- Parameters:
other- the other filter- Returns:
- a filter that passes what both pass
-
or
This filter orother.- Parameters:
other- the other filter- Returns:
- a filter that passes what either passes
-
negate
Returns a filter that passes what this one does not.- Returns:
- a filter that passes what this one does not
-
statusCode
Compares the status of the response the client got (0 for none) withvalue.- Parameters:
comparison- how to comparevalue- the status to compare with- Returns:
- the filter
-
duration
Compares the duration of the exchange or flow, in milliseconds, withmillis. A record whose duration is unknown never passes.- Parameters:
comparison- how to comparemillis- the duration to compare with- Returns:
- the filter
-
notHealthCheck
Leaves out health checks: requests forDEFAULT_HEALTH_CHECK_PATH, and requests from Envoy's health checker (User-Agent: Envoy/HC).- Returns:
- the filter
-
notHealthCheckPath
Leaves out health checks: requests forpath(its query aside), and requests from Envoy's health checker (User-Agent: Envoy/HC).- Parameters:
path- the health-check path- Returns:
- the filter
-
notHealthCheckHeader
Leaves out health checks: requests that carry the fieldheader.- Parameters:
header- the field that marks a health check- Returns:
- the filter
-
responseFlag
Passes records with any offlags, or with any flag at all when none is given.- Parameters:
flags- the flags to look for- Returns:
- the filter
-
header
Passes requests that carry the fieldname(or the pseudo-header, such as:path).- Parameters:
name- the field name- Returns:
- the filter
-
header
Passes requests whose fieldnamematchesregexas a whole.- Parameters:
name- the field nameregex- the regular expression- Returns:
- the filter
-
headerEquals
Passes requests whose fieldnameis exactlyvalue.- Parameters:
name- the field namevalue- the value- Returns:
- the filter
-
runtime
Passespercentpercent of records, as Envoy's runtime filter does: chosen by the request'sX-Request-IDwhen it has one (so every log samples the same requests), else at random.- Parameters:
percent- from 0 to 100- Returns:
- the filter
-
allOf
Passes what all offilterspass.- Parameters:
filters- the filters- Returns:
- the filter
-
anyOf
Passes what any offilterspasses.- Parameters:
filters- the filters- Returns:
- the filter
-
parse
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
-