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

Migrate the optimizer mixin to core #94272

Merged

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Mar 10, 2021

Summary

Fix #77020

Migrate the legacy optimize mixin (/src/optimize) that is serving our webpack bundles to core.

Checklist

@pgayvallet pgayvallet changed the title Kbn 77020 migrate optimizer mixin Migrate the optimizer mixin to core Mar 10, 2021
@pgayvallet pgayvallet added Feature:Legacy Removal Issues related to removing legacy Kibana 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.13.0 chore labels Mar 10, 2021
Copy link
Contributor Author

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Self-review

Comment on lines +9 to +13
// 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';
Copy link
Contributor Author

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.

Comment on lines +60 to +68
[...uiPlugins.internal.entries()].forEach(([id, { publicTargetDir }]) => {
registerRouteForBundle(router, {
publicPath: `${serverBasePath}/${buildNum}/bundles/plugin/${id}/`,
routePath: `/${buildNum}/bundles/plugin/${id}/`,
bundlesPath: publicTargetDir,
fileHashCache,
isDist,
});
});
Copy link
Contributor Author

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.

Comment on lines +30 to +38
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') {
Copy link
Contributor Author

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.

Comment on lines -34 to 24

const promise = Rx.merge(
return Rx.merge(
Rx.fromEvent<Buffer>(read, 'data'),
Rx.fromEvent<Error>(read, 'error').pipe(
map((error) => {
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Comment on lines -24 to +29
setup(coreSetup: InternalCoreSetup) {
setup(coreSetup: InternalCoreSetup, uiPlugins: UiPlugins) {
Copy link
Contributor Author

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.

Comment on lines -68 to +65
// setup routes that serve the @kbn/optimizer output
optimizeMixin
loggingMixin
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting closer.

@pgayvallet pgayvallet marked this pull request as ready for review March 11, 2021 10:27
@pgayvallet pgayvallet requested review from a team as code owners March 11, 2021 10:27
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@joshdover joshdover left a 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';
Copy link
Contributor

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 🤦

Comment on lines -34 to 24

const promise = Rx.merge(
return Rx.merge(
Rx.fromEvent<Buffer>(read, 'data'),
Rx.fromEvent<Error>(read, 'error').pipe(
map((error) => {
Copy link
Contributor

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.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

@pgayvallet pgayvallet merged commit 25e586a into elastic:master Mar 17, 2021
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Mar 17, 2021
* 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
jloleysens added a commit that referenced this pull request Mar 17, 2021
…-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
pgayvallet added a commit that referenced this pull request Mar 17, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:Legacy Removal Issues related to removing legacy Kibana 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.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate optimize mixin to KP
5 participants