Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/elastic/kibana into threa…
Browse files Browse the repository at this point in the history
…dpool_rejection_alert
  • Loading branch information
igoristic committed Oct 29, 2020
2 parents 7d2a33d + 995111a commit a8772dd
Show file tree
Hide file tree
Showing 153 changed files with 2,543 additions and 704 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export declare class KibanaRequest<Params = unknown, Query = unknown, Body = unk
| [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. |
| [params](./kibana-plugin-core-server.kibanarequest.params.md) | | <code>Params</code> | |
| [query](./kibana-plugin-core-server.kibanarequest.query.md) | | <code>Query</code> | |
| [rewrittenUrl](./kibana-plugin-core-server.kibanarequest.rewrittenurl.md) | | <code>Url</code> | URL rewritten in onPreRouting request interceptor. |
| [rewrittenUrl](./kibana-plugin-core-server.kibanarequest.rewrittenurl.md) | | <code>URL</code> | URL rewritten in onPreRouting request interceptor. |
| [route](./kibana-plugin-core-server.kibanarequest.route.md) | | <code>RecursiveReadonly&lt;KibanaRequestRoute&lt;Method&gt;&gt;</code> | matched route details |
| [socket](./kibana-plugin-core-server.kibanarequest.socket.md) | | <code>IKibanaSocket</code> | [IKibanaSocket](./kibana-plugin-core-server.ikibanasocket.md) |
| [url](./kibana-plugin-core-server.kibanarequest.url.md) | | <code>Url</code> | a WHATWG URL standard object. |
| [url](./kibana-plugin-core-server.kibanarequest.url.md) | | <code>URL</code> | a WHATWG URL standard object. |
| [uuid](./kibana-plugin-core-server.kibanarequest.uuid.md) | | <code>string</code> | A UUID to identify this request. |

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ URL rewritten in onPreRouting request interceptor.
<b>Signature:</b>

```typescript
readonly rewrittenUrl?: Url;
readonly rewrittenUrl?: URL;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ a WHATWG URL standard object.
<b>Signature:</b>

```typescript
readonly url: Url;
readonly url: URL;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
ReactExpressionRenderer: ({ className, dataAttrs, padding, renderError, expression, onEvent, reload$, ...expressionLoaderOptions }: ReactExpressionRendererProps) => JSX.Element
ReactExpressionRenderer: ({ className, dataAttrs, padding, renderError, expression, onEvent, reload$, debounce, ...expressionLoaderOptions }: ReactExpressionRendererProps) => JSX.Element
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[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)

## ReactExpressionRendererProps.debounce property

<b>Signature:</b>

```typescript
debounce?: number;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ReactExpressionRendererProps extends IExpressionLoaderParams
| --- | --- | --- |
| [className](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.classname.md) | <code>string</code> | |
| [dataAttrs](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.dataattrs.md) | <code>string[]</code> | |
| [debounce](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.debounce.md) | <code>number</code> | |
| [expression](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.expression.md) | <code>string &#124; ExpressionAstExpression</code> | |
| [onEvent](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.onevent.md) | <code>(event: ExpressionRendererEvent) =&gt; void</code> | |
| [padding](./kibana-plugin-plugins-expressions-public.reactexpressionrendererprops.padding.md) | <code>'xs' &#124; 's' &#124; 'm' &#124; 'l' &#124; 'xl'</code> | |
Expand Down
28 changes: 17 additions & 11 deletions src/core/server/http/http_server.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { parse as parseUrl } from 'url';
import { Request } from 'hapi';
import { merge } from 'lodash';
import { Socket } from 'net';
Expand Down Expand Up @@ -72,6 +73,7 @@ function createKibanaRequestMock<P = any, Q = any, B = any>({
auth = { isAuthenticated: true },
}: RequestFixtureOptions<P, Q, B> = {}) {
const queryString = stringify(query, { sort: false });
const url = parseUrl(`${path}${queryString ? `?${queryString}` : ''}`);

return KibanaRequest.from<P, Q, B>(
createRawRequestMock({
Expand All @@ -83,12 +85,7 @@ function createKibanaRequestMock<P = any, Q = any, B = any>({
payload: body,
path,
method,
url: {
path,
pathname: path,
query: queryString,
search: queryString ? `?${queryString}` : queryString,
},
url,
route: {
settings: { tags: routeTags, auth: routeAuthRequired, app: kibanaRouteOptions },
},
Expand Down Expand Up @@ -121,6 +118,11 @@ interface DeepPartialArray<T> extends Array<DeepPartial<T>> {}
type DeepPartialObject<T> = { [P in keyof T]+?: DeepPartial<T[P]> };

function createRawRequestMock(customization: DeepPartial<Request> = {}) {
const pathname = customization.url?.pathname || '/';
const path = `${pathname}${customization.url?.search || ''}`;
const url = Object.assign({ pathname, path, href: path }, customization.url);

// @ts-expect-error _core isn't supposed to be accessed - remove once we upgrade to hapi v18
return merge(
{},
{
Expand All @@ -129,17 +131,21 @@ function createRawRequestMock(customization: DeepPartial<Request> = {}) {
isAuthenticated: true,
},
headers: {},
path: '/',
path,
route: { settings: {} },
url: {
href: '/',
},
url,
raw: {
req: {
url: '/',
url: path,
socket: {},
},
},
// TODO: Remove once we upgrade to hapi v18
_core: {
info: {
uri: 'http://localhost',
},
},
},
customization
) as Request;
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class HttpServer {
}

this.registerOnPreRouting((request, response, toolkit) => {
const oldUrl = request.url.href!;
const oldUrl = request.url.pathname + request.url.search;
const newURL = basePathService.remove(oldUrl);
const shouldRedirect = newURL !== oldUrl;
if (shouldRedirect) {
Expand Down
24 changes: 21 additions & 3 deletions src/core/server/http/integration_tests/lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ describe('OnPreRouting', () => {
const router = createRouter('/');

router.get({ path: '/login', validate: false }, (context, req, res) => {
return res.ok({ body: { rewrittenUrl: req.rewrittenUrl?.path } });
return res.ok({
body: {
rewrittenUrl: req.rewrittenUrl
? `${req.rewrittenUrl.pathname}${req.rewrittenUrl.search}`
: undefined,
},
});
});

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

router.get({ path: '/reroute-2', validate: false }, (context, req, res) => {
return res.ok({ body: { rewrittenUrl: req.rewrittenUrl?.path } });
return res.ok({
body: {
rewrittenUrl: req.rewrittenUrl
? `${req.rewrittenUrl.pathname}${req.rewrittenUrl.search}`
: undefined,
},
});
});

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

router.get({ path: '/login', validate: false }, (context, req, res) => {
return res.ok({ body: { rewrittenUrl: req.rewrittenUrl?.path } });
return res.ok({
body: {
rewrittenUrl: req.rewrittenUrl
? `${req.rewrittenUrl.pathname}${req.rewrittenUrl.search}`
: undefined,
},
});
});

registerOnPreRouting((req, res, t) => t.next());
Expand Down
25 changes: 23 additions & 2 deletions src/core/server/http/lifecycle/on_pre_routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

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

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

const { url } = result;
request.setUrl(url);

// TODO: Remove once we upgrade to Node.js 12!
//
// Warning: The following for-loop took 10 days to write, and is a hack
// to force V8 to make a copy of the string in memory.
//
// The reason why we need this is because of what appears to be a bug
// in V8 that caused some URL paths to not be routed correctly once
// `request.setUrl` was called with the path.
//
// The details can be seen in this discussion on Twitter:
// https://twitter.com/wa7son/status/1319992632366518277
let urlCopy = '';
for (let i = 0; i < url.length; i++) {
urlCopy += url[i];
}

request.setUrl(urlCopy);

// We should update raw request as well since it can be proxied to the old platform
request.raw.req.url = url;
return responseToolkit.continue;
Expand Down
15 changes: 8 additions & 7 deletions src/core/server/http/router/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Url } from 'url';
import { URL } from 'url';
import uuid from 'uuid';
import { Request, RouteOptionsApp, ApplicationState } from 'hapi';
import { Observable, fromEvent, merge } from 'rxjs';
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface KibanaRouteOptions extends RouteOptionsApp {
export interface KibanaRequestState extends ApplicationState {
requestId: string;
requestUuid: string;
rewrittenUrl?: Url;
rewrittenUrl?: URL;
}

/**
Expand Down Expand Up @@ -163,7 +163,7 @@ export class KibanaRequest<
*/
public readonly uuid: string;
/** a WHATWG URL standard object. */
public readonly url: Url;
public readonly url: URL;
/** matched route details */
public readonly route: RecursiveReadonly<KibanaRequestRoute<Method>>;
/**
Expand All @@ -190,7 +190,7 @@ export class KibanaRequest<
/**
* URL rewritten in onPreRouting request interceptor.
*/
public readonly rewrittenUrl?: Url;
public readonly rewrittenUrl?: URL;

/** @internal */
protected readonly [requestSymbol]: Request;
Expand All @@ -212,7 +212,8 @@ export class KibanaRequest<
this.uuid = appState?.requestUuid ?? uuid.v4();
this.rewrittenUrl = appState?.rewrittenUrl;

this.url = request.url;
// @ts-expect-error request._core isn't supposed to be accessed - remove once we upgrade to hapi v18
this.url = new URL(request.url.href!, request._core.info.uri);
this.headers = deepFreeze({ ...request.headers });
this.isSystemRequest =
request.headers['kbn-system-request'] === 'true' ||
Expand Down Expand Up @@ -304,8 +305,8 @@ export class KibanaRequest<
if (authOptions === false) return false;
throw new Error(
`unexpected authentication options: ${JSON.stringify(authOptions)} for route: ${
this.url.href
}`
this.url.pathname
}${this.url.search}`
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ import { Type } from '@kbn/config-schema';
import { TypeOf } from '@kbn/config-schema';
import { UpdateDocumentByQueryParams } from 'elasticsearch';
import { UpdateDocumentParams } from 'elasticsearch';
import { Url } from 'url';
import { URL } from 'url';

// @public
export interface AppCategory {
Expand Down Expand Up @@ -1007,11 +1007,11 @@ export class KibanaRequest<Params = unknown, Query = unknown, Body = unknown, Me
readonly params: Params;
// (undocumented)
readonly query: Query;
readonly rewrittenUrl?: Url;
readonly rewrittenUrl?: URL;
readonly route: RecursiveReadonly<KibanaRequestRoute<Method>>;
// (undocumented)
readonly socket: IKibanaSocket;
readonly url: Url;
readonly url: URL;
readonly uuid: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ set_chmod() {
chmod -f 660 ${KBN_PATH_CONF}/kibana.yml || true
chmod -f 2750 <%= dataDir %> || true
chmod -f 2750 ${KBN_PATH_CONF} || true
chmod -f 2750 <%= logDir %> || true
}

set_chown() {
chown <%= user %>:<%= group %> <%= logDir %>
chown -R <%= user %>:<%= group %> <%= dataDir %>
chown -R root:<%= group %> ${KBN_PATH_CONF}
}

set_access() {
setup() {
[ ! -d "<%= logDir %>" ] && mkdir "<%= logDir %>"
set_chmod
set_chown
}
Expand All @@ -35,7 +38,7 @@ case $1 in
IS_UPGRADE=true
fi

set_access
setup
;;
abort-deconfigure|abort-upgrade|abort-remove)
;;
Expand All @@ -55,7 +58,7 @@ case $1 in
IS_UPGRADE=true
fi

set_access
setup
;;

*)
Expand Down
2 changes: 2 additions & 0 deletions src/dev/build/tasks/os_packages/run_fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export async function runFpm(
`pluginsDir=/usr/share/kibana/plugins`,
'--template-value',
`dataDir=/var/lib/kibana`,
'--template-value',
`logDir=/var/log/kibana`,

// config and data directories are copied to /usr/share and /var/lib
// below, so exclude them from the main package source located in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Environment=KBN_PATH_CONF=/etc/kibana
EnvironmentFile=-/etc/default/kibana
EnvironmentFile=-/etc/sysconfig/kibana

ExecStart=/usr/share/kibana/bin/kibana
ExecStart=/usr/share/kibana/bin/kibana --logging.dest="/var/log/kibana/kibana.log"

Restart=on-failure
RestartSec=3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fi

name=kibana
program=/usr/share/kibana/bin/kibana
args="--logging.dest=/var/log/kibana/kibana.log"
pidfile="/var/run/kibana/$name.pid"

[ -r /etc/default/$name ] && . /etc/default/$name
Expand All @@ -55,19 +56,15 @@ emit() {
}

start() {
[ ! -d "/var/log/kibana/" ] && mkdir "/var/log/kibana/"
chown "$user":"$group" "/var/log/kibana/"
chmod 2750 "/var/log/kibana/"

[ ! -d "/var/run/kibana/" ] && mkdir "/var/run/kibana/"
chown "$user":"$group" "/var/run/kibana/"
chmod 755 "/var/run/kibana/"

chroot --userspec "$user":"$group" "$chroot" sh -c "
cd \"$chdir\"
exec \"$program\"
" >> /var/log/kibana/kibana.stdout 2>> /var/log/kibana/kibana.stderr &
exec \"$program $args\"
" >> /var/log/kibana/kibana.log 2>&1 &

# Generate the pidfile from here. If we instead made the forked process
# generate it there will be a race condition between the pidfile writing
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/expressions/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ export interface Range {
// Warning: (ae-missing-release-tag) "ReactExpressionRenderer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const ReactExpressionRenderer: ({ className, dataAttrs, padding, renderError, expression, onEvent, reload$, ...expressionLoaderOptions }: ReactExpressionRendererProps) => JSX.Element;
export const ReactExpressionRenderer: ({ className, dataAttrs, padding, renderError, expression, onEvent, reload$, debounce, ...expressionLoaderOptions }: ReactExpressionRendererProps) => JSX.Element;

// Warning: (ae-missing-release-tag) "ReactExpressionRendererProps" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand All @@ -1050,6 +1050,8 @@ export interface ReactExpressionRendererProps extends IExpressionLoaderParams {
// (undocumented)
dataAttrs?: string[];
// (undocumented)
debounce?: number;
// (undocumented)
expression: string | ExpressionAstExpression;
// (undocumented)
onEvent?: (event: ExpressionRendererEvent) => void;
Expand Down
Loading

0 comments on commit a8772dd

Please sign in to comment.