Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into task/fleet-86369-…
Browse files Browse the repository at this point in the history
…add-used-by-counts
  • Loading branch information
paul-tavares committed Jan 11, 2021
2 parents 3b4d481 + 628dd17 commit 9bcd2d8
Show file tree
Hide file tree
Showing 107 changed files with 4,765 additions and 677 deletions.
5 changes: 4 additions & 1 deletion docs/developer/advanced/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
* <<running-elasticsearch>>
* <<development-es-snapshots>>
* <<development-basepath>>
* <<upgrading-nodejs>>

include::development-es-snapshots.asciidoc[leveloffset=+1]

include::running-elasticsearch.asciidoc[leveloffset=+1]

include::development-basepath.asciidoc[leveloffset=+1]
include::development-basepath.asciidoc[leveloffset=+1]

include::upgrading-nodejs.asciidoc[leveloffset=+1]
76 changes: 76 additions & 0 deletions docs/developer/advanced/upgrading-nodejs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[[upgrading-nodejs]]
== Upgrading Node.js

{kib} requires a specific Node.js version to run.
When running {kib} from source, you must have this version installed locally.

The required version of Node.js is listed in several different files throughout the {kib} source code.
Theses files must be updated when upgrading Node.js:

- {kib-repo}blob/{branch}/.ci/Dockerfile[`.ci/Dockerfile`] - The version is specified in the `NODE_VERSION` constant.
This is used to pull the relevant image from https://hub.docker.com/_/node[Docker Hub].
Note that Docker Hub can take 24+ hours to be updated with the new images after a new release of Node.js, so if you're upgrading Node.js in Kibana _just_ after the official Node.js release, you have to check if the new images are present on Docker Hub.
If they are not, and the update is urgent, you can skip this file and update it later once Docker Hub has been updated.
- {kib-repo}blob/{branch}/.node-version[`.node-version`]
- {kib-repo}blob/{branch}/.nvmrc[`.nvmrc`]
- {kib-repo}blob/{branch}/package.json[`package.json`] - The version is specified in the `engines.node` field.

See PR {kib-repo}pull/86593[#86593] for an example of how the Node.js version has been upgraded previously.

In the 6.8 branch, the `.ci/Dockerfile` file does not exist, so when upgrading Node.js in that branch, just skip that file.

=== Backporting

The following rules are not set in stone.
Use best judgement when backporting.

Currently version 7.11 and newer run Node.js 14, while 7.10 and older run Node.js 10.
Hence, upgrades to either Node.js 14 or Node.js 10 shold be done as separate PRs.

==== Node.js patch upgrades

Typically, you want to backport Node.js *patch* upgrades to all supported release branches that run the same _major_ Node.js version:

- If upgrading Node.js 14, and the current release is 7.11.1, the main PR should target `master` and be backported to `7.x` and `7.11`.
- If upgrading Node.js 10, the main PR should target `6.8` only.

==== Node.js minor upgrades

Typically, you want to backport Node.js *minor* upgrades to the next minor {kib} release branch that runs the same *major* Node.js version:

- If upgrading Node.js 14, and the current release is 7.11.1, the main PR should target `master` and be backported to `7.x`, while leaving the `7.11` branch as-is.
- If upgrading Node.js 10, the main PR should target `6.8` only.

=== Upgrading installed Node.js version

The following instructions expect that https://github.com/nvm-sh/nvm[nvm] is used to manage locally installed Node.js versions.

Run the following to install the new Node.js version. Replace `<version>` with the desired Node.js version:

[source,bash]
----
nvm install <version>
----

To get the same global npm modules installed with the new version of Node.js as is currently installed, use the `--reinstall-packages-from` command-line argument (optionally replace `14` with the desired source version):

[source,bash]
----
nvm install <version> --reinstall-packages-from=14
----

If needed, uninstall the old version of Node.js by running the following. Replace `<old-version>` with the full version number of the version that should be uninstalled:

[source,bash]
----
nvm uninstall <old-version>
----

Optionally, tell nvm to always use the "highest" installed Node.js 14 version. Replace `14` if a different major version is desired:

[source,bash]
----
nvm alias default 14
----

Alternatively, include the full version number at the end to specify a specific default version.
2 changes: 1 addition & 1 deletion docs/developer/getting-started/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cd kibana

Install the version of Node.js listed in the `.node-version` file. This
can be automated with tools such as
https://github.com/creationix/nvm[nvm],
https://github.com/nvm-sh/nvm[nvm],
https://github.com/coreybutler/nvm-windows[nvm-windows] or
https://github.com/wbyoung/avn[avn]. As we also include a `.nvmrc` file
you can switch to the correct version when using nvm by running:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
"intl-messageformat": "^2.2.0",
"intl-relativeformat": "^2.1.0",
"io-ts": "^2.0.5",
"ipaddr.js": "2.0.0",
"isbinaryfile": "4.0.2",
"joi": "^13.5.2",
"jquery": "^3.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface DataViewComponentProps extends InspectorViewProps {
uiActions: UiActionsStart;
fieldFormats: FieldFormatsStart;
isFilterable: (column: DatatableColumn) => boolean;
options: { fileName?: string };
}

