-
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
[Reporting/NP Migration] Remove server.expose of ExportTypeRegistry #50973
[Reporting/NP Migration] Remove server.expose of ExportTypeRegistry #50973
Conversation
Pinging @elastic/kibana-stack-services (Team:Stack Services) |
This comment has been minimized.
This comment has been minimized.
0365826
to
47efc80
Compare
This comment has been minimized.
This comment has been minimized.
47efc80
to
53320f1
Compare
This comment has been minimized.
This comment has been minimized.
53320f1
to
44166c6
Compare
This comment has been minimized.
This comment has been minimized.
0d7f588
to
446a9f8
Compare
This comment has been minimized.
This comment has been minimized.
446a9f8
to
723ab00
Compare
@@ -1,64 +0,0 @@ | |||
/* |
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.
Moved this out to replace server/lib/export_types_registry
@@ -1,22 +0,0 @@ | |||
/* |
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.
replaced all the export_type/server/index.ts
files with export_type/index.ts
} | ||
|
||
export const exportTypesRegistryFactory = oncePerServer(exportTypesRegistryFn); | ||
// FIXME: is this the best way to return a singleton? |
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.
Maybe there is no need to memoize this, since exportTypesRegistry
is consumed in 1 place
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.
Why not instanciate ExportTypesRegistry
in the module and export the singleton then? Maybe a little harder for tests though.
x-pack/legacy/plugins/reporting/export_types/printable_pdf/server/lib/generate_pdf.ts
Show resolved
Hide resolved
💚 Build Succeeded |
This comment has been minimized.
This comment has been minimized.
💚 Build Succeeded |
💚 Build Succeeded |
@elasticmachine merge upstream |
…tform-shim-part-iv
@elasticmachine merge upstream |
@@ -50,3 +50,9 @@ export const PNG_JOB_TYPE = 'PNG'; | |||
export const CSV_JOB_TYPE = 'csv'; | |||
export const CSV_FROM_SAVEDOBJECT_JOB_TYPE = 'csv_from_savedobject'; | |||
export const USES_HEADLESS_JOB_TYPES = [PDF_JOB_TYPE, PNG_JOB_TYPE]; | |||
|
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.
🙇
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
@elastic/kibana-platform would you be able to lend someone to give a 2nd review on this PR? As it has a lot of refactoring, there is some context required, but the main part of the changes are to support getting rid of our |
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.
Don't have all the functional context, but PR does what is described and it seems to be going in the right direction for NP migration.
Some comments:
export const LICENSE_TYPE_TRIAL = 'trial'; | ||
export const LICENSE_TYPE_BASIC = 'basic'; | ||
export const LICENSE_TYPE_STANDARD = 'standard'; | ||
export const LICENSE_TYPE_GOLD = 'gold'; | ||
export const LICENSE_TYPE_PLATINUM = 'platinum'; |
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.
Should probably use LicenseType
from x-pack/plugins/licensing/server
instead or redeclaring them
// => ExportTypeDefinition<T, U, V, W> | ||
|
||
export class ExportTypesRegistry { | ||
private _map: Map<string, ExportTypeDefinition<any, any, any, any>> = new Map(); |
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.
NIT: should probably be unknown
instead of any
} | ||
|
||
export const exportTypesRegistryFactory = oncePerServer(exportTypesRegistryFn); | ||
// FIXME: is this the best way to return a singleton? |
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.
Why not instanciate ExportTypesRegistry
in the module and export the singleton then? Maybe a little harder for tests though.
const config = server.config(); | ||
const DOWNLOAD_BASE_URL = config.get('server.basePath') + `${API_BASE_URL}/jobs/download`; |
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.
You could access this from NP with core.http.basePath.serverBasePath
instead of relying on the legacy config.
function handleError(exportTypeId: string, err: Error) { | ||
if (err instanceof esErrors['401']) { | ||
return boom.unauthorized(`Sorry, you aren't authenticated`); | ||
} | ||
if (err instanceof esErrors['403']) { | ||
return boom.forbidden(`Sorry, you are not authorized to create ${exportTypeId} reports`); | ||
} | ||
if (err instanceof esErrors['404']) { | ||
return boom.boomify(err, { statusCode: 404 }); | ||
} | ||
return err; | ||
} |
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.
Info for later: Boom errors are not handled by default by NP router. You will have to user router.handleLegacyErrors
when you'll migrate your routes (or use proper NP response errors)
Thanks for the insightful feedback, @pgayvallet ! I think your comments should come in as changes in forthcoming PRs |
…lastic#50973) * [Reporting/NPMigration] typescriptify ExportTypeRegistry, remove from server.expose * Minor routes registration cleanup * move the ETR test file * Re-pack the route registration, reduce LOC changes * add EnqueueJobFn type * Fix usage collector test * remove a throw error used for development/debugging * fix imports error * Fix execute job tests * wip test fixes * test fixes for real * fix more tests * fix diffs * Add TODOs about the ExportTypesRegistry.register unwrap the factory functions. * really make headlessbrowserdriver required as an execute job factory option * fix tests * Use constants for license type keywords
…50973) (#52813) * [Reporting/NPMigration] typescriptify ExportTypeRegistry, remove from server.expose * Minor routes registration cleanup * move the ETR test file * Re-pack the route registration, reduce LOC changes * add EnqueueJobFn type * Fix usage collector test * remove a throw error used for development/debugging * fix imports error * Fix execute job tests * wip test fixes * test fixes for real * fix more tests * fix diffs * Add TODOs about the ExportTypesRegistry.register unwrap the factory functions. * really make headlessbrowserdriver required as an execute job factory option * fix tests * Use constants for license type keywords
Summary
This PR prepares the Reporting plugin for New Platform further, by taking away the export type registry from being "exposed" on the server. Previously, this was done as a utility to access a singleton. Now, the code follows the traditional flow of passing down the object to modules that depend on it.
Some of the modules that depend on export type registry were loaded with
oncePerServer
, which made the exported modules forced to be functions that could only receive the server object as a parameter. Since that doesn't work with the main idea behind the code change, there are unrelated modules that had to change by no longer being loaded withoncePerServer
.This PR is related to the dependent PRs:
The main changes of this PR is to pass the
browserDriverFactory
andexportTypesRegistry
objects to the module that need them, instead of making those objects available throughout the plugin usingserver.expose
.Other cleanup-related work:
export_type/server/index.ts
files withexport_type/index.ts
. The new changes expose an export type definition object, which are imported by the export type registry class, and consumed in itsgetExportTypesRegistryFn
.register
function into a server function to have the export defs registered.common/export_types_registry
and moved its code toserver/lib/export_types_registry
server/lib
registry code would scan a directory for available export types. Now each export type definition is explicitly imported. The scan code is no longer needed and the registry code should be consolidated inserver/lib/
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibility