Skip to content

Commit

Permalink
Merge branch 'master' into directory_names_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored May 26, 2020
2 parents 92a987c + c9c37f7 commit 4af24a2
Show file tree
Hide file tree
Showing 36 changed files with 478 additions and 152 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/lib/apm_telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export async function createApmTelemetry({

const collectAndStore = async () => {
const config = await config$.pipe(take(1)).toPromise();
const esClient = core.elasticsearch.dataClient;
const [{ elasticsearch }] = await core.getStartServices();
const esClient = elasticsearch.legacy.client;

const indices = await getApmIndices({
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@ export const EmbeddableExpressionType = 'embeddable';
export { EmbeddableTypes, EmbeddableInput };

export interface EmbeddableExpression<Input extends EmbeddableInput> {
/**
* The type of the expression result
*/
type: typeof EmbeddableExpressionType;
/**
* The input to be passed to the embeddable
*/
input: Input;
/**
* The type of embeddable
*/
embeddableType: string;
/**
* Timestamp. Needed to get a different result after each time the expression is evaluated
* to force a reload of the embeddables internal data
*/
generatedAt: number;
}

export const embeddableType = (): ExpressionTypeDefinition<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function savedLens(): ExpressionFunctionDefinition<
disableTriggers: true,
},
embeddableType: EmbeddableTypes.lens,
generatedAt: Date.now(),
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export function savedMap(): ExpressionFunctionDefinition<
hiddenLayers: args.hideLayer || [],
},
embeddableType: EmbeddableTypes.map,
generatedAt: Date.now(),
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function savedSearch(): ExpressionFunctionDefinition<
...buildEmbeddableFilters(filters),
},
embeddableType: EmbeddableTypes.search,
generatedAt: Date.now(),
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function savedVisualization(): ExpressionFunctionDefinition<
vis: visOptions,
},
embeddableType: EmbeddableTypes.visualization,
generatedAt: Date.now(),
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const embeddableRendererFactory = (core: CoreStart, plugins: StartDeps) =
});
} else {
embeddablesRegistry[uniqueId].updateInput(input);
embeddablesRegistry[uniqueId].reload();
}
},
});
Expand Down
19 changes: 13 additions & 6 deletions x-pack/plugins/canvas/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ import { CanvasStartDeps, CanvasSetupDeps } from './plugin';
// @ts-ignore Untyped local
import { App } from './components/app';
import { KibanaContextProvider } from '../../../../src/plugins/kibana_react/public';
import { initInterpreter, resetInterpreter } from './lib/run_interpreter';
import { initInterpreter } from './lib/run_interpreter';
import { registerLanguage } from './lib/monaco_language_def';
import { SetupRegistries } from './plugin_api';
import { initRegistries, populateRegistries, destroyRegistries } from './registries';
import { getDocumentationLinks } from './lib/documentation_links';
// @ts-ignore untyped component
import { HelpMenu } from './components/help_menu/help_menu';
import { createStore, destroyStore } from './store';
import { createStore } from './store';

/* eslint-enable */
import { init as initStatsReporter } from './lib/ui_metric';

import { CapabilitiesStrings } from '../i18n';

import { startServices, stopServices, services } from './services';
import { startServices, services } from './services';
// @ts-ignore Untyped local
import { destroyHistory } from './lib/history_provider';
// @ts-ignore Untyped local
import { stopRouter } from './lib/router_provider';
// @ts-ignore Untyped local
import { appUnload } from './state/actions/app';

import './style/index.scss';

Expand Down Expand Up @@ -68,6 +70,7 @@ export const renderApp = (
);
return () => {
ReactDOM.unmountComponentAtNode(element);
canvasStore.dispatch(appUnload());
};
};

Expand Down Expand Up @@ -129,10 +132,14 @@ export const initializeCanvas = async (
};

