Skip to content

Commit

Permalink
Prerelease toggle (elastic#143853)
Browse files Browse the repository at this point in the history
* WIP: prerelease toggle

* changed styling

* fixed switch

* auto upgrade and hiding button on callout if no ga available

* tweak prereleaseIntegrationsEnabled state to add undefined state in beginning

* fixing types and tests

* fixing types

* removed dummy endpoint package

* extracted hooks to avoid double loading of packages and categories

* prevent double loading of package details

* updated openapi

* fixing tests

* added try catch around loading settings in preconfig

* error handling on integrations, fixing cypress test with that

* reading prerelease from settings during package install

* fix tests

* fixing tests

* added back experimental as deprecated, fix more tests

* fixed issue in package details overview where nlatest version didnt show prerelease

* changed getPackageInfo to load prerelease from settings if not provided

* fixing tests, moved getSettings to bulk install fn

* fixing cypress and endpoint tests

* fix tests

* fix tests

* added back experimental flag in other plugins, as it is not exaclty the same as prerelease

* reverted mappings change in api_integration

* fixed prerelease condition, fix limited test, trying to fix field limit

* removed experimental flag from epr api call

* added unit test on version dropdown and prerelease callout, set field limit to 1500

* added UI package version check for prerelease disabled case

* fixed synthetics test

* extracted getSettings to a helper function

* removed using prerease setting in auto upgrades and install

* fixing tests, added back prerelease flag to install apis

* fixing a bug with version and release badge of installed integrations

* reload package in overview after loading prerelease setting, this is to show available upgrade if package is installed

* fixing tests by passing prerelease flag on apis

* fixing cypress test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
juliaElastic and kibanamachine authored Nov 2, 2022
1 parent 8be27cb commit 5431d1f
Show file tree
Hide file tree
Showing 66 changed files with 886 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"ingest-download-sources": "1e69dabd6db5e320fe08c5bda8f35f29bafc6b54",
"ingest-outputs": "29b867bf7bfd28b1e17c84697dce5c6d078f9705",
"ingest-package-policies": "e8707a8c7821ea085e67c2d213e24efa56307393",
"ingest_manager_settings": "bb71f20e36a9ac3a2e46d9345e2caa96e7bf8c22",
"ingest_manager_settings": "6f36714825cc15ea8d7cda06fde7851611a532b4",
"inventory-view": "bc2bd1e7ec7c186159447ab228d269f22bd39056",
"kql-telemetry": "29544cd7d3b767c5399878efae6bd724d24c03fd",
"legacy-url-alias": "7172dfd54f2e0c89fe263fd7095519b2d826a930",
Expand Down
58 changes: 57 additions & 1 deletion x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,35 @@
}
},
"operationId": "get-package-categories"
}
},
"parameters": [
{
"in": "query",
"name": "prerelease",
"schema": {
"type": "boolean",
"default": false
},
"description": "Whether to include prerelease packages in categories count (e.g. beta, rc, preview) "
},
{
"in": "query",
"name": "experimental",
"deprecated": true,
"schema": {
"type": "boolean",
"default": false
}
},
{
"in": "query",
"name": "include_policy_templates",
"schema": {
"type": "boolean",
"default": false
}
}
]
},
"/epm/packages/limited": {
"get": {
Expand Down Expand Up @@ -304,6 +332,31 @@
"default": false
},
"description": "Whether to exclude the install status of each package. Enabling this option will opt in to caching for the response via `cache-control` headers. If you don't need up-to-date installation info for a package, and are querying for a list of available packages, providing this flag can improve performance substantially."
},
{
"in": "query",
"name": "prerelease",
"schema": {
"type": "boolean",
"default": false
},
"description": "Whether to return prerelease versions of packages (e.g. beta, rc, preview) "
},
{
"in": "query",
"name": "experimental",
"deprecated": true,
"schema": {
"type": "boolean",
"default": false
}
},
{
"in": "query",
"name": "category",
"schema": {
"type": "string"
}
}
]
},
Expand Down Expand Up @@ -4206,6 +4259,9 @@
"items": {
"type": "string"
}
},
"prerelease_integrations_enabled": {
"type": "boolean"
}
},
"required": [
Expand Down
40 changes: 40 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ paths:
schema:
$ref: '#/components/schemas/get_categories_response'
operationId: get-package-categories
parameters:
- in: query
name: prerelease
schema:
type: boolean
default: false
description: >-
Whether to include prerelease packages in categories count (e.g. beta,
rc, preview)
- in: query
name: experimental
deprecated: true
schema:
type: boolean
default: false
- in: query
name: include_policy_templates
schema:
type: boolean
default: false
/epm/packages/limited:
get:
summary: Packages - Get limited list
Expand Down Expand Up @@ -196,6 +216,24 @@ paths:
headers. If you don't need up-to-date installation info for a package,
and are querying for a list of available packages, providing this flag
can improve performance substantially.
- in: query
name: prerelease
schema:
type: boolean
default: false
description: >-
Whether to return prerelease versions of packages (e.g. beta, rc,
preview)
- in: query
name: experimental
deprecated: true
schema:
type: boolean
default: false
- in: query
name: category
schema:
type: string
/epm/packages/_bulk:
post:
summary: Packages - Bulk install
Expand Down Expand Up @@ -2617,6 +2655,8 @@ components:
type: array
items:
type: string
prerelease_integrations_enabled:
type: boolean
required:
- fleet_server_hosts
- id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ properties:
type: array
items:
type: string
prerelease_integrations_enabled:
type: boolean
required:
- fleet_server_hosts
- id
19 changes: 19 additions & 0 deletions x-pack/plugins/fleet/common/openapi/paths/epm@categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,22 @@ get:
schema:
$ref: ../components/schemas/get_categories_response.yaml
operationId: get-package-categories
parameters:
- in: query
name: prerelease
schema:
type: boolean
default: false
description: >-
Whether to include prerelease packages in categories count (e.g. beta, rc, preview)
- in: query
name: experimental
deprecated: true
schema:
type: boolean
default: false
- in: query
name: include_policy_templates
schema:
type: boolean
default: false
17 changes: 17 additions & 0 deletions x-pack/plugins/fleet/common/openapi/paths/epm@packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ parameters:
caching for the response via `cache-control` headers. If you don't need up-to-date installation
info for a package, and are querying for a list of available packages, providing this flag can
improve performance substantially.
- in: query
name: prerelease
schema:
type: boolean
default: false
description: >-
Whether to return prerelease versions of packages (e.g. beta, rc, preview)
- in: query
name: experimental
deprecated: true
schema:
type: boolean
default: false
- in: query
name: category
schema:
type: string
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { SavedObjectAttributes } from '@kbn/core/public';
export interface BaseSettings {
has_seen_add_data_notice?: boolean;
fleet_server_hosts?: string[];
prerelease_integrations_enabled: boolean;
}

export interface Settings extends BaseSettings {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/common/types/rest_spec/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import type {

export interface GetCategoriesRequest {
query: {
// deprecated in 8.6
experimental?: boolean;
prerelease?: boolean;
include_policy_templates?: boolean;
};
}
Expand All @@ -31,7 +33,9 @@ export interface GetCategoriesResponse {
export interface GetPackagesRequest {
query: {
category?: string;
// deprecated in 8.6
experimental?: boolean;
prerelease?: boolean;
excludeInstallStatus?: boolean;
};
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/cypress/e2e/install_assets.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Install unverified package assets', () => {
}).as('installAssets');

// save mocking out the whole package response, but make it so that fleet server is always uninstalled
cy.intercept('GET', '/api/fleet/epm/packages/fleet_server', (req) => {
cy.intercept('GET', '/api/fleet/epm/packages/fleet_server*', (req) => {
req.continue((res) => {
if (res.body?.item?.savedObject) {
delete res.body.item.savedObject;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/cypress/e2e/integrations_mock.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Add Integration - Mock API', () => {
const oldVersion = '0.3.3';
const newVersion = '1.3.4';
beforeEach(() => {
cy.intercept('/api/fleet/epm/packages?experimental=true', {
cy.intercept('/api/fleet/epm/packages?prerelease=true', {
items: [
{
name: 'apache',
Expand All @@ -28,7 +28,7 @@ describe('Add Integration - Mock API', () => {
],
});

cy.intercept(`/api/fleet/epm/packages/apache/${oldVersion}`, {
cy.intercept(`/api/fleet/epm/packages/apache/${oldVersion}*`, {
item: {
name: 'apache',
version: oldVersion,
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Add Integration - Mock API', () => {

cy.getBySel(INTEGRATION_POLICIES_UPGRADE_CHECKBOX).uncheck({ force: true });

cy.intercept(`/api/fleet/epm/packages/apache/${newVersion}`, {
cy.intercept(`/api/fleet/epm/packages/apache/${newVersion}*`, {
item: {
name: 'apache',
version: newVersion,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('Add Integration - Real API', () => {
setupIntegrations();
cy.getBySel(getIntegrationCategories('aws')).click();
cy.getBySel(INTEGRATIONS_SEARCHBAR.BADGE).contains('AWS').should('exist');
cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length', 30);
cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length', 28);

cy.getBySel(INTEGRATIONS_SEARCHBAR.INPUT).clear().type('Cloud');
cy.getBySel(INTEGRATION_LIST).find('.euiCard').should('have.length', 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { queryClient } from '..';
import { pkgKeyFromPackageInfo } from '../../../services';

const fetchInstalledIntegrations = async () => {
const response = await sendGetPackages({ experimental: true });
const response = await sendGetPackages({ prerelease: true });

if (response.error) {
throw new Error(response.error.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export * from './use_agent_policy_context';
export * from './use_integrations_state';
export * from './use_confirm_force_install';
export * from './use_confirm_open_unverified';
export * from './use_packages';
export * from './use_categories';
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { useEffect, useCallback, useState } from 'react';

import type { RequestError } from '../../fleet/hooks';
import { sendGetCategories } from '../../fleet/hooks';
import type { GetCategoriesResponse } from '../types';

export function useCategories(prerelease?: boolean) {
const [data, setData] = useState<GetCategoriesResponse | undefined>();
const [error, setError] = useState<RequestError | undefined>();
const [isLoading, setIsLoading] = useState(false);
const [isPrereleaseEnabled, setIsPrereleaseEnabled] = useState(prerelease);

const fetchData = useCallback(async () => {
if (prerelease === undefined) {
return;
}
if (isPrereleaseEnabled === prerelease) {
return;
}
setIsPrereleaseEnabled(prerelease);
setIsLoading(true);
try {
const res = await sendGetCategories({
include_policy_templates: true,
prerelease,
});
if (res.error) {
throw res.error;
}
if (res.data) {
setData(res.data);
}
} catch (err) {
setError(err);
}
setIsLoading(false);
}, [prerelease, isPrereleaseEnabled]);

useEffect(() => {
fetchData();
}, [fetchData]);

return {
data,
error,
isLoading,
};
}
Loading

0 comments on commit 5431d1f

Please sign in to comment.