Add some format string support to libbeat #2065
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds some customizable format-string support to libbeat. This feature is not used anywhere yet, but lays some ground-work for features/improvements requiring format-string support dynamically constructing strings right from events.
EventFormatString implements format string support on events
of type common.MapStr.
The concrete event expansion requires the field name enclosed by brackets.
For example: '%{[field.name]}'. Field names can be separated by points or
multiple braces. This format
%{[field.name]}
is equivalent to%{[field][name]}
.Default values are given by the colon operator. For example:
%{[field.name]:default value}
.EventFormatString is build on top of generic StringFormatter Compile function.
Compile compiles an input format string into a StringFormatter. The variable
compiler
vc
is invoked for every variable expansion found in the input formatstring.
Variable expansion are enclosed in expansion braces
%{<expansion>}
.The
<expansion>
can contain additional parameters separated by opsintroduced by collons ':'. For example the format string
%{value:v1:?v2}
will be parsed into variable expansion on
value
with variable ops[(":", "v1"), (":?", "v2")]
. It's up to the variable compiler to interpretcontent and variable ops.
The back-slash character
\
acts as escape character so the sequence '%{' will be written to the resulting string is\
is used.