Skip to content

[CodeEditor] Add grok highlighting#159334

Merged
Dosant merged 3 commits intoelastic:mainfrom
Dosant:d/2023-06-08-code-editor-grok
Jun 13, 2023
Merged

[CodeEditor] Add grok highlighting#159334
Dosant merged 3 commits intoelastic:mainfrom
Dosant:d/2023-06-08-code-editor-grok

Conversation

@Dosant
Copy link
Copy Markdown
Contributor

@Dosant Dosant commented Jun 8, 2023

Summary

Close #155506

Screenshot 2023-06-12 at 17 11 18

I didn't introduce any custom colors here but just used built-in token types for highlighting (string for red and variable for blue)

@Dosant Dosant requested a review from sabarasaba June 8, 2023 16:15
@sabarasaba
Copy link
Copy Markdown
Member

Screenshot 2023-06-08 at 17 43 02 I didn't introduce any custom colors here but just used built-in token types for highlighting (`string` for red and `variable` for blue)

I think its good, the syntax is pretty minimal so its fine to keep it simple as you did!

From the original ace implementation, I didn't understand what this does, also couldn't understand it from grok docs. Is this important? :

{
token: (escapeToken /* regexToken */) => {
if (escapeToken) {
return ['grokEscape', 'grokEscaped'];
}
return 'grokRegex';
},
regex: '(\\\\)?([\\[\\]\\(\\)\\?\\:\\|])',
},

I'm a bit rusty with regexes but it seems like it matches any backslashes followed by square brackets, parentheses, question marks, colons, or vertical bars? I'm unsure what this is for, but perhaps @alisonelizabeth might have some idea 🤔

@Dosant Dosant added release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// labels Jun 9, 2023
@Dosant Dosant marked this pull request as ready for review June 9, 2023 14:02
@Dosant Dosant requested review from a team as code owners June 9, 2023 14:02
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

@alisonelizabeth
Copy link
Copy Markdown
Contributor

I think this is a good start. Thanks @Dosant!

Grok debugger has been around a long time and unfortunately I do not have much context into the original implementation. That said, I was able to track down #18572, where it looks like the syntax highlighting was implemented. There is a screenshot that shows the previous behavior.

@Dosant
Copy link
Copy Markdown
Contributor Author

Dosant commented Jun 12, 2023

@sabarasaba, @alisonelizabeth, thanks! so I think I understand what it is now:

first, there were the following CSS classes that added color (probably they were removed by mistake so highlighting stoped working on some point for ace)

  .ace_grokStart,
   .ace_grokEnd,
   .ace_grokSeparator,
   .ace_grokEscape {
     color: #999999; // euiColorMediumShade
   }

   .ace_grokPatternName {
     color: #017F75; // euiColorSecondary
   }

   .ace_grokFieldName,
   .ace_grokRegex {
     color: #0079A5; // euiColorPrimary
   }

   .ace_grokFieldType {
     color: #0079A5; // euiColorPrimary
     font-style: italic;
   }
 }

you can see that from

 { 
   token: (escapeToken /* regexToken */) => { 
     if (escapeToken) { 
       return ['grokEscape', 'grokEscaped']; 
     } 
     return 'grokRegex'; 
   }, 
   regex: '(\\\\)?([\\[\\]\\(\\)\\?\\:\\|])', 
 }, 

we highlighted with css only grokEscape and grokRegex, but not grokEscaped

so the idea was to highlight either grokEscape or grokRegex if it wasn't escaped. (not really sure what grokRegex is, looks like just one of the symbols in the list)

I'll try to repro with monaco highlighting

@Dosant
Copy link
Copy Markdown
Contributor Author

Dosant commented Jun 12, 2023

I think this should work as before in ace now including special symbols and escaping them (a bit different on colors and less variance, as I wanted to avoid adding custom themes):

Screenshot 2023-06-12 at 17 11 18

@sabarasaba, should be ready for review 👍

@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
kibanaReact 308 311 +3

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
kibanaReact 153 154 +1

Async chunks

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

id before after diff
grokdebugger 8.9KB 8.9KB -1.0B
kibanaReact 208.2KB 209.1KB +903.0B
total +902.0B

Page load bundle

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

id before after diff
kibanaReact 51.9KB 52.0KB +52.0B
Unknown metric groups

API count

id before after diff
kibanaReact 185 186 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 410 414 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 491 495 +4
total +6

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Copy Markdown
Member

@sabarasaba sabarasaba left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this @Dosant! Changes lgtm, tested locally 🚀

@Dosant Dosant merged commit e893133 into elastic:main Jun 13, 2023
@kibanamachine kibanamachine added v8.9.0 backport:skip This PR does not require backporting labels Jun 13, 2023
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jun 13, 2023
* main:
  [Lens] Add custom formatter within the Lens editor (elastic#158468)
  [Uptime] Hide app if no data is available (elastic#159118)
  [CodeEditor] Add grok highlighting (elastic#159334)
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jun 13, 2023
* main: (199 commits)
  [Lens] Add custom formatter within the Lens editor (elastic#158468)
  [Uptime] Hide app if no data is available (elastic#159118)
  [CodeEditor] Add grok highlighting (elastic#159334)
  Expose decoded cloudId components from the cloud plugin's contract (elastic#159442)
  [Profiling] Use collector and symbolizer integrations in the add data page (elastic#159481)
  [Infrastructure UI] Hosts View: Unified Search bar with auto-refresh enabled (elastic#157011)
  [APM] Add feature flag for not available apm schema (elastic#158911)
  [Lens] Remove deprecated componentWillReceiveProps usage (elastic#159502)
  [api-docs] 2023-06-13 Daily api_docs build (elastic#159536)
  [data views] Use versioned router for REST routes (elastic#158608)
  [maps] fix geo line source not loaded unless maps application is opened (elastic#159432)
  [Enterprise Search][Search application]Fix Create Api key url (elastic#159519)
  [Security Solution] Increase timeout for indexing hosts (elastic#159518)
  dashboard Reset button disable (elastic#159430)
  [Security Solution] Unskip Endpoint API tests after package fix (elastic#159484)
  [Synthetics] adjust alert timing (elastic#159511)
  [ResponseOps][rule registry] Remove usages of `refresh: true` (elastic#159252)
  Revert "Remove unused package (elastic#158597)"
  [Serverless] Adding config to disable authentication on task manager background worker utilization API (elastic#159505)
  Remove unused package (elastic#158597)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// v8.9.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Grok syntax highlighting in CodeEditor

7 participants