-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field Reference: handle special characters #14044
Changes from 7 commits
5d80ce0
9f8be9e
179a530
4089067
f7c2999
d58447d
86168c1
88af969
62be405
96e8868
cc31ac9
bb9d939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ It is often useful to be able to refer to a field or collection of fields by nam | |||||
you can use the Logstash field reference syntax. | ||||||
|
||||||
The syntax to access a field specifies the entire path to the field, with each fragment wrapped in square brackets. | ||||||
When a field name contains square brackets, they must be properly <<formal-grammar-escape-sequences, _escaped_>>. | ||||||
|
||||||
_Field References_ can be expressed literally within <<conditionals,_Conditional_>> statements in your pipeline configurations, | ||||||
as string arguments to your pipeline plugins, or within sprintf statements that will be used by your pipeline plugins: | ||||||
|
@@ -133,3 +134,15 @@ embeddedFieldReference | |||||
; | ||||||
|
||||||
An _Embedded Field Reference_ is a _Field Reference_ that is itself wrapped in square brackets (`[` and `]`), and can be a component of a _Composite Field Reference_. | ||||||
|
||||||
[float] | ||||||
[[formal-grammar-escape-sequences]] | ||||||
=== Escape Sequences | ||||||
|
||||||
In order to reference a field whose name contains a character that has special meaning in the field reference grammar, it needs to be escaped. | ||||||
Logstash can be globally configured to use one of two field reference escape modes: | ||||||
|
||||||
- `NONE` (default): no escape sequence processing is done. Fields containing literal square brackets cannot be referenced by the Event API. | ||||||
- `PERCENT`: URI-style percent encoding of UTF-8 bytes. The left square bracket (`[`) is expressed as `%5B`, and the right square bracket (`]`) is expressed as `%5D`. | ||||||
// NOTE: the following is _also_ HTML-escaped in the asciidoc source document so that browsers rendering the HTML will unwrap one escape and leave the remaining. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest using regular words rather than the asciidoc admonition format. The comment treatment would keep it from getting formatted, but it keeps catching my eye. |
||||||
- `AMPERSAND`: HTML-style ampersand encoding (`&#` + decimal unicode codepoint + `;`). The left square bracket (`[`) is expressed as `[`, and the right square bracket (`]`) is expressed as `]`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,17 @@ Values other than `disabled` are currently considered BETA, and may produce unin | |
| When set to `true`, quoted strings will process the following escape sequences: `\n` becomes a literal newline (ASCII 10). `\r` becomes a literal carriage return (ASCII 13). `\t` becomes a literal tab (ASCII 9). `\\` becomes a literal backslash `\`. `\"` becomes a literal double quotation mark. `\'` becomes a literal quotation mark. | ||
| `false` | ||
|
||
| `config.field_reference.escape_style` | ||
a| _EXPERIMENTAL_ setting that provides a way to reference fields that contain <<formal-grammar-escape-sequences,field reference special characters>> `[` and `]`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be "Technical preview" instead of "Experimental." Reference: https://github.com/elastic/docs#using-the-technical-preview-admonition I tried adding/formatting this nugget in a variety of ways. So far, I don't really like any of them. Here are two of several things I tried: Admonitions are supposed to handle formatting, but I haven't hit on a combination that looks good and provides adequate info for the user. Only tagging the option with "Preview" doesn't convey the risk that the option might change or go away. I can sync with @gtback next week for ideas and design intent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wish the admonitions contained a link to a better place where we define what we mean and add more detail. I've never seen these used in a table, but let me know what I can do to help. |
||
|
||
Current options are: | ||
|
||
* `PERCENT`: URI-style `%`{plus}`HH` hexadecimal encoding of UTF-8 bytes (`[` -> `%5B`; `]` -> `%5D`) | ||
* `AMPERSAND`: HTML-style `&#`{plus}`DD`{plus}`;` encoding of decimal Unicode code-points (`[` -> `[`; `]` -> `[`) | ||
* `NONE`: field names containing special characters _cannot_ be referenced. | ||
|
||
| `NONE` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this entry case sensitive? In this topic, we already have two instances of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is. And there really is no reason for it to be upcase, so I have changed the implementation to be downcase throughout to match the other Both other instances of "None" in the file should actually be "N/A" since they represent an absence of a default value instead of a default value that is the literal |
||
|
||
| `modules` | ||
| When configured, `modules` must be in the nested YAML structure described above this table. | ||
| None | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,11 @@ class LogStash::Runner < Clamp::StrictCommand | |
:default => LogStash::SETTINGS.get_default("config.string"), | ||
:attribute_name => "config.string" | ||
|
||
option ["--field-reference-escape-style"], "STYLE", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got confused that this does not take effect when using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved in d58447d by moving the setting's application from the agent (which isn't started for shell sessions) to the runner before shell sessions are invoked. |
||
I18n.t("logstash.runner.flag.field-reference-escape-style"), | ||
:default => LogStash::SETTINGS.get_default("config.field_reference.escape_style"), | ||
:attribute_name => "config.field_reference.escape_style" | ||
|
||
# Module settings | ||
option ["--modules"], "MODULES", | ||
I18n.t("logstash.runner.flag.modules"), | ||
|
@@ -323,6 +328,14 @@ def execute | |
validate_settings! or return 1 | ||
@dispatcher.fire(:before_bootstrap_checks) | ||
|
||
field_reference_escape_style_setting = settings.get_setting('config.field_reference.escape_style') | ||
if field_reference_escape_style_setting.set? | ||
logger.warn(I18n.t("logstash.settings.experimental.set", canonical_name: field_reference_escape_style_setting.name)) | ||
end | ||
field_reference_escape_style = field_reference_escape_style_setting.value | ||
logger.debug("Setting global FieldReference escape style: #{field_reference_escape_style}") | ||
org.logstash.FieldReference::set_escape_style(field_reference_escape_style) | ||
|
||
return start_shell(setting("interactive"), binding) if setting("interactive") | ||
|
||
module_parser = LogStash::Modules::CLIParser.new(setting("modules_list"), setting("modules_variable_list")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.