class DataViewComponent extends Component<DataViewComponentProps, DataViewComponentState> {
Expand Down Expand Up @@ -122,7 +123,7 @@ class DataViewComponent extends Component<DataViewComponentProps, DataViewCompon
return (
<DataTableFormat
data={this.state.datatable}
exportTitle={this.props.title}
exportTitle={this.props.options?.fileName || this.props.title}
uiSettings={this.props.uiSettings}
fieldFormats={this.props.fieldFormats}
uiActions={this.props.uiActions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const getDataViewComponentWrapper = (
fieldFormats={getStartServices().fieldFormats}
uiActions={getStartServices().uiActions}
isFilterable={getStartServices().isFilterable}
options={props.options}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ export class InspectPanelAction implements Action<ActionContext> {
if (!(await this.isCompatible({ embeddable })) || adapters === undefined) {
throw new Error('Action not compatible with context');
}

const session = this.inspector.open(adapters, {
title: embeddable.getTitle(),
options: {
fileName:
embeddable.getTitle() || // pick the visible title
embeddable.getInput().title || // or the custom title if used, but currently hidden
embeddable.getOutput().defaultTitle || // or the saved title
// in the very last resort use "untitled"
i18n.translate('embeddableApi.panel.inspectPanel.untitledEmbeddableFilename', {
defaultMessage: 'untitled',
}),
},
});
// Overwrite the embeddables.destroy() function to close the inspector
// before calling the original destroy method
Expand Down
1 change: 1 addition & 0 deletions src/plugins/inspector/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class InspectorPublicPlugin implements Plugin<Setup, Start> {
views={views}
adapters={adapters}
title={options.title}
options={options.options}
dependencies={{ uiSettings: core.uiSettings }}
/>
),
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/inspector/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export interface InspectorViewProps<TAdapters extends Adapters = Adapters> {
* The title that the inspector is currently using e.g. a visualization name.
*/
title: string;
/**
* A set of specific options for each view.
*/
options?: unknown;
}

/**
Expand Down Expand Up @@ -61,9 +65,11 @@ export interface InspectorViewDescription {
* Options that can be specified when opening the inspector.
* @property {string} title - An optional title, that will be shown in the header
* of the inspector. Can be used to give more context about what is being inspected.
* @property {unknown} options - A set of specific payload to be passed to inspector views
*/
export interface InspectorOptions {
title?: string;
options?: unknown;
}

export type InspectorSession = OverlayRef;
3 changes: 3 additions & 0 deletions src/plugins/inspector/public/ui/inspector_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const inspectorTitle = i18n.translate('inspector.title', {
interface InspectorPanelProps {
adapters: Adapters;
title?: string;
options?: unknown;
views: InspectorViewDescription[];
dependencies: {
uiSettings: IUiSettingsClient;
Expand Down Expand Up @@ -76,6 +77,7 @@ export class InspectorPanel extends Component<InspectorPanelProps, InspectorPane
}
},
title: PropTypes.string,
options: PropTypes.object,
};

state: InspectorPanelState = {
Expand Down Expand Up @@ -111,6 +113,7 @@ export class InspectorPanel extends Component<InspectorPanelProps, InspectorPane
<this.state.selectedView.component
adapters={this.props.adapters}
title={this.props.title || ''}
options={this.props.options}
/>
</Suspense>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,22 @@ export async function rollDailyData(logger: Logger, savedObjectsClient?: ISavedO
})),
{ overwrite: true }
);
await Promise.all(
const promiseStatuses = await Promise.allSettled(
rawApplicationUsageTransactional.map(
({ id }) => savedObjectsClient.delete(SAVED_OBJECTS_TRANSACTIONAL_TYPE, id) // There is no bulkDelete :(
)
);
const rejectedPromises = promiseStatuses.filter(
(settledResult): settledResult is PromiseRejectedResult =>
settledResult.status === 'rejected'
);
if (rejectedPromises.length > 0) {
throw new Error(
`Failed to delete some items in ${SAVED_OBJECTS_TRANSACTIONAL_TYPE}: ${JSON.stringify(
rejectedPromises.map(({ reason }) => reason)
)}`
);
}
}
} while (toCreate.size > 0);
} catch (err) {
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/management/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"common/**/*",
"public/**/*",
"server/**/*",
"../../../typings/**/*"
],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../home/tsconfig.json"},
{ "path": "../kibana_react/tsconfig.json"},
{ "path": "../kibana_utils/tsconfig.json"}
]
}
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"exclude": ["plugin_functional/plugins/**/*", "interpreter_functional/plugins/**/*"],
"references": [
{ "path": "../src/core/tsconfig.json" },
{ "path": "../src/plugins/management/tsconfig.json" },
{ "path": "../src/plugins/bfetch/tsconfig.json" },
{ "path": "../src/plugins/embeddable/tsconfig.json" },
{ "path": "../src/plugins/expressions/tsconfig.json" },
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"exclude": [
"src/**/__fixtures__/**/*",
"src/core/**/*",
"src/plugins/management/**/*",
"src/plugins/apm_oss/**/*",
"src/plugins/bfetch/**/*",
"src/plugins/data/**/*",
Expand Down Expand Up @@ -38,6 +39,7 @@
],
"references": [
{ "path": "./src/core/tsconfig.json" },
{ "path": "./src/plugins/management/tsconfig.json"},
{ "path": "./src/plugins/apm_oss/tsconfig.json" },
{ "path": "./src/plugins/bfetch/tsconfig.json" },
{ "path": "./src/plugins/data/tsconfig.json" },
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.refs.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{ "path": "./src/plugins/telemetry_collection_manager/tsconfig.json" },
{ "path": "./src/plugins/ui_actions/tsconfig.json" },
{ "path": "./src/plugins/url_forwarding/tsconfig.json" },
{ "path": "./src/plugins/usage_collection/tsconfig.json" }
{ "path": "./src/plugins/usage_collection/tsconfig.json" },
{ "path": "./src/plugins/management/tsconfig.json" },
]
}
5 changes: 2 additions & 3 deletions x-pack/plugins/alerts/server/alerts_client/alerts_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server';
import { TaskManagerStartContract } from '../../../task_manager/server';
import { taskInstanceToAlertTaskInstance } from '../task_runner/alert_task_instance';
import { deleteTaskIfItExists } from '../lib/delete_task_if_it_exists';
import { RegistryAlertType, UntypedNormalizedAlertType } from '../alert_type_registry';
import { AlertsAuthorization, WriteOperations, ReadOperations } from '../authorization';
import { IEventLogClient } from '../../../../plugins/event_log/server';
Expand Down Expand Up @@ -602,7 +601,7 @@ export class AlertsClient {
const removeResult = await this.unsecuredSavedObjectsClient.delete('alert', id);

await Promise.all([
taskIdToRemove ? deleteTaskIfItExists(this.taskManager, taskIdToRemove) : null,
taskIdToRemove ? this.taskManager.removeIfExists(taskIdToRemove) : null,
apiKeyToInvalidate
? markApiKeyForInvalidation(
{ apiKey: apiKeyToInvalidate },
Expand Down Expand Up @@ -1060,7 +1059,7 @@ export class AlertsClient {

await Promise.all([
attributes.scheduledTaskId
? deleteTaskIfItExists(this.taskManager, attributes.scheduledTaskId)
? this.taskManager.removeIfExists(attributes.scheduledTaskId)
: null,
apiKeyToInvalidate
? await markApiKeyForInvalidation(
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/alerts/server/alerts_client/tests/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('delete()', () => {
const result = await alertsClient.delete({ id: '1' });
expect(result).toEqual({ success: true });
expect(unsecuredSavedObjectsClient.delete).toHaveBeenCalledWith('alert', '1');
expect(taskManager.remove).toHaveBeenCalledWith('task-123');
expect(taskManager.removeIfExists).toHaveBeenCalledWith('task-123');
expect(unsecuredSavedObjectsClient.create.mock.calls[0][0]).toBe(
'api_key_pending_invalidation'
);
Expand All @@ -135,7 +135,7 @@ describe('delete()', () => {
const result = await alertsClient.delete({ id: '1' });
expect(result).toEqual({ success: true });
expect(unsecuredSavedObjectsClient.delete).toHaveBeenCalledWith('alert', '1');
expect(taskManager.remove).toHaveBeenCalledWith('task-123');
expect(taskManager.removeIfExists).toHaveBeenCalledWith('task-123');
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledWith('alert', '1');
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
Expand All @@ -153,7 +153,7 @@ describe('delete()', () => {
});

await alertsClient.delete({ id: '1' });
expect(taskManager.remove).not.toHaveBeenCalled();
expect(taskManager.removeIfExists).not.toHaveBeenCalled();
});

test(`doesn't invalidate API key when apiKey is null`, async () => {
Expand Down Expand Up @@ -217,8 +217,8 @@ describe('delete()', () => {
);
});

test('throws error when taskManager.remove throws an error', async () => {
taskManager.remove.mockRejectedValue(new Error('TM Fail'));
test('throws error when taskManager.removeIfExists throws an error', async () => {
taskManager.removeIfExists.mockRejectedValue(new Error('TM Fail'));

await expect(alertsClient.delete({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
`"TM Fail"`
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/alerts/server/alerts_client/tests/disable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('disable()', () => {
version: '123',
}
);
expect(taskManager.remove).toHaveBeenCalledWith('task-123');
expect(taskManager.removeIfExists).toHaveBeenCalledWith('task-123');
expect(
(unsecuredSavedObjectsClient.create.mock.calls[0][1] as InvalidatePendingApiKey).apiKeyId
).toBe('123');
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('disable()', () => {
version: '123',
}
);
expect(taskManager.remove).toHaveBeenCalledWith('task-123');
expect(taskManager.removeIfExists).toHaveBeenCalledWith('task-123');
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
});

Expand All @@ -280,7 +280,7 @@ describe('disable()', () => {

await alertsClient.disable({ id: '1' });
expect(unsecuredSavedObjectsClient.update).not.toHaveBeenCalled();
expect(taskManager.remove).not.toHaveBeenCalled();
expect(taskManager.removeIfExists).not.toHaveBeenCalled();
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -314,7 +314,7 @@ describe('disable()', () => {

await alertsClient.disable({ id: '1' });
expect(unsecuredSavedObjectsClient.update).toHaveBeenCalled();
expect(taskManager.remove).toHaveBeenCalled();
expect(taskManager.removeIfExists).toHaveBeenCalled();
expect(unsecuredSavedObjectsClient.create).not.toHaveBeenCalled();
expect(alertsClientParams.logger.error).toHaveBeenCalledWith(
'disable(): Failed to load API key to invalidate on alert 1: Fail'
Expand All @@ -338,7 +338,7 @@ describe('disable()', () => {
});

test('throws when failing to remove task from task manager', async () => {
taskManager.remove.mockRejectedValueOnce(new Error('Failed to remove task'));
taskManager.removeIfExists.mockRejectedValueOnce(new Error('Failed to remove task'));

await expect(alertsClient.disable({ id: '1' })).rejects.toThrowErrorMatchingInlineSnapshot(
`"Failed to remove task"`
Expand Down
Loading

0 comments on commit 9bcd2d8

Please sign in to comment.