export const teardownCanvas = (coreStart: CoreStart, startPlugins: CanvasStartDeps) => {
stopServices();
destroyRegistries();
resetInterpreter();
destroyStore();

// TODO: Not cleaning these up temporarily.
// We have an issue where if requests are inflight, and you navigate away,
// those requests could still be trying to act on the store and possibly require services.
// stopServices();
// resetInterpreter();
// destroyStore();

coreStart.chrome.setBadge(undefined);
coreStart.chrome.setHelpExtension(undefined);
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/canvas/public/state/actions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ import { createAction } from 'redux-actions';
// actions to set the application state
export const appReady = createAction('appReady');
export const appError = createAction('appError');
export const appUnload = createAction('appUnload');
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { getFullscreen } from '../selectors/app';
import { getInFlight } from '../selectors/resolved_args';
import { getWorkpad, getPages, getSelectedPageIndex, getAutoplay } from '../selectors/workpad';
// @ts-ignore untyped local
import { appUnload } from '../actions/app';
// @ts-ignore Untyped Local
import { routerProvider } from '../../lib/router_provider';
import { setAutoplayInterval } from '../../lib/app_state';
import { createTimeInterval } from '../../lib/time_interval';
Expand Down Expand Up @@ -83,5 +85,9 @@ export const workpadAutoplay: Middleware<{}, State> = ({ getState }) => (next) =
} else {
stopAutoUpdate();
}

if (action.type === appUnload.toString()) {
stopAutoUpdate();
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { State } from '../../../types';
import { fetchAllRenderables } from '../actions/elements';
// @ts-ignore Untyped Local
import { setRefreshInterval } from '../actions/workpad';
// @ts-ignore Untyped Local
import { appUnload } from '../actions/app';
import { inFlightComplete } from '../actions/resolved_args';
import { getInFlight } from '../selectors/resolved_args';
import { getRefreshInterval } from '../selectors/workpad';
Expand Down Expand Up @@ -81,5 +83,9 @@ export const workpadRefresh: Middleware<{}, State> = ({ dispatch, getState }) =>
startDelayedUpdate();
}
}

if (action.type === appUnload.toString()) {
cancelDelayedUpdate();
}
};
};
10 changes: 10 additions & 0 deletions x-pack/plugins/canvas/public/state/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import { getRootReducer } from './reducers';

let store;

export function getStore() {
return store;
}

export function cloneStore() {
const state = store.getState();
store = undefined;
return createStore(state);
}

