Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[File upload] Move File Upload to New Platform #58550

Merged
merged 11 commits into from
Mar 4, 2020
2 changes: 1 addition & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"xpack.drilldowns": "plugins/drilldowns",
"xpack.endpoint": "plugins/endpoint",
"xpack.features": "plugins/features",
"xpack.fileUpload": "legacy/plugins/file_upload",
"xpack.fileUpload": "plugins/file_upload",
"xpack.graph": ["legacy/plugins/graph", "plugins/graph"],
"xpack.grokDebugger": "legacy/plugins/grokdebugger",
"xpack.idxMgmt": "plugins/index_management",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { remoteClusters } from './legacy/plugins/remote_clusters';
import { crossClusterReplication } from './legacy/plugins/cross_cluster_replication';
import { upgradeAssistant } from './legacy/plugins/upgrade_assistant';
import { uptime } from './legacy/plugins/uptime';
import { fileUpload } from './legacy/plugins/file_upload';
import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects';
import { snapshotRestore } from './legacy/plugins/snapshot_restore';
import { transform } from './legacy/plugins/transform';
Expand Down Expand Up @@ -69,7 +68,6 @@ module.exports = function(kibana) {
crossClusterReplication(kibana),
upgradeAssistant(kibana),
uptime(kibana),
fileUpload(kibana),
encryptedSavedObjects(kibana),
lens(kibana),
snapshotRestore(kibana),
Expand Down
36 changes: 0 additions & 36 deletions x-pack/legacy/plugins/file_upload/index.js

This file was deleted.

6 changes: 6 additions & 0 deletions x-pack/legacy/plugins/maps/public/kibana_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export const getInspector = () => {
return inspector;
};

let fileUpload;
kindsun marked this conversation as resolved.
Show resolved Hide resolved
export const setFileUpload = fileUploadPlugin => (fileUpload = fileUploadPlugin);
export const getFileUpload = () => {
kindsun marked this conversation as resolved.
Show resolved Hide resolved
return fileUpload.JsonUploadAndParse;
};

export async function fetchSearchSourceAndRecordWithInspector({
searchSource,
requestId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React from 'react';
import { start as fileUpload } from '../../../../../file_upload/public/legacy';
import { getFileUpload } from '../../../kibana_services';

export function ClientFileCreateSourceEditor({
previewGeojsonFile,
Expand All @@ -14,8 +14,9 @@ export function ClientFileCreateSourceEditor({
onRemove,
onIndexReady,
}) {
const FileUpload = getFileUpload();
return (
<fileUpload.JsonUploadAndParse
<FileUpload
appName={'Maps'}
isIndexingTriggered={isIndexingTriggered}
onFileUpload={previewGeojsonFile}
Expand Down
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { wrapInI18nContext } from 'ui/i18n';
// @ts-ignore
import { MapListing } from './components/map_listing';
// @ts-ignore
import { setLicenseId, setInspector } from './kibana_services';
import { setLicenseId, setInspector, setFileUpload } from './kibana_services';
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { featureCatalogueEntry } from './feature_catalogue_entry';
Expand Down Expand Up @@ -52,5 +52,6 @@ export class MapsPlugin implements Plugin<MapsPluginSetup, MapsPluginStart> {

public start(core: CoreStart, plugins: any) {
setInspector(plugins.np.inspector);
setFileUpload(plugins.np.file_upload);
}
}
9 changes: 9 additions & 0 deletions x-pack/plugins/file_upload/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "file_upload",
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["xpack", "file_upload"],
"server": true,
"ui": true,
"requiredPlugins": ["data", "usageCollection"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { npStart } from 'ui/new_platform';
import { DEFAULT_KBN_VERSION } from '../common/constants/file_import';

export const indexPatternService = npStart.plugins.data.indexPatterns;

export let indexPatternService;
export let savedObjectsClient;
export let basePath;
export let kbnVersion;
export let kbnFetch;

export const initServicesAndConstants = ({ savedObjects, http, injectedMetadata }) => {
savedObjectsClient = savedObjects.client;
export const setupInitServicesAndConstants = ({ http }) => {
basePath = http.basePath.basePath;
kbnVersion = injectedMetadata.getKibanaVersion(DEFAULT_KBN_VERSION);
kbnFetch = http.fetch;
};

export const startInitServicesAndConstants = ({ savedObjects }, { data }) => {
indexPatternService = data.indexPatterns;
savedObjectsClient = savedObjects.client;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,36 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Plugin, CoreStart } from 'src/core/public';
// @ts-ignore
import { CoreSetup, CoreStart, Plugin } from 'kibana/server';
// @ts-ignore
import { JsonUploadAndParse } from './components/json_upload_and_parse';
// @ts-ignore
import { initServicesAndConstants } from './kibana_services';
import { setupInitServicesAndConstants, startInitServicesAndConstants } from './kibana_services';
import { IDataPluginServices } from '../../../../src/plugins/data/public';

/**
* These are the interfaces with your public contracts. You should export these
* for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces.
* @public
*/

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface FileUploadPluginSetupDependencies {}
export interface FileUploadPluginStartDependencies {
data: IDataPluginServices;
}

export type FileUploadPluginSetup = ReturnType<FileUploadPlugin['setup']>;
export type FileUploadPluginStart = ReturnType<FileUploadPlugin['start']>;

/** @internal */
export class FileUploadPlugin implements Plugin<FileUploadPluginSetup, FileUploadPluginStart> {
public setup() {}
public setup(core: CoreSetup, plugins: FileUploadPluginSetupDependencies) {
setupInitServicesAndConstants(core);
}

public start(core: CoreStart) {
initServicesAndConstants(core);
public start(core: CoreStart, plugins: FileUploadPluginStartDependencies) {
startInitServicesAndConstants(core, plugins);
return {
JsonUploadAndParse,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { FileUploadPlugin } from './plugin';

import { npStart } from 'ui/new_platform';
import { plugin } from '.';
export * from './plugin';

const pluginInstance = plugin();

export const start = pluginInstance.start(npStart.core);
export const plugin = () => new FileUploadPlugin();
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

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

export class FileUploadPlugin {
constructor() {
this.router = null;
}

setup(core) {
setup(core, plugins) {
core.savedObjects.registerType(fileUploadTelemetryMappingsType);
setElasticsearchClientServices(core.elasticsearch);
this.router = core.http.createRouter();
registerFileUploadUsageCollector(plugins.usageCollection);
}

start(core, plugins) {
start(core) {
initRoutes(this.router, core.savedObjects.getSavedObjectsRepository);
setInternalRepository(core.savedObjects.createInternalRepository);

registerFileUploadUsageCollector(plugins.usageCollection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*/

export { registerFileUploadUsageCollector } from './file_upload_usage_collector';
export { fileUploadTelemetryMappingsType } from './mappings';
21 changes: 21 additions & 0 deletions x-pack/plugins/file_upload/server/telemetry/mappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure how to test ..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a global telemetry test covering it here that should fail if telemetry isn't being generated. Checking locally produces this result as expected:

image


import { SavedObjectsType } from 'src/core/server';
import { TELEMETRY_DOC_ID } from './telemetry';

export const fileUploadTelemetryMappingsType: SavedObjectsType = {
name: TELEMETRY_DOC_ID,
hidden: false,
namespaceAgnostic: true,
mappings: {
properties: {
filesUploadedTotalCount: {
type: 'long',
},
},
},
};