Skip to content

Commit a8772dd

Browse files
committed
Merge branch 'master' of https://github.com/elastic/kibana into threadpool_rejection_alert
2 parents 7d2a33d + 995111a commit a8772dd

File tree

153 files changed

+2543
-704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+2543
-704
lines changed

docs/development/core/server/kibana-plugin-core-server.kibanarequest.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export declare class KibanaRequest<Params = unknown, Query = unknown, Body = unk
3030
| [isSystemRequest](./kibana-plugin-core-server.kibanarequest.issystemrequest.md) | | <code>boolean</code> | Whether or not the request is a "system request" rather than an application-level request. Can be set on the client using the <code>HttpFetchOptions#asSystemRequest</code> option. |
3131
| [params](./kibana-plugin-core-server.kibanarequest.params.md) | | <code>Params</code> | |
3232
| [query](./kibana-plugin-core-server.kibanarequest.query.md) | | <code>Query</code> | |
33-
| [rewrittenUrl](./kibana-plugin-core-server.kibanarequest.rewrittenurl.md) | | <code>Url</code> | URL rewritten in onPreRouting request interceptor. |
33+
| [rewrittenUrl](./kibana-plugin-core-server.kibanarequest.rewrittenurl.md) | | <code>URL</code> | URL rewritten in onPreRouting request interceptor. |
3434
| [route](./kibana-plugin-core-server.kibanarequest.route.md) | | <code>RecursiveReadonly&lt;KibanaRequestRoute&lt;Method&gt;&gt;</code> | matched route details |
3535
| [socket](./kibana-plugin-core-server.kibanarequest.socket.md) | | <code>IKibanaSocket</code> | [IKibanaSocket](./kibana-plugin-core-server.ikibanasocket.md) |
36-
| [url](./kibana-plugin-core-server.kibanarequest.url.md) | | <code>Url</code> | a WHATWG URL standard object. |
36+
| [url](./kibana-plugin-core-server.kibanarequest.url.md) | | <code>URL</code> | a WHATWG URL standard object. |
3737
| [uuid](./kibana-plugin-core-server.kibanarequest.uuid.md) | | <code>string</code> | A UUID to identify this request. |
3838

docs/development/core/server/kibana-plugin-core-server.kibanarequest.rewrittenurl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ URL rewritten in onPreRouting request interceptor.
99
<b>Signature:</b>
1010

1111
```typescript
12-
readonly rewrittenUrl?: Url;
12+
readonly rewrittenUrl?: URL;
1313
```

docs/development/core/server/kibana-plugin-core-server.kibanarequest.url.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ a WHATWG URL standard object.
99
<b>Signature:</b>
1010

1111
```typescript
12-
readonly url: Url;
12+
readonly url: URL;
1313
```

docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.reactexpressionrenderer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<b>Signature:</b>
88

99
```typescript
10-
ReactExpressionRenderer: ({ className, dataAttrs, padding, renderError, expression, onEvent, reload$, ...expressionLoaderOptions }: ReactExpressionRendererProps) => JSX.Element
10+
ReactExpressionRenderer: ({ className, dataAttrs, padding, renderError, expression, onEvent, reload$, debounce, ...expressionLoaderOptions }: ReactExpressionRendererProps) => JSX.Element
1111
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) &gt; [ReactExpressionRendererProps](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.md) &gt; [debounce](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.debounce.md)
4+
5+
## ReactExpressionRendererProps.debounce property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
debounce?: number;
11+
```

docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ReactExpressionRendererProps extends IExpressionLoaderParams
1616
| --- | --- | --- |
1717
| [className](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.classname.md) | <code>string</code> | |
1818
| [dataAttrs](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.dataattrs.md) | <code>string[]</code> | |
19+
| [debounce](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.debounce.md) | <code>number</code> | |
1920
| [expression](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.expression.md) | <code>string &#124; ExpressionAstExpression</code> | |
2021
| [onEvent](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.onevent.md) | <code>(event: ExpressionRendererEvent) =&gt; void</code> | |
2122
| [padding](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.padding.md) | <code>'xs' &#124; 's' &#124; 'm' &#124; 'l' &#124; 'xl'</code> | |

