Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/elastic/kibana into add-i…
Browse files Browse the repository at this point in the history
…nventory-metric-threshold-alerts
  • Loading branch information
phillipb committed Apr 30, 2020
2 parents 2fe7091 + 0399f70 commit 1886f29
Show file tree
Hide file tree
Showing 79 changed files with 2,209 additions and 1,072 deletions.
4 changes: 3 additions & 1 deletion src/cli/cluster/cluster_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ export class ClusterManager {

const ignorePaths = [
/[\\\/](\..*|node_modules|bower_components|target|public|__[a-z0-9_]+__|coverage)([\\\/]|$)/,
/\.test\.(js|ts)$/,
/\.test\.(js|tsx?)$/,
/\.md$/,
/debug\.log$/,
...pluginInternalDirsIgnore,
fromRoot('src/legacy/server/sass/__tmp__'),
fromRoot('x-pack/legacy/plugins/reporting/.chromium'),
Expand Down
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
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_discover_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function({ getService, getPageObjects }) {

log.debug('create long_window_logstash index pattern');
// NOTE: long_window_logstash load does NOT create index pattern
await PageObjects.settings.createIndexPattern('long-window-logstash-');
await PageObjects.settings.createIndexPattern('long-window-logstash-*');
await kibanaServer.uiSettings.replace(defaultSettings);
await browser.refresh();

Expand Down
6 changes: 3 additions & 3 deletions test/functional/apps/getting_started/_shakespeare.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export default function({ getService, getPageObjects }) {

it('should create shakespeare index pattern', async function() {
log.debug('Create shakespeare index pattern');
await PageObjects.settings.createIndexPattern('shakes', null);
await PageObjects.settings.createIndexPattern('shakespeare', null);
const patternName = await PageObjects.settings.getIndexPageHeading();
expect(patternName).to.be('shakes*');
expect(patternName).to.be('shakespeare');
});

// https://www.elastic.co/guide/en/kibana/current/tutorial-visualizing.html
Expand All @@ -74,7 +74,7 @@ export default function({ getService, getPageObjects }) {
log.debug('create shakespeare vertical bar chart');
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVerticalBarChart();
await PageObjects.visualize.clickNewSearch('shakes*');
await PageObjects.visualize.clickNewSearch('shakespeare');
await PageObjects.visChart.waitForVisualization();

const expectedChartValues = [111396];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ export default function({ getService, getPageObjects }) {
it('should handle special charaters in template input', async () => {
await PageObjects.settings.clickAddNewIndexPatternButton();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.settings.setIndexPatternField({
indexPatternName: '❤️',
expectWildcard: false,
});
await PageObjects.settings.setIndexPatternField('❤️');
await PageObjects.header.waitUntilLoadingHasFinished();

await retry.try(async () => {
Expand Down
26 changes: 22 additions & 4 deletions test/functional/page_objects/settings_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider
}
await PageObjects.header.waitUntilLoadingHasFinished();
await retry.try(async () => {
await this.setIndexPatternField({ indexPatternName });
await this.setIndexPatternField(indexPatternName);
});
await PageObjects.common.sleep(2000);
await (await this.getCreateIndexPatternGoToStep2Button()).click();
Expand Down Expand Up @@ -375,14 +375,32 @@ export function SettingsPageProvider({ getService, getPageObjects }: FtrProvider
return indexPatternId;
}

async setIndexPatternField({ indexPatternName = 'logstash-', expectWildcard = true } = {}) {
async setIndexPatternField(indexPatternName = 'logstash-*') {
log.debug(`setIndexPatternField(${indexPatternName})`);
const field = await this.getIndexPatternField();
await field.clearValue();
await field.type(indexPatternName, { charByChar: true });
if (
indexPatternName.charAt(0) === '*' &&
indexPatternName.charAt(indexPatternName.length - 1) === '*'
) {
// this is a special case when the index pattern name starts with '*'
// like '*:makelogs-*' where the UI will not append *
await field.type(indexPatternName, { charByChar: true });
} else if (indexPatternName.charAt(indexPatternName.length - 1) === '*') {
// the common case where the UI will append '*' automatically so we won't type it
const tempName = indexPatternName.slice(0, -1);
await field.type(tempName, { charByChar: true });
} else {
// case where we don't want the * appended so we'll remove it if it was added
await field.type(indexPatternName, { charByChar: true });
const tempName = await field.getAttribute('value');
if (tempName.length > indexPatternName.length) {
await field.type(browser.keys.DELETE, { charByChar: true });
}
}
const currentName = await field.getAttribute('value');
log.debug(`setIndexPatternField set to ${currentName}`);
expect(currentName).to.eql(`${indexPatternName}${expectWildcard ? '*' : ''}`);
expect(currentName).to.eql(indexPatternName);
}

async getCreateIndexPatternGoToStep2Button() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const METRIC_EXPLORER_AGGREGATIONS = [
'cardinality',
'rate',
'count',
'sum',
] as const;

type MetricExplorerAggregations = typeof METRIC_EXPLORER_AGGREGATIONS[number];
Expand Down Expand Up @@ -54,6 +55,7 @@ export const metricsExplorerRequestBodyOptionalFieldsRT = rt.partial({
afterKey: rt.union([rt.string, rt.null, rt.undefined]),
limit: rt.union([rt.number, rt.null, rt.undefined]),
filterQuery: rt.union([rt.string, rt.null, rt.undefined]),
forceInterval: rt.boolean,
});

export const metricsExplorerRequestBodyRT = rt.intersection([
Expand Down
Loading

0 comments on commit 1886f29

Please sign in to comment.