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

[Ingest Manager] Kibana, not EPR, controls removable packages #69761

Merged
merged 4 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions x-pack/plugins/ingest_manager/common/openapi/spec_oas3.json
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,198 @@
},
"success": true
}
},
"required-package": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an example for a package which has removable: false

"value": {
"response": {
"format_version": "1.0.0",
"name": "endpoint",
"title": "Elastic Endpoint",
"version": "0.3.0",
"readme": "/package/endpoint/0.3.0/docs/README.md",
"license": "basic",
"description": "This is the Elastic Endpoint package.",
"type": "solution",
"categories": [
"security"
],
"release": "beta",
"requirement": {
"kibana": {
"versions": ">7.4.0"
}
},
"icons": [
{
"src": "/package/endpoint/0.3.0/img/logo-endpoint-64-color.svg",
"size": "16x16",
"type": "image/svg+xml"
}
],
"assets": {
"kibana": {
"dashboard": [
{
"pkgkey": "endpoint-0.3.0",
"service": "kibana",
"type": "dashboard",
"file": "826759f0-7074-11ea-9bc8-6b38f4d29a16.json",
"path": "endpoint-0.3.0/kibana/dashboard/826759f0-7074-11ea-9bc8-6b38f4d29a16.json"
}
],
"map": [
{
"pkgkey": "endpoint-0.3.0",
"service": "kibana",
"type": "map",
"file": "a3a3bd10-706b-11ea-9bc8-6b38f4d29a16.json",
"path": "endpoint-0.3.0/kibana/map/a3a3bd10-706b-11ea-9bc8-6b38f4d29a16.json"
}
],
"visualization": [
{
"pkgkey": "endpoint-0.3.0",
"service": "kibana",
"type": "visualization",
"file": "1cfceda0-728b-11ea-9bc8-6b38f4d29a16.json",
"path": "endpoint-0.3.0/kibana/visualization/1cfceda0-728b-11ea-9bc8-6b38f4d29a16.json"
},
{
"pkgkey": "endpoint-0.3.0",
"service": "kibana",
"type": "visualization",
"file": "1e525190-7074-11ea-9bc8-6b38f4d29a16.json",
"path": "endpoint-0.3.0/kibana/visualization/1e525190-7074-11ea-9bc8-6b38f4d29a16.json"
},
{
"pkgkey": "endpoint-0.3.0",
"service": "kibana",
"type": "visualization",
"file": "55387750-729c-11ea-9bc8-6b38f4d29a16.json",
"path": "endpoint-0.3.0/kibana/visualization/55387750-729c-11ea-9bc8-6b38f4d29a16.json"
},
{
"pkgkey": "endpoint-0.3.0",
"service": "kibana",
"type": "visualization",
"file": "92b1edc0-706a-11ea-9bc8-6b38f4d29a16.json",
"path": "endpoint-0.3.0/kibana/visualization/92b1edc0-706a-11ea-9bc8-6b38f4d29a16.json"
}
]
}
},
"datasets": [
{
"id": "endpoint",
"title": "Endpoint Events",
"release": "experimental",
"type": "events",
"package": "endpoint",
"path": "events"
},
{
"id": "endpoint.metadata",
"title": "Endpoint Metadata",
"release": "experimental",
"type": "metrics",
"package": "endpoint",
"path": "metadata"
},
{
"id": "endpoint.policy",
"title": "Endpoint Policy Response",
"release": "experimental",
"type": "metrics",
"package": "endpoint",
"path": "policy"
},
{
"id": "endpoint.telemetry",
"title": "Endpoint Telemetry",
"release": "experimental",
"type": "metrics",
"package": "endpoint",
"path": "telemetry"
}
],
"datasources": [
{
"name": "endpoint",
"title": "Endpoint data source",
"description": "Interact with the endpoint.",
"inputs": null,
"multiple": false
}
],
"download": "/epr/endpoint/endpoint-0.3.0.tar.gz",
"path": "/package/endpoint/0.3.0",
"latestVersion": "0.3.0",
"removable": false,
"status": "installed",
"savedObject": {
"id": "endpoint",
"type": "epm-packages",
"updated_at": "2020-06-23T21:44:59.319Z",
"version": "Wzk4LDFd",
"attributes": {
"installed": [
{
"id": "826759f0-7074-11ea-9bc8-6b38f4d29a16",
"type": "dashboard"
},
{
"id": "1cfceda0-728b-11ea-9bc8-6b38f4d29a16",
"type": "visualization"
},
{
"id": "1e525190-7074-11ea-9bc8-6b38f4d29a16",
"type": "visualization"
},
{
"id": "55387750-729c-11ea-9bc8-6b38f4d29a16",
"type": "visualization"
},
{
"id": "92b1edc0-706a-11ea-9bc8-6b38f4d29a16",
"type": "visualization"
},
{
"id": "a3a3bd10-706b-11ea-9bc8-6b38f4d29a16",
"type": "map"
},
{
"id": "events-endpoint",
"type": "index-template"
},
{
"id": "metrics-endpoint.metadata",
"type": "index-template"
},
{
"id": "metrics-endpoint.policy",
"type": "index-template"
},
{
"id": "metrics-endpoint.telemetry",
"type": "index-template"
}
],
"es_index_patterns": {
"events": "events-endpoint-*",
"metadata": "metrics-endpoint.metadata-*",
"policy": "metrics-endpoint.policy-*",
"telemetry": "metrics-endpoint.telemetry-*"
},
"name": "endpoint",
"version": "0.3.0",
"internal": false,
"removable": false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is a required package

},
"references": []
}
},
"success": true
}
}
}
}
Expand Down Expand Up @@ -3822,6 +4014,9 @@
},
"path": {
"type": "string"
},
"removable": {
"type": "boolean"
}
},
"required": [
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export interface RegistryPackage {
icons?: RegistryImage[];
assets?: string[];
internal?: boolean;
removable?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer coming from the Registry so remove from its type

format_version: string;
datasets?: Dataset[];
datasources?: RegistryDatasource[];
Expand Down Expand Up @@ -206,6 +205,7 @@ interface PackageAdditions {
title: string;
latestVersion: string;
assets: AssetsGroupedByServiceByType;
removable?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add to Ingest's Package type

}

// Managers public HTTP response types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SavedObjectsClientContract } from 'src/core/server';
import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants';
import { Installation, InstallationStatus, PackageInfo, KibanaAssetType } from '../../../types';
import * as Registry from '../registry';
import { createInstallableFrom } from './index';
import { createInstallableFrom, isRequiredPackage } from './index';

export { fetchFile as getFile, SearchParams } from '../registry';

Expand Down Expand Up @@ -79,17 +79,15 @@ export async function getPackageInfo(options: {
getInstallationObject({ savedObjectsClient, pkgName }),
Registry.fetchFindLatestPackage(pkgName),
Registry.getArchiveInfo(pkgName, pkgVersion),
] as const);
// adding `as const` due to regression in TS 3.7.2
// see https://github.com/microsoft/TypeScript/issues/34925#issuecomment-550021453
// and https://github.com/microsoft/TypeScript/pull/33707#issuecomment-550718523
]);

