-
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
[New platform] Support configuring request specific basePath #35951
Conversation
It's applied to identify incoming requests across New and Legacy platforms. We can rely on the value if want to attach additional information to incoming requests without mutating them.
💚 Build Succeeded |
💔 Build Failed |
} | ||
|
||
// should work only for KibanaRequest as soon as spaces migrate to NP | ||
private setBasePathFor(request: KibanaRequest | Request, basePath: string) { |
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 store basePath in WeakMap, where request.raw.req: IncomingMessage
is used as a key. Hapi re-uses request.raw.req
when we proxy request to LP, so it still can be used as a key to retrieve basePath from NP api
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.
Can I ask why we opt for a WeakMap instead of a Map for this cache?
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.
If we use ordinary Map it will lead to memory leaks, because Map keeps a reference to incoming request and it cannot be removed by GC. Using WeakMap
frees us from the obligation to control the allocated memory manually.
__dirname, | ||
'./__fixtures__/plugins/dummy_on_request' | ||
); | ||
const plugin = path.resolve(__dirname, './__fixtures__/plugins/dummy_on_request'); |
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.
TODO for myself: create an issue to cleanup tests. after #35297 we can use setup
/ start
contracts in tests and don't need to declare a plugin for this
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.
created issue #36256
retest |
💚 Build Succeeded |
} | ||
|
||
public getFilteredHeaders(headersToKeep: string[]) { | ||
return filterHeaders(this.headers, headersToKeep); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
public unstable_getIncomingMessage() { |
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 we want to expose it on a long distance, so I added prefix unstable_
Pinging @elastic/kibana-platform |
Pinging @elastic/kibana-security |
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.
Have some syntax notes and question.
registerRouter(router); | ||
|
||
await server.start(config); | ||
await supertest(innerServer.listener) |
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.
Can this be re-written to take advantage of the async function and removing the then
?
const response = await supertest(innerServer.listener).get('/').expect(200);
expect(response.body).toEqual({ key: path });
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.
yes, but in this case, the test suit is inconsistent from other tests in this file.
} | ||
|
||
// should work only for KibanaRequest as soon as spaces migrate to NP | ||
private setBasePathFor(request: KibanaRequest | Request, basePath: string) { |
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.
Can I ask why we opt for a WeakMap instead of a Map for this cache?
💚 Build Succeeded |
💚 Build Succeeded |
@eliperelman addressed |
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 with TODO
addressed.
…#35951) * expose IncomingMessage from KibanaRequest It's applied to identify incoming requests across New and Legacy platforms. We can rely on the value if want to attach additional information to incoming requests without mutating them. * support attaching basePath information to incoming requests * Support Url changing for incoming requests * add tests * use NP API in the legacy platform * relax KibanaRequest typings * check basePath cannot be set twice * address @eli comments * generate docs
…#36257) * expose IncomingMessage from KibanaRequest It's applied to identify incoming requests across New and Legacy platforms. We can rely on the value if want to attach additional information to incoming requests without mutating them. * support attaching basePath information to incoming requests * Support Url changing for incoming requests * add tests * use NP API in the legacy platform * relax KibanaRequest typings * check basePath cannot be set twice * address @eli comments * generate docs
Summary
With this PR http service in NP provides ability:
onRequest
interceptorBoth features are required to replace current Spaces functionality in legacy platform.
#35429 (comment)
@legrego
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 accessibilityFor maintainers