Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into np/discover
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Apr 30, 2020
2 parents 30253a3 + 3442c25 commit 3eca079
Show file tree
Hide file tree
Showing 43 changed files with 907 additions and 122 deletions.
58 changes: 58 additions & 0 deletions src/core/server/http/http_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,14 @@ describe('setup contract', () => {
await create();
expect(create()).rejects.toThrowError('A cookieSessionStorageFactory was already created');
});

it('does not throw if called after stop', async () => {
const { createCookieSessionStorageFactory } = await server.setup(config);
await server.stop();
expect(() => {
createCookieSessionStorageFactory(cookieOptions);
}).not.toThrow();
});
});

describe('#isTlsEnabled', () => {
Expand Down Expand Up @@ -1113,4 +1121,54 @@ describe('setup contract', () => {
expect(getServerInfo().protocol).toEqual('https');
});
});

describe('#registerStaticDir', () => {
it('does not throw if called after stop', async () => {
const { registerStaticDir } = await server.setup(config);
await server.stop();
expect(() => {
registerStaticDir('/path1/{path*}', '/path/to/resource');
}).not.toThrow();
});
});

describe('#registerOnPreAuth', () => {
test('does not throw if called after stop', async () => {
const { registerOnPreAuth } = await server.setup(config);
await server.stop();
expect(() => {
registerOnPreAuth((req, res) => res.unauthorized());
}).not.toThrow();
});
});

describe('#registerOnPostAuth', () => {
test('does not throw if called after stop', async () => {
const { registerOnPostAuth } = await server.setup(config);
await server.stop();
expect(() => {
registerOnPostAuth((req, res) => res.unauthorized());
}).not.toThrow();
});
});

describe('#registerOnPreResponse', () => {
test('does not throw if called after stop', async () => {
const { registerOnPreResponse } = await server.setup(config);
await server.stop();
expect(() => {
registerOnPreResponse((req, res, t) => t.next());
}).not.toThrow();
});
});

describe('#registerAuth', () => {
test('does not throw if called after stop', async () => {
const { registerAuth } = await server.setup(config);
await server.stop();
expect(() => {
registerAuth((req, res) => res.unauthorized());
}).not.toThrow();
});
});
});
28 changes: 27 additions & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class HttpServer {
private registeredRouters = new Set<IRouter>();
private authRegistered = false;
private cookieSessionStorageCreated = false;
private stopped = false;

private readonly log: Logger;
private readonly authState: AuthStateStorage;
Expand Down Expand Up @@ -144,6 +145,10 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Http server is not setup up yet');
}
if (this.stopped) {
this.log.warn(`start called after stop`);
return;
}
this.log.debug('starting http server');

for (const router of this.registeredRouters) {
Expand Down Expand Up @@ -189,13 +194,13 @@ export class HttpServer {
}

public async stop() {
this.stopped = true;
if (this.server === undefined) {
return;
}

this.log.debug('stopping http server');
await this.server.stop();
this.server = undefined;
}

private getAuthOption(
Expand Down Expand Up @@ -234,6 +239,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`setupConditionalCompression called after stop`);
}

const { enabled, referrerWhitelist: list } = config.compression;
if (!enabled) {
Expand Down Expand Up @@ -261,6 +269,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerOnPostAuth called after stop`);
}

this.server.ext('onPostAuth', adoptToHapiOnPostAuthFormat(fn, this.log));
}
Expand All @@ -269,6 +280,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerOnPreAuth called after stop`);
}

this.server.ext('onRequest', adoptToHapiOnPreAuthFormat(fn, this.log));
}
Expand All @@ -277,6 +291,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerOnPreResponse called after stop`);
}

this.server.ext('onPreResponse', adoptToHapiOnPreResponseFormat(fn, this.log));
}
Expand All @@ -288,6 +305,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`createCookieSessionStorageFactory called after stop`);
}
if (this.cookieSessionStorageCreated) {
throw new Error('A cookieSessionStorageFactory was already created');
}
Expand All @@ -305,6 +325,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerAuth called after stop`);
}
if (this.authRegistered) {
throw new Error('Auth interceptor was already registered');
}
Expand Down Expand Up @@ -348,6 +371,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Http server is not setup up yet');
}
if (this.stopped) {
this.log.warn(`registerStaticDir called after stop`);
}

