Skip to content

[Logs UI] Custom rendering for <LogStream /> columns#85148

Merged
afgomez merged 11 commits intoelastic:masterfrom
afgomez:82748-log-stream-custom-column-rendering
Dec 10, 2020
Merged

[Logs UI] Custom rendering for <LogStream /> columns#85148
afgomez merged 11 commits intoelastic:masterfrom
afgomez:82748-log-stream-custom-column-rendering

Conversation

@afgomez
Copy link
Copy Markdown
Contributor

@afgomez afgomez commented Dec 7, 2020

Summary

Closes #82748

This PR adds rendering options to the <LogStream/> column definition. This will allow consumers of the API to modify how the columns render.

Example

We have applied the following configuration to the page_view_log_in_context.tsx

<LogStream
  sourceId={sourceId}
  startTimestamp={startTimestamp}
  endTimestamp={endTimestamp}
  query={contextQuery}
  center={contextEntry.cursor}
  highlight={contextEntry.id}
  height="100%"
  columns={[
    {
      type: 'timestamp',
      width: 100,
      header: 'When?',
      render: (timestamp) => new Intl.DateTimeFormat('en-GB').format(timestamp),
    },
    {
      type: 'field',
      field: 'host.name',
      width: '150px',
      header: 'Where?',
      render: (value) =>
        typeof value === 'string' ? value.replace(/.local$/, '.🏠') : value,
    },
    {
      type: 'field',
      field: 'log.level',
      width: 32,
      header: false,
      render: (logLevel) => {
        switch (logLevel) {
          case 'warn':
            return '⚠️';
          case 'error':
            return '⛔️';
          case 'debug':
            return '🐞';
          default:
            return 'ℹ️';
        }
      },
    },
    {
      type: 'message',
      header: 'What?',
      render: (message) => {
        let newMessage = message.startsWith('Entered') ? `➡️ ${message}` : message;
        newMessage = newMessage.replace('SIGKILL', '☠️');
        newMessage = newMessage.replace('disconnect', '️🔌');
        newMessage = newMessage.replace('map', '🗺');
        return newMessage;
      },
    },
  ]}
/>

This is the result:

Screenshot 2020-12-07 at 16 24 10

@afgomez afgomez added v8.0.0 Feature:Logs UI Logs UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services release_note:skip Skip the PR/issue when compiling release notes v7.11.0 Epic:Shared Logs Component labels Dec 7, 2020
@afgomez afgomez added this to the Logs UI 7.11 milestone Dec 7, 2020
@afgomez afgomez requested a review from a team as a code owner December 7, 2020 15:31
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

@weltenwort weltenwort self-requested a review December 9, 2020 10:28
@afgomez
Copy link
Copy Markdown
Contributor Author

afgomez commented Dec 9, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
infra 1084 1085 +1

Async chunks

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

id before after diff
infra 2.7MB 2.7MB +3.8KB

Distributable file count

id before after diff
default 46981 47741 +760

History

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

Copy link
Copy Markdown
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

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

I was able to make use of the new feature by modifying the way agent logs are rendered on first try. Well done on the implementation and documentation, which are both very readable. 👍

As I said before, a storybook story that showcases it would make reviewing new features such as these even easier.

return messageSegment.constant;
}
if (isFieldSegment(messageSegment)) {
return messageSegment.value.toString();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💭 This might make messages with complex values impossible to render correctly. But that's hard to avoid short of exposing the segment abstraction to the render() method.

What do you think about passing the constants and unstringified values as an array instead? Would that complicate the API too much?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you remember on the top of your head any cases where one of the parts is a complex object? (Otherwise I will check the message formation rules myself tomorrow).

An option can be to test for the type of the value, and if it's anything other than a string use JSON.stringify() on it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I scanned all the test cases for the custom message formatters but didn't find anything where a complex field value was embedded in the message. 🤷 So maybe my concern was not justified.

@afgomez afgomez merged commit 4778365 into elastic:master Dec 10, 2020
@afgomez afgomez deleted the 82748-log-stream-custom-column-rendering branch December 10, 2020 16:19
afgomez pushed a commit that referenced this pull request Dec 10, 2020
…#85598)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Logs UI Logs UI feature release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.11.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Logs UI] Custom column rendering in the shared <LogStream /> component

4 participants