-
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
Migrate the optimizer mixin to core #94272
Migrate the optimizer mixin to core #94272
Conversation
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.
Self-review
// can't use fs/promises when working with streams using file descriptors | ||
// see https://github.com/nodejs/node/issues/35862 | ||
|
||
import Fs from 'fs'; | ||
import { promisify } from 'util'; |
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.
Spent one hour trying to properly use fs/promises
with createReadStream
, then I had to fall back to promisify
as it was in legacy.
TIL: promisified fs are not the exact same as the new APIs provided by fs/promises
.
[...uiPlugins.internal.entries()].forEach(([id, { publicTargetDir }]) => { | ||
registerRouteForBundle(router, { | ||
publicPath: `${serverBasePath}/${buildNum}/bundles/plugin/${id}/`, | ||
routePath: `/${buildNum}/bundles/plugin/${id}/`, | ||
bundlesPath: publicTargetDir, | ||
fileHashCache, | ||
isDist, | ||
}); | ||
}); |
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.
We could probably optimize this a little to have a single route registered to serve all plugins bundle. I didn't bother, as it created divergence in the underlying registerRouteForBundle
between plugins and non-plugins bundles, and just introduced more complexity, which isn't worth it ihmo.
export async function selectCompressedFile(acceptEncodingHeader: string | undefined, path: string) { | ||
let fd: number | undefined; | ||
let fileEncoding: 'gzip' | 'br' | undefined; | ||
const ext = extname(path); | ||
|
||
const supportedEncodings = Accept.encodings(acceptEncodingHeader, ['br', 'gzip']); | ||
|
||
// do not bother trying to look compressed versions for anything else than js or css files | ||
if (ext === '.js' || ext === '.css') { |
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.
I did not unit test this specific file, because we would just be mocking the filesystem APIs and the testing process would be tedious for little value. This is covered both by integration and FTR tests anyway.
|
||
const promise = Rx.merge( | ||
return Rx.merge( | ||
Rx.fromEvent<Buffer>(read, 'data'), | ||
Rx.fromEvent<Error>(read, 'error').pipe( | ||
map((error) => { |
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.
Not sure of the value of using an observable approach to generate the hash tbh, but it's working, so I kept the implementation as it was in legacy.
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'm sure this creates 100s of RxJs objects, but guess fine for now.
setup(coreSetup: InternalCoreSetup) { | ||
setup(coreSetup: InternalCoreSetup, uiPlugins: UiPlugins) { |
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.
We need the uiPlugins
definition to register the bundle routes, so I had to add it to the CoreApp.setup
parameters, as it's not available from the setup contract.
// setup routes that serve the @kbn/optimizer output | ||
optimizeMixin | ||
loggingMixin |
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.
Getting closer.
Pinging @elastic/kibana-core (Team:Core) |
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.
LGTM
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.
Looks great. Tested locally and everything seemed to work well 👍
@@ -6,4 +6,4 @@ | |||
* Side Public License, v 1. | |||
*/ | |||
|
|||
export { optimizeMixin } from './optimize_mixin'; | |||
module.exports = 'GZIP-CHUNK'; |
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.
Git thinks this is a rename, sigh 🤦
|
||
const promise = Rx.merge( | ||
return Rx.merge( | ||
Rx.fromEvent<Buffer>(read, 'data'), | ||
Rx.fromEvent<Error>(read, 'error').pipe( | ||
map((error) => { |
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'm sure this creates 100s of RxJs objects, but guess fine for now.
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
* migrate optimizer mixin to core apps * fix core_app tests * add integration tests, extract selectCompressedFile * add CoreApp unit test * more unit tests * unit tests for bundle_route * more unit tests * remove /src/optimize/ from codeowners * fix case * NIT # Conflicts: # .github/CODEOWNERS
…-action * 'master' of github.com:elastic/kibana: (44 commits) Migrate the optimizer mixin to core (#94272) Replace EuiCodeBlock with JsonCodeEditor in DiscoverGrid (#92442) [ML] Anomaly Detection: Migrate validation messages links to use docLinks. (#94568) [Lists][Exceptions] - Adding basic linting, i18n and storybook support (#94772) [Fleet] Add test/fix for invalid/missing ids in bulk agent reassign (#94632) [Security Solution] [Cases] Move create page components and dependencies to Cases (#94444) [ML] Data Frame Analytics accessibility tests: fix flaky outlier creation test (#94735) [Security Solutions] Remove commented out old linter rules (#94753) [App Search] Role mappings migration part 2 (#94461) [CI] Update Backport action inputs to match updated ones (#94721) [chore] Remove the infra team from CODEOWNERS (#94740) [Connectors UI] Make UI use new connector APIs (#94180) [ML] Use indices options in anomaly detection job wizards (#91830) Remove `string` as a valid registry var type value (#94174) [Alerts] Replaces legacy es client with the ElasticsearchClient for alerts and triggers_actions_ui plugins. (#93364) [Reporting-CSV Export] Re-write CSV Export using SearchSource (#88303) chore(NA): upgrade bazel rules nodejs to v3.2.2 (#94726) [APM] Settings: Update layout and update/add descriptions (#94398) skip flaky suite (#94666) [XY axis] Integrates legend color picker with the eui palette (#90589) ... # Conflicts: # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/cold_phase/cold_phase.tsx # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared_fields/searchable_snapshot_field/searchable_snapshot_field.tsx # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/constants.ts # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.tsx # x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/configuration_context.tsx # x-pack/plugins/index_lifecycle_management/public/shared_imports.ts
* migrate optimizer mixin to core apps * fix core_app tests * add integration tests, extract selectCompressedFile * add CoreApp unit test * more unit tests * unit tests for bundle_route * more unit tests * remove /src/optimize/ from codeowners * fix case * NIT # Conflicts: # .github/CODEOWNERS
Summary
Fix #77020
Migrate the legacy optimize mixin (
/src/optimize
) that is serving our webpack bundles to core.Checklist