this.server.route({
path,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_markdown/public/markdown_vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n';

import { MarkdownVisWrapper } from './markdown_vis_controller';
import { MarkdownOptions } from './markdown_options';
import { SettingsOptions } from './settings_options';
import { SettingsOptions } from './settings_options_lazy';
import { DefaultEditorSize } from '../../vis_default_editor/public';

export const markdownVisDefinition = {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/vis_type_markdown/public/settings_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ function SettingsOptions({ stateParams, setValue }: VisOptionsProps<MarkdownVisP
);
}

export { SettingsOptions };
// default export required for React.Lazy
// eslint-disable-next-line import/no-default-export
export { SettingsOptions as default };
30 changes: 30 additions & 0 deletions src/plugins/vis_type_markdown/public/settings_options_lazy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { lazy, Suspense } from 'react';
import { EuiLoadingSpinner } from '@elastic/eui';

// @ts-ignore
const SettingsOptionsComponent = lazy(() => import('./settings_options'));

export const SettingsOptions = (props: any) => (
<Suspense fallback={<EuiLoadingSpinner />}>
<SettingsOptionsComponent {...props} />
</Suspense>
);
13 changes: 9 additions & 4 deletions src/plugins/vis_type_vega/public/vega_request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import { Filter, esQuery, TimeRange, Query } from '../../data/public';

// @ts-ignore
import { VegaParser } from './data_model/vega_parser';
// @ts-ignore
import { SearchCache } from './data_model/search_cache';
// @ts-ignore
Expand All @@ -46,7 +44,12 @@ export function createVegaRequestHandler({
const { timefilter } = data.query.timefilter;
const timeCache = new TimeCache(timefilter, 3 * 1000);

return ({ timeRange, filters, query, visParams }: VegaRequestHandlerParams) => {
return async function vegaRequestHandler({
timeRange,
filters,
query,
visParams,
}: VegaRequestHandlerParams) {
if (!searchCache) {
searchCache = new SearchCache(getData().search.__LEGACY.esClient, {
max: 10,
Expand All @@ -58,8 +61,10 @@ export function createVegaRequestHandler({

const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings);
const filtersDsl = esQuery.buildEsQuery(undefined, query, filters, esQueryConfigs);
// @ts-ignore
const { VegaParser } = await import('./data_model/vega_parser');
const vp = new VegaParser(visParams.spec, searchCache, timeCache, filtersDsl, serviceSettings);

return vp.parseAsync();
return await vp.parseAsync();
};
}
4 changes: 2 additions & 2 deletions src/plugins/vis_type_vega/public/vega_visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/
import { i18n } from '@kbn/i18n';
import { VegaView } from './vega_view/vega_view';
import { VegaMapView } from './vega_view/vega_map_view';
import { getNotifications, getData, getSavedObjects } from './services';

export const createVegaVisualization = ({ serviceSettings }) =>
Expand Down Expand Up @@ -117,8 +115,10 @@ export const createVegaVisualization = ({ serviceSettings }) =>

if (vegaParser.useMap) {
const services = { toastService: getNotifications().toasts };
const { VegaMapView } = await import('./vega_view/vega_map_view');
this._vegaView = new VegaMapView(vegaViewParams, services);
} else {
const { VegaView } = await import('./vega_view/vega_view');
this._vegaView = new VegaView(vegaViewParams);
}
await this._vegaView.init();
Expand Down
13 changes: 10 additions & 3 deletions x-pack/plugins/event_log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,28 @@ PUT _ilm/policy/event_log_policy
"hot": {
"actions": {
"rollover": {
"max_size": "5GB",
"max_size": "50GB",
"max_age": "30d"
}
}
},
"delete": {
"min_age": "90d",
"actions": {
"delete": {}
}
}
}
}
}
```

This means that ILM would "rollover" the current index, say
`.kibana-event-log-000001` by creating a new index `.kibana-event-log-000002`,
`.kibana-event-log-8.0.0-000001` by creating a new index `.kibana-event-log-8.0.0-000002`,
which would "inherit" everything from the index template, and then ILM will
set the write index of the the alias to the new index. This would happen
when the original index grew past 5 GB, or was created more than 30 days ago.
when the original index grew past 50 GB, or was created more than 30 days ago.
After rollover, the indices will be removed after 90 days to avoid disks to fill up.

For more relevant information on ILM, see:
[getting started with ILM doc][] and [write index alias behavior][]:
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/event_log/server/es/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ export function getIlmPolicy() {
hot: {
actions: {
rollover: {
max_size: '5GB',
max_size: '50GB',
max_age: '30d',
// max_docs: 1, // you know, for testing
},
},
},
delete: {
min_age: '90d',
actions: {
delete: {},
},
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
EuiText,
EuiFormRow,
EuiButtonEmpty,
EuiCheckbox,
EuiToolTip,
EuiIcon,
EuiFieldSearch,
} from '@elastic/eui';
import { IFieldType } from 'src/plugins/data/public';
Expand Down Expand Up @@ -57,6 +60,7 @@ interface Props {
groupBy?: string;
filterQuery?: string;
sourceId?: string;
alertOnNoData?: boolean;
};
alertsContext: AlertsContextValue<AlertContextMeta>;
setAlertParams(key: string, value: any): void;
Expand Down Expand Up @@ -282,6 +286,28 @@ export const Expressions: React.FC<Props> = props => {
</EuiButtonEmpty>
</div>

<EuiSpacer size={'m'} />
<EuiCheckbox
id="metrics-alert-no-data-toggle"
label={
<>
{i18n.translate('xpack.infra.metrics.alertFlyout.alertOnNoData', {
defaultMessage: "Alert me if there's no data",
})}{' '}
<EuiToolTip
content={i18n.translate('xpack.infra.metrics.alertFlyout.noDataHelpText', {
defaultMessage:
'Enable this to trigger the action if the metric(s) do not report any data over the expected time period, or if the alert fails to query Elasticsearch',
})}
>
<EuiIcon type="questionInCircle" color="subdued" />
</EuiToolTip>
</>
}
checked={alertParams.alertOnNoData}
onChange={e => setAlertParams('alertOnNoData', e.target.checked)}
/>

<EuiSpacer size={'m'} />

<EuiFormRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export function getAlertType(): AlertTypeModel {
defaultActionMessage: i18n.translate(
'xpack.infra.metrics.alerting.threshold.defaultActionMessage',
{
defaultMessage: `\\{\\{alertName\\}\\} - \\{\\{context.group\\}\\}
defaultMessage: `\\{\\{alertName\\}\\} - \\{\\{context.group\\}\\} is in a state of \\{\\{context.alertState\\}\\}
\\{\\{context.metricOf.condition0\\}\\} has crossed a threshold of \\{\\{context.thresholdOf.condition0\\}\\}
Current value is \\{\\{context.valueOf.condition0\\}\\}
Reason:
\\{\\{context.reason\\}\\}
`,
}
),
Expand Down
Loading

0 comments on commit 3eca079

Please sign in to comment.