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

[core.logging] Fix calculating payload bytes for arrays and zlib streams. #92100

Merged
merged 9 commits into from
Mar 2, 2021

Conversation

lukeelmers
Copy link
Member

@lukeelmers lukeelmers commented Feb 19, 2021

Closes #90457

Summary

This PR fixes 2 bugs related to how we calculate payload bytes for the purposes of http response logging which was introduced in #87939:

  1. Ensures object responses that are arrays get calculated (in [core.logging] Fix issue where logs fail to calculate size of gunzip streams. #90353 we fixed a bug that was breaking Fleet, but forgot to consider array payload calculations)
  2. Ensures that we calculate payload sizes for the zlib streams which are used in Fleet and SIEM.

Example logs with calculated zlib payloads
Screen Shot 2021-02-19 at 4 01 17 PM

Reviewing / Testing

It is recommended to preview the diff with "hide whitespace changes" enabled.

You need to enable http.server.response logs to test this. Here's the config I've been testing with:

logging:
  events: # add this section to test legacy logs and compare
    request: "*"
    response: "*"

  appenders:
    console:
      type: console
      layout:
        type: pattern
        highlight: true
        pattern: "[%date][%level][%logger] %message"

  root:
    appenders: [console, default]
    level: warn

  loggers:
    - name: http.server.response
      appenders: [console]
      level: debug

@lukeelmers lukeelmers added bug Fixes for quality problems that affect the customer experience Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Feature:Logging v7.12.0 v7.13.0 auto-backport Deprecated - use backport:version if exact versions are needed labels Feb 19, 2021
@lukeelmers lukeelmers requested a review from a team as a code owner February 19, 2021 23:04
@lukeelmers lukeelmers self-assigned this Feb 19, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

return (
!isBoom(res) &&
res.variety === 'stream' &&
res.source === src &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need such a sophisticated check? Maybe duck-typing would be enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

Re-evaluating each of the typeguards, there's actually quite a bit of cleanup we can do -- for example, we're already checking isBoom earlier in the function so we don't need those checks duplicated in the typeguards, and testing reference equality of res.source and src isn't strictly necessary.

I went ahead and simplified each of them to take the source object and the variety string.

The one for zlib streams is still a little more complex as TS will complain if we just try to check variety === 'stream' && obj.bytesWritten, as obj is unknown, hence the typeof and null checks.

@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

@restrry This is ready for another look whenever you get the chance.

@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

@lukeelmers lukeelmers enabled auto-merge (squash) March 2, 2021 00:58
@lukeelmers
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
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
triggersActionsUi 1.6MB 1.5MB -23.9KB

Page load bundle

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

id before after diff
triggersActionsUi 104.0KB 104.1KB +82.0B
Unknown metric groups

async chunk count

id before after diff
triggersActionsUi 41 42 +1

History

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

cc @lukeelmers

@kibanamachine
Copy link
Contributor

💚 Backport successful

7.12 / #93284
7.x / #93285

Successful backport PRs will be merged automatically after passing CI.

@lukeelmers lukeelmers deleted the fix/payload-bytes branch March 2, 2021 18:40
kibanamachine added a commit that referenced this pull request Mar 2, 2021
…ams. (#92100) (#93284)

Co-authored-by: Luke Elmers <luke.elmers@elastic.co>
kibanamachine added a commit that referenced this pull request Mar 2, 2021
…ams. (#92100) (#93285)

Co-authored-by: Luke Elmers <luke.elmers@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed bug Fixes for quality problems that affect the customer experience Feature:Logging release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.12.0 v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core.logging] Request/Response logging cleanup tasks.
4 participants