Skip to content
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

Handle both JSON and XJSON in processor editor #200692

Merged

Conversation

SoniaSanzV
Copy link
Contributor

@SoniaSanzV SoniaSanzV commented Nov 19, 2024

Closes #175753

Summary

When a user creates a pipeline with a processor that has an JSON editor field [Foreach, Grok, Inference, Redact and Script], our editor convert the input to XJSON. This can be confused to the user, who see their input modified without understanding the reason. For that, this PR creates a new editor that handles both XJSON and JSON format and does not changes the content that the user introduced while editing. Once the pipeline is saved, it will always retrieve the parsed data.

I've created a whole new editor instead of modifying XJsonEditor because the original one is still in use in the Custom processor. This is because I've created a list of the processor fields that needs to be serialized in convertProcessorInternalToProcessor. Since we don't know the name of the custom processor, we can't apply this workflow. I'm not super happy with the idea of adding manually the names of the processors to a list. I would like to have something more agnostic but I haven't come up with a solution that allows me to do that without breaking other fields. So, any suggestions are super welcome!

How to test

Create one of the following processors: Foreach, Grok, Inference, Redact or Script. In the JSON field, add a JSON with both with and without escaped strings. While you are editing the processor before saving the pipeline, you should see the processor as you typed it. In the Show Request flyout, you should see the properly parsed JSON.

The pipeline should save with the correct parsed values and, once saved, if you click update, you only will get parsed values.

Demo

processors_editor.mov

@SoniaSanzV SoniaSanzV added Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes Feature:Ingest Node Pipelines Ingest node pipelines management backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Nov 19, 2024
@SoniaSanzV SoniaSanzV self-assigned this Nov 19, 2024
@SoniaSanzV SoniaSanzV requested a review from a team as a code owner November 19, 2024 10:07
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-management (Team:Kibana Management)

Copy link
Contributor

@ElenaStoeva ElenaStoeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @SoniaSanzV! This approach makes sense to me and the UI works well. I would just suggest renaming the new component as the current name is a bit confusing. Also, why can't we use the new component for the Custom processor as well and completely remove the old xjson editor? It would be nice to add this fix to the Custom processor as well and make the behaviour there consistent with the rest of the processors.

lineNumbers: 'off',
};

