[Lists] Remove capture of Stack trace when registering server-side extension points (#179577)

## Summary

- Removes the capture of `Error.stack` when registering new Lists
server-side extension points. Calls to `Error.stack` are costly and was
contributing to kibana Plugin start up time
- Fixes #179405


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Paul Tavares 2024-04-01 10:37:38 -04:00 committed by GitHub
parent 6e23d50e7c
commit c8d16b958f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 5 additions and 28 deletions

View file

@ -36,14 +36,6 @@ describe('When using ExtensionPointStorage', () => {
expect(storageService.get('exceptionsListPreCreateItem')).toBeUndefined();
});
it('should capture `.stack` from where extension point was registered', () => {
storageService.add(preCreateExtensionPointMock);
expect(storageService.getExtensionRegistrationSource(preCreateExtensionPointMock)).toContain(
'extension_point_storage.test'
);
});
it('should clear() all extensions', () => {
storageService.clear();

View file

@ -17,7 +17,6 @@ import { ExtensionPointStorageClient } from './extension_point_storage_client';
export class ExtensionPointStorage implements ExtensionPointStorageInterface {
private readonly store = new Map<ExtensionPoint['type'], Set<ExtensionPoint>>();
private readonly registeredFrom = new Map<ExtensionPoint, string>();
constructor(private readonly logger: Logger) {}
@ -30,24 +29,11 @@ export class ExtensionPointStorage implements ExtensionPointStorageInterface {
if (extensionPointsForType) {
extensionPointsForType.add(extension);
// Capture stack trace from where this extension point was registered, so that it can be used when
// errors occur or callbacks don't return the expected result
const from = new Error('REGISTERED FROM:').stack ?? 'REGISTERED FROM: unknown';
this.registeredFrom.set(
extension,
from.substring(from.indexOf('REGISTERED FROM:')).concat('\n ----------------------')
);
}
}
clear(): void {
this.store.clear();
this.registeredFrom.clear();
}
getExtensionRegistrationSource(extensionPoint: ExtensionPoint): string | undefined {
return this.registeredFrom.get(extensionPoint);
}
get<T extends ExtensionPoint['type']>(

View file

@ -61,9 +61,6 @@ export class ExtensionPointStorageClient implements ExtensionPointStorageClientI
}
for (const externalExtension of externalExtensions) {
const extensionRegistrationSource =
this.storage.getExtensionRegistrationSource(externalExtension);
inputArgument = await externalExtension.callback({
context: callbackContext,
data: inputArgument as ExtensionPointCallbackDataArgument,
@ -76,7 +73,11 @@ export class ExtensionPointStorageClient implements ExtensionPointStorageClientI
if (validationError) {
this.logger.error(
new ExtensionPointError(
`Extension point for ${externalExtension.type} returned data that failed validation: ${extensionRegistrationSource}`,
`Extension point for ${
externalExtension.type
} returned data that failed validation: ${
validationError.message
}\nCallback src: ${externalExtension.callback.toString().substring(0, 300)}...`,
{
validationError,
}

View file

@ -200,8 +200,6 @@ export interface ExtensionPointStorageInterface {
clear(): void;
getExtensionRegistrationSource(extensionPoint: ExtensionPoint): string | undefined;
get<T extends ExtensionPoint['type']>(
extensionType: T
): Set<NarrowExtensionPointToType<T>> | undefined;