src/core/server/http/http_server.mocks.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
import { parse as parseUrl } from 'url';
1920
import { Request } from 'hapi';
2021
import { merge } from 'lodash';
2122
import { Socket } from 'net';
@@ -72,6 +73,7 @@ function createKibanaRequestMock<P = any, Q = any, B = any>({
7273
auth = { isAuthenticated: true },
7374
}: RequestFixtureOptions<P, Q, B> = {}) {
7475
const queryString = stringify(query, { sort: false });
76+
const url = parseUrl(`${path}${queryString ? `?${queryString}` : ''}`);
7577

7678
return KibanaRequest.from<P, Q, B>(
7779
createRawRequestMock({
@@ -83,12 +85,7 @@ function createKibanaRequestMock<P = any, Q = any, B = any>({
8385
payload: body,
8486
path,
8587
method,
86-
url: {
87-
path,
88-
pathname: path,
89-
query: queryString,
90-
search: queryString ? `?${queryString}` : queryString,
91-
},
88+
url,
9289
route: {
9390
settings: { tags: routeTags, auth: routeAuthRequired, app: kibanaRouteOptions },
9491
},
@@ -121,6 +118,11 @@ interface DeepPartialArray<T> extends Array<DeepPartial<T>> {}
121118
type DeepPartialObject<T> = { [P in keyof T]+?: DeepPartial<T[P]> };
122119

123120
function createRawRequestMock(customization: DeepPartial<Request> = {}) {
121+
const pathname = customization.url?.pathname || '/';
122+
const path = `${pathname}${customization.url?.search || ''}`;
123+
const url = Object.assign({ pathname, path, href: path }, customization.url);
124+
125+
// @ts-expect-error _core isn't supposed to be accessed - remove once we upgrade to hapi v18
124126
return merge(
125127
{},
126128
{
@@ -129,17 +131,21 @@ function createRawRequestMock(customization: DeepPartial<Request> = {}) {
129131
isAuthenticated: true,
130132
},
131133
headers: {},
132-
path: '/',
134+
path,
133135
route: { settings: {} },
134-
url: {
135-
href: '/',
136-
},
136+
url,
137137
raw: {
138138
req: {
139-
url: '/',
139+
url: path,
140140
socket: {},
141141
},
142142
},
143+
// TODO: Remove once we upgrade to hapi v18
144+
_core: {
145+
info: {
146+
uri: 'http://localhost',
147+
},
148+
},
143149
},
144150
customization
145151
) as Request;

src/core/server/http/http_server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class HttpServer {
271271
}
272272

273273
this.registerOnPreRouting((request, response, toolkit) => {
274-
const oldUrl = request.url.href!;
274+
const oldUrl = request.url.pathname + request.url.search;
275275
const newURL = basePathService.remove(oldUrl);
276276
const shouldRedirect = newURL !== oldUrl;
277277
if (shouldRedirect) {

src/core/server/http/integration_tests/lifecycle.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ describe('OnPreRouting', () => {
124124
const router = createRouter('/');
125125

126126
router.get({ path: '/login', validate: false }, (context, req, res) => {
127-
return res.ok({ body: { rewrittenUrl: req.rewrittenUrl?.path } });
127+
return res.ok({
128+
body: {
129+
rewrittenUrl: req.rewrittenUrl
130+
? `${req.rewrittenUrl.pathname}${req.rewrittenUrl.search}`
131+
: undefined,
132+
},
133+
});
128134
});
129135

130136
registerOnPreRouting((req, res, t) => t.rewriteUrl('/login'));
@@ -143,7 +149,13 @@ describe('OnPreRouting', () => {
143149
const router = createRouter('/');
144150

145151
router.get({ path: '/reroute-2', validate: false }, (context, req, res) => {
146-
return res.ok({ body: { rewrittenUrl: req.rewrittenUrl?.path } });
152+
return res.ok({
153+
body: {
154+
rewrittenUrl: req.rewrittenUrl
155+
? `${req.rewrittenUrl.pathname}${req.rewrittenUrl.search}`
156+
: undefined,
157+
},
158+
});
147159
});
148160

149161
registerOnPreRouting((req, res, t) => t.rewriteUrl('/reroute-1'));
@@ -163,7 +175,13 @@ describe('OnPreRouting', () => {
163175
const router = createRouter('/');
164176

165177
router.get({ path: '/login', validate: false }, (context, req, res) => {
166-
return res.ok({ body: { rewrittenUrl: req.rewrittenUrl?.path } });
178+
return res.ok({
179+
body: {
180+
rewrittenUrl: req.rewrittenUrl
181+
? `${req.rewrittenUrl.pathname}${req.rewrittenUrl.search}`
182+
: undefined,
183+
},
184+
});
167185
});
168186

169187
registerOnPreRouting((req, res, t) => t.next());

src/core/server/http/lifecycle/on_pre_routing.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* under the License.
1818
*/
1919

20+
import { URL } from 'url';
2021
import { Lifecycle, Request, ResponseToolkit as HapiResponseToolkit } from 'hapi';
2122
import { Logger } from '../../logging';
2223
import {
@@ -110,10 +111,30 @@ export function adoptToHapiOnRequest(fn: OnPreRoutingHandler, log: Logger) {
110111

111112
if (preRoutingResult.isRewriteUrl(result)) {
112113
const appState = request.app as KibanaRequestState;
113-
appState.rewrittenUrl = appState.rewrittenUrl ?? request.url;
114+
appState.rewrittenUrl =
115+
// @ts-expect-error request._core isn't supposed to be accessed - remove once we upgrade to hapi v18
116+
appState.rewrittenUrl ?? new URL(request.url.href!, request._core.info.uri);
114117

115118
const { url } = result;
116-
request.setUrl(url);
119+
120+
// TODO: Remove once we upgrade to Node.js 12!
121+
//
122+
// Warning: The following for-loop took 10 days to write, and is a hack
123+
// to force V8 to make a copy of the string in memory.
124+
//
125+
// The reason why we need this is because of what appears to be a bug
126+
// in V8 that caused some URL paths to not be routed correctly once
127+
// `request.setUrl` was called with the path.
128+
//
129+
// The details can be seen in this discussion on Twitter:
130+
// https://twitter.com/wa7son/status/1319992632366518277
131+
let urlCopy = '';
132+
for (let i = 0; i < url.length; i++) {
133+
urlCopy += url[i];
134+
}
135+
136+
request.setUrl(urlCopy);
137+
117138
// We should update raw request as well since it can be proxied to the old platform
118139
request.raw.req.url = url;
119140
return responseToolkit.continue;

0 commit comments

Comments
 (0)