export const XJsonAndJsonEditor: FunctionComponent<Props> = ({ field, editorProps }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simply name it XJsonEditor since json language is a subset of xjson, so if an editor is xjson, it means that it should also support json.

@SoniaSanzV SoniaSanzV force-pushed the ingestPipelines/grokProcessor_#175753 branch from 33ac991 to a1af452 Compare November 21, 2024 10:34
@SoniaSanzV
Copy link
Contributor Author

Great work @SoniaSanzV! This approach makes sense to me and the UI works well. I would just suggest renaming the new component as the current name is a bit confusing. Also, why can't we use the new component for the Custom processor as well and completely remove the old xjson editor? It would be nice to add this fix to the Custom processor as well and make the behaviour there consistent with the rest of the processors.

Thanks for the review @ElenaStoeva . I've been giving it a thought and found a way to make the custom processor also have the same formatting as the others. So I have been able to leave the editor name as XJsonEditor.

Screen.Recording.2024-11-21.at.11.32.14.mov

Copy link
Contributor

@ElenaStoeva ElenaStoeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for refactoring the changes @SoniaSanzV! Tested locally and it works well. Changes lgtm with a small suggestion on the tests.


await act(async () => {
find('patternDefinitionsField').simulate('change', {
jsonContent: '{"pattern_1":"""aaa(bbb""", "pattern_2":"aaa(bbb"}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (applies to all test files): can we try using triple-quote strings that contain illegal characters (e.g. " or \) and check that they are correctly escaped when converted to single-quote chars? We can also add the equivalent single-quote chars and make sure they are not changed when being serialized.

@SoniaSanzV SoniaSanzV force-pushed the ingestPipelines/grokProcessor_#175753 branch from a1af452 to b4436a8 Compare November 26, 2024 15:24
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
ingestPipelines 405.8KB 406.8KB +1.1KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
ingestPipelines 17.9KB 17.8KB -40.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
ingestPipelines 15 29 +14

Total ESLint disabled count

id before after diff
ingestPipelines 15 29 +14

History

cc @SoniaSanzV

@SoniaSanzV SoniaSanzV merged commit 8839894 into elastic:main Nov 27, 2024
22 checks passed
@SoniaSanzV SoniaSanzV deleted the ingestPipelines/grokProcessor_#175753 branch November 27, 2024 06:42
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12045117770

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 27, 2024
Closes [elastic#175753](elastic#175753)

## Summary
When a user creates a pipeline with a processor that has an JSON editor
field [Foreach, Grok, Inference, Redact and Script], our editor convert
the input to XJSON. This can be confused to the user, who see their
input modified without understanding the reason. For that, this PR
creates a new editor that handles both XJSON and JSON format and does
not changes the content that the user introduced while editing. Once the
pipeline is saved, it will always retrieve the parsed data.

I've created a whole new editor instead of modifying `XJsonEditor`
because the original one is still in use in the `Custom processor`. This
is because I've created [a
list](https://github.com/SoniaSanzV/kibana/blob/d7d5ecafa7dbae96fe52c2e37394520b6353bd92/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts#L151-L157)
of the processor fields that needs to be serialized in
`convertProcessorInternalToProcessor`. Since we don't know the name of
the custom processor, we can't apply this workflow. I'm not super happy
with the idea of adding manually the names of the processors to a list.
I would like to have something more agnostic but I haven't come up with
a solution that allows me to do that without breaking other fields. So,
any suggestions are super welcome!

### How to test
Create one of the following processors: Foreach, Grok, Inference, Redact
or Script. In the JSON field, add a JSON with both with and without
escaped strings. While you are editing the processor before saving the
pipeline, you should see the processor as you typed it. In the `Show
Request` flyout, you should see the properly parsed JSON.

The pipeline should save with the correct parsed values and, once saved,
if you click update, you only will get parsed values.

### Demo

https://github.com/user-attachments/assets/1f9681df-2fb4-4ed5-ac30-03f2937abfe9
(cherry picked from commit 8839894)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 27, 2024
# Backport

This will backport the following commits from `main` to `8.x`:
- [Handle both JSON and XJSON in processor editor
(#200692)](#200692)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sonia Sanz
Vivas","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-27T06:42:30Z","message":"Handle
both JSON and XJSON in processor editor (#200692)\n\nCloses
[#175753](https://github.com/elastic/kibana/issues/175753)\r\n\r\n##
Summary\r\nWhen a user creates a pipeline with a processor that has an
JSON editor\r\nfield [Foreach, Grok, Inference, Redact and Script], our
editor convert\r\nthe input to XJSON. This can be confused to the user,
who see their\r\ninput modified without understanding the reason. For
that, this PR\r\ncreates a new editor that handles both XJSON and JSON
format and does\r\nnot changes the content that the user introduced
while editing. Once the\r\npipeline is saved, it will always retrieve
the parsed data.\r\n\r\nI've created a whole new editor instead of
modifying `XJsonEditor`\r\nbecause the original one is still in use in
the `Custom processor`. This\r\nis because I've created
[a\r\nlist](https://github.com/SoniaSanzV/kibana/blob/d7d5ecafa7dbae96fe52c2e37394520b6353bd92/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts#L151-L157)\r\nof
the processor fields that needs to be serialized
in\r\n`convertProcessorInternalToProcessor`. Since we don't know the
name of\r\nthe custom processor, we can't apply this workflow. I'm not
super happy\r\nwith the idea of adding manually the names of the
processors to a list.\r\nI would like to have something more agnostic
but I haven't come up with\r\na solution that allows me to do that
without breaking other fields. So,\r\nany suggestions are super
welcome!\r\n\r\n### How to test\r\nCreate one of the following
processors: Foreach, Grok, Inference, Redact\r\nor Script. In the JSON
field, add a JSON with both with and without\r\nescaped strings. While
you are editing the processor before saving the\r\npipeline, you should
see the processor as you typed it. In the `Show\r\nRequest` flyout, you
should see the properly parsed JSON.\r\n\r\nThe pipeline should save
with the correct parsed values and, once saved,\r\nif you click update,
you only will get parsed values.\r\n\r\n###
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/1f9681df-2fb4-4ed5-ac30-03f2937abfe9","sha":"8839894646451144a9534157c08cde18727aa240","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Kibana
Management","release_note:skip","v9.0.0","Feature:Ingest Node
Pipelines","backport:prev-minor"],"title":"Handle both JSON and XJSON in
processor
editor","number":200692,"url":"https://github.com/elastic/kibana/pull/200692","mergeCommit":{"message":"Handle
both JSON and XJSON in processor editor (#200692)\n\nCloses
[#175753](https://github.com/elastic/kibana/issues/175753)\r\n\r\n##
Summary\r\nWhen a user creates a pipeline with a processor that has an
JSON editor\r\nfield [Foreach, Grok, Inference, Redact and Script], our
editor convert\r\nthe input to XJSON. This can be confused to the user,
who see their\r\ninput modified without understanding the reason. For
that, this PR\r\ncreates a new editor that handles both XJSON and JSON
format and does\r\nnot changes the content that the user introduced
while editing. Once the\r\npipeline is saved, it will always retrieve
the parsed data.\r\n\r\nI've created a whole new editor instead of
modifying `XJsonEditor`\r\nbecause the original one is still in use in
the `Custom processor`. This\r\nis because I've created
[a\r\nlist](https://github.com/SoniaSanzV/kibana/blob/d7d5ecafa7dbae96fe52c2e37394520b6353bd92/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts#L151-L157)\r\nof
the processor fields that needs to be serialized
in\r\n`convertProcessorInternalToProcessor`. Since we don't know the
name of\r\nthe custom processor, we can't apply this workflow. I'm not
super happy\r\nwith the idea of adding manually the names of the
processors to a list.\r\nI would like to have something more agnostic
but I haven't come up with\r\na solution that allows me to do that
without breaking other fields. So,\r\nany suggestions are super
welcome!\r\n\r\n### How to test\r\nCreate one of the following
processors: Foreach, Grok, Inference, Redact\r\nor Script. In the JSON
field, add a JSON with both with and without\r\nescaped strings. While
you are editing the processor before saving the\r\npipeline, you should
see the processor as you typed it. In the `Show\r\nRequest` flyout, you
should see the properly parsed JSON.\r\n\r\nThe pipeline should save
with the correct parsed values and, once saved,\r\nif you click update,
you only will get parsed values.\r\n\r\n###
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/1f9681df-2fb4-4ed5-ac30-03f2937abfe9","sha":"8839894646451144a9534157c08cde18727aa240"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200692","number":200692,"mergeCommit":{"message":"Handle
both JSON and XJSON in processor editor (#200692)\n\nCloses
[#175753](https://github.com/elastic/kibana/issues/175753)\r\n\r\n##
Summary\r\nWhen a user creates a pipeline with a processor that has an
JSON editor\r\nfield [Foreach, Grok, Inference, Redact and Script], our
editor convert\r\nthe input to XJSON. This can be confused to the user,
who see their\r\ninput modified without understanding the reason. For
that, this PR\r\ncreates a new editor that handles both XJSON and JSON
format and does\r\nnot changes the content that the user introduced
while editing. Once the\r\npipeline is saved, it will always retrieve
the parsed data.\r\n\r\nI've created a whole new editor instead of
modifying `XJsonEditor`\r\nbecause the original one is still in use in
the `Custom processor`. This\r\nis because I've created
[a\r\nlist](https://github.com/SoniaSanzV/kibana/blob/d7d5ecafa7dbae96fe52c2e37394520b6353bd92/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts#L151-L157)\r\nof
the processor fields that needs to be serialized
in\r\n`convertProcessorInternalToProcessor`. Since we don't know the
name of\r\nthe custom processor, we can't apply this workflow. I'm not
super happy\r\nwith the idea of adding manually the names of the
processors to a list.\r\nI would like to have something more agnostic
but I haven't come up with\r\na solution that allows me to do that
without breaking other fields. So,\r\nany suggestions are super
welcome!\r\n\r\n### How to test\r\nCreate one of the following
processors: Foreach, Grok, Inference, Redact\r\nor Script. In the JSON
field, add a JSON with both with and without\r\nescaped strings. While
you are editing the processor before saving the\r\npipeline, you should
see the processor as you typed it. In the `Show\r\nRequest` flyout, you
should see the properly parsed JSON.\r\n\r\nThe pipeline should save
with the correct parsed values and, once saved,\r\nif you click update,
you only will get parsed values.\r\n\r\n###
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/1f9681df-2fb4-4ed5-ac30-03f2937abfe9","sha":"8839894646451144a9534157c08cde18727aa240"}}]}]
BACKPORT-->

Co-authored-by: Sonia Sanz Vivas <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
Closes [elastic#175753](elastic#175753)

## Summary
When a user creates a pipeline with a processor that has an JSON editor
field [Foreach, Grok, Inference, Redact and Script], our editor convert
the input to XJSON. This can be confused to the user, who see their
input modified without understanding the reason. For that, this PR
creates a new editor that handles both XJSON and JSON format and does
not changes the content that the user introduced while editing. Once the
pipeline is saved, it will always retrieve the parsed data.

I've created a whole new editor instead of modifying `XJsonEditor`
because the original one is still in use in the `Custom processor`. This
is because I've created [a
list](https://github.com/SoniaSanzV/kibana/blob/d7d5ecafa7dbae96fe52c2e37394520b6353bd92/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts#L151-L157)
of the processor fields that needs to be serialized in
`convertProcessorInternalToProcessor`. Since we don't know the name of
the custom processor, we can't apply this workflow. I'm not super happy
with the idea of adding manually the names of the processors to a list.
I would like to have something more agnostic but I haven't come up with
a solution that allows me to do that without breaking other fields. So,
any suggestions are super welcome!

### How to test
Create one of the following processors: Foreach, Grok, Inference, Redact
or Script. In the JSON field, add a JSON with both with and without
escaped strings. While you are editing the processor before saving the
pipeline, you should see the processor as you typed it. In the `Show
Request` flyout, you should see the properly parsed JSON.

The pipeline should save with the correct parsed values and, once saved,
if you click update, you only will get parsed values.

### Demo


https://github.com/user-attachments/assets/1f9681df-2fb4-4ed5-ac30-03f2937abfe9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) Feature:Ingest Node Pipelines Ingest node pipelines management release_note:skip Skip the PR/issue when compiling release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kibana breaks JSON format of GROK patterns
4 participants