-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Ingest Pipelines] Fix serialization and deserialization of user input for "patterns" fields #94689
[Ingest Pipelines] Fix serialization and deserialization of user input for "patterns" fields #94689
Conversation
…b processors, also addded a test
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
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.
Thanks for jumping on this bugfix so quickly!
I tested the original issue and confirmed it is now working as expected. However, I did find an issue when running the example in the dissect docs. I think we also need to account for escaping quotes. Can you take a look?
{
"dissect": {
"field": "message",
"pattern" : "%{clientip} %{ident} %{auth} [%{@timestamp}] \"%{verb} %{request} HTTP/%{httpversion}\" %{status} %{size}"
}
}
Very well caught @alisonelizabeth 👏🏻 ! I've pivoted the approach away from changing the indentation levels by hand and am rather making use of The quirk with this approach is that a user must provide a valid JSON string which requires an added level of validation on the input pattern. I think the strength with this is that users will be able to use all examples of patterns in the docs exactly as they appear in the input boxes for grok patterns. Let me know what you think! |
@elasticmachine merge upstream |
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.
Great work @jloleysens! Latest LGTM. Verified changes locally. Left one minor comment.
} | ||
}; | ||
|
||
export const isJSONStringValidator: ValidationFunc = ({ value }) => { |
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.
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.
Yeah I looked at that validator, but the condition for returning true
also requires that the result of JSON.parse
be an object
- in this case it will be a string
.
if (parsedJSON && typeof parsedJSON !== 'object') { |
For now I think it is OK to keep that behaviour and create our own validator.
…t for "patterns" fields (elastic#94689) * updated serialization and deserialization behavior of dissect and gsub processors, also addded a test * also fix grok processor * pivot input checking to use JSON.stringify and JSON.parse Co-authored-by: Kibana Machine <[email protected]>
💔 Build Failed
Failed CI StepsTest FailuresKibana Pipeline / general / X-Pack API Integration Tests.x-pack/test/api_integration/apis/management/index_management/component_templates·ts.apis management index management Component templates Delete should return an error for any component templates not sucessfully deletedStandard Out
Stack Trace
Kibana Pipeline / general / X-Pack API Integration Tests.x-pack/test/api_integration/apis/management/index_management/component_templates·ts.apis management index management Component templates Delete should return an error for any component templates not sucessfully deletedStandard Out
Stack Trace
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: |
…t for "patterns" fields (#94689) (#94897) * updated serialization and deserialization behavior of dissect and gsub processors, also addded a test * also fix grok processor * pivot input checking to use JSON.stringify and JSON.parse Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
…t for "patterns" fields (#94689) (#94896) * updated serialization and deserialization behavior of dissect and gsub processors, also addded a test * also fix grok processor * pivot input checking to use JSON.stringify and JSON.parse Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
Summary
Fix #94404
When users input text for the "pattern" field inside of the Grok, Dissect and Gsub processors we were not taking into account that this input comes from text area or text inputs where value is taken literally as it appears which is then
JSON.stringify
'd to something users do not expect. For instance, all backslash escaped chars (\t
,\n
) input by the user are encoded with an added backslash (\\t
,\\n
) resulting in a grok that matches for a backslash and at
char instead of a whitespace tab.To fix this, when deserializing, we
JSON.stringify
the text we got from the server to escape whitespace and render a result in the text area/input that makes whitespaces visible.When serializing the input we
JSON.parse
to remove one level of indentation so that we actually have\t
instead of\\t
as the text value in memory when the form is submitted.Release note
We fixed a bug that incorrectly encoded user input for special characters like tabs (
\t
) and newlines (\n
) for the Grok, Gsub and Dissect processors in the ingest pipelines editor.Checklist
Delete any items that are not applicable to this PR.