export function createStore(initialState) {
if (typeof store !== 'undefined') {
throw new Error('Redux store can only be initialized once');
Expand Down
17 changes: 15 additions & 2 deletions x-pack/plugins/canvas/public/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
* you may not use this file except in compliance with the Elastic License.
*/

// @ts-ignore Untyped local
import { createStore as createReduxStore, destroyStore as destroy } from './state/store';
import {
createStore as createReduxStore,
destroyStore as destroy,
getStore,
cloneStore,
// @ts-ignore Untyped local
} from './state/store';
// @ts-ignore Untyped local
import { getInitialState } from './state/initial_state';

import { CoreSetup } from '../../../../src/core/public';
import { CanvasSetupDeps } from './plugin';

export async function createStore(core: CoreSetup, plugins: CanvasSetupDeps) {
if (getStore()) {
return cloneStore();
}

return createFreshStore(core, plugins);
}

export async function createFreshStore(core: CoreSetup, plugins: CanvasSetupDeps) {
const initialState = getInitialState();

const basePath = core.http.basePath.get();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/event_log/server/es/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('getIndexTemplate()', () => {
const indexTemplate = getIndexTemplate(esNames);
expect(indexTemplate.index_patterns).toEqual([esNames.indexPatternWithVersion]);
expect(indexTemplate.settings.number_of_shards).toBeGreaterThanOrEqual(0);
expect(indexTemplate.settings.number_of_replicas).toBeGreaterThanOrEqual(0);
expect(indexTemplate.settings.auto_expand_replicas).toBe('0-1');
expect(indexTemplate.settings['index.lifecycle.name']).toBe(esNames.ilmPolicy);
expect(indexTemplate.settings['index.lifecycle.rollover_alias']).toBe(esNames.alias);
expect(indexTemplate.mappings).toMatchObject({});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/event_log/server/es/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getIndexTemplate(esNames: EsNames) {
index_patterns: [esNames.indexPatternWithVersion],
settings: {
number_of_shards: 1,
number_of_replicas: 1,
auto_expand_replicas: '0-1',
'index.lifecycle.name': esNames.ilmPolicy,
'index.lifecycle.rollover_alias': esNames.alias,
},
Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions x-pack/plugins/file_upload/server/kibana_server_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

let dataClient;

export const setElasticsearchClientServices = (elasticsearch) => {
({ dataClient } = elasticsearch);
};
export const getDataClient = () => dataClient;

let internalRepository;
export const setInternalRepository = (createInternalRepository) => {
internalRepository = createInternalRepository();
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/file_upload/server/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { initRoutes } from './routes/file_upload';
import { setElasticsearchClientServices, setInternalRepository } from './kibana_server_services';
import { setInternalRepository } from './kibana_server_services';
import { registerFileUploadUsageCollector, fileUploadTelemetryMappingsType } from './telemetry';

export class FileUploadPlugin {
Expand All @@ -15,7 +15,6 @@ export class FileUploadPlugin {

setup(core, plugins) {
core.savedObjects.registerType(fileUploadTelemetryMappingsType);
setElasticsearchClientServices(core.elasticsearch);
this.router = core.http.createRouter();
registerFileUploadUsageCollector(plugins.usageCollection);
}
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/file_upload/server/routes/file_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { callWithRequestFactory } from '../client/call_with_request_factory';
import { importDataProvider } from '../models/import_data';
import { updateTelemetry } from '../telemetry/telemetry';
import { MAX_BYTES } from '../../common/constants/file_import';
Expand Down Expand Up @@ -86,7 +85,7 @@ const finishValidationAndProcessReq = () => {
let resp;
try {
const validIdReqData = idConditionalValidation(body, boolHasId);
const callWithRequest = callWithRequestFactory(req);
const callWithRequest = con.core.elasticsearch.dataClient.callAsCurrentUser;
const { importData: importDataFunc } = importDataProvider(callWithRequest);

const { index, settings, mappings, ingestPipeline, data } = validIdReqData;
Expand Down
14 changes: 3 additions & 11 deletions x-pack/plugins/ingest_pipelines/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
"version": "8.0.0",
"server": true,
"ui": true,
"requiredPlugins": [
"licensing",
"management"
],
"optionalPlugins": [
"usageCollection"
],
"configPath": [
"xpack",
"ingest_pipelines"
]
"requiredPlugins": ["licensing", "management"],
"optionalPlugins": ["security", "usageCollection"],
"configPath": ["xpack", "ingest_pipelines"]
}
5 changes: 4 additions & 1 deletion x-pack/plugins/ingest_pipelines/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class IngestPipelinesPlugin implements Plugin<void, void, any, any> {
this.apiRoutes = new ApiRoutes();
}

public setup({ http, elasticsearch }: CoreSetup, { licensing }: Dependencies) {
public setup({ http }: CoreSetup, { licensing, security }: Dependencies) {
this.logger.debug('ingest_pipelines: setup');

const router = http.createRouter();
Expand All @@ -47,6 +47,9 @@ export class IngestPipelinesPlugin implements Plugin<void, void, any, any> {
this.apiRoutes.setup({
router,
license: this.license,
config: {
isSecurityEnabled: security !== undefined && security.license.isEnabled(),
},
lib: {
isEsError,
},
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/ingest_pipelines/server/routes/api/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import { schema } from '@kbn/config-schema';
import { Pipeline } from '../../../common/types';
import { API_BASE_PATH } from '../../../common/constants';
import { RouteDependencies } from '../../types';
import { pipelineSchema } from './pipeline_schema';

const bodySchema = schema.object({
name: schema.string(),
description: schema.maybe(schema.string()),
processors: schema.arrayOf(schema.recordOf(schema.string(), schema.any())),
version: schema.maybe(schema.number()),
on_failure: schema.maybe(schema.arrayOf(schema.recordOf(schema.string(), schema.any()))),
...pipelineSchema,
});

export const registerCreateRoute = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { schema } from '@kbn/config-schema';

export const pipelineSchema = {
description: schema.maybe(schema.string()),
processors: schema.arrayOf(schema.recordOf(schema.string(), schema.any())),
version: schema.maybe(schema.number()),
on_failure: schema.maybe(schema.arrayOf(schema.recordOf(schema.string(), schema.any()))),
};
Loading

0 comments on commit 4af24a2

Please sign in to comment.