// add properties that aren't (or aren't yet) on Registry response
const updated = {
...item,
latestVersion: latestPackage.version,
title: item.title || nameAsTitle(item.name),
assets: Registry.groupPathsByService(assets || []),
removable: !isRequiredPackage(pkgName),
};
return createInstallableFrom(updated, savedObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ export {
export { installKibanaAssets, installPackage, ensureInstalledPackage } from './install';
export { removeInstallation } from './remove';

type RequiredPackage = 'system' | 'endpoint';
const requiredPackages: Record<RequiredPackage, boolean> = {
system: true,
endpoint: true,
};

export function isRequiredPackage(value: string): value is RequiredPackage {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This tests based only on the package name, not name + version. We can add versions in later if we need to

Copy link
Contributor

Choose a reason for hiding this comment

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

++

return value in requiredPackages;
}

export class PackageNotInstalledError extends Error {
constructor(pkgkey: string) {
super(`${pkgkey} is not installed`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { installIndexPatterns } from '../kibana/index_pattern/install';
import * as Registry from '../registry';
import { getObject } from './get_objects';
import { getInstallation, getInstallationObject } from './index';
import { getInstallation, getInstallationObject, isRequiredPackage } from './index';
import { installTemplates } from '../elasticsearch/template/install';
import { generateESIndexPatterns } from '../elasticsearch/template/template';
import { installPipelines } from '../elasticsearch/ingest_pipeline/install';
Expand Down Expand Up @@ -104,7 +104,8 @@ export async function installPackage(options: {
throw Boom.badRequest('Cannot install or update to an out-of-date package');

const reinstall = pkgVersion === installedPkg?.attributes.version;
const { internal = false, removable = true } = registryPackageInfo;
const removable = !isRequiredPackage(pkgName);
const { internal = false } = registryPackageInfo;

// delete the previous version's installation's SO kibana assets before installing new ones
// in case some assets were removed in the new version
Expand Down