Skip to content

Commit

Permalink
Merge branch 'main' into serverless/plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
clintandrewhall authored Apr 26, 2023
2 parents 6d8044f + 6690c44 commit 06c74bc
Show file tree
Hide file tree
Showing 90 changed files with 989 additions and 257 deletions.
3 changes: 1 addition & 2 deletions .buildkite/disabled_jest_configs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[
"x-pack/plugins/watcher/jest.config.js",
"src/core/server/integration_tests/ui_settings/jest.integration.config.js"
"x-pack/plugins/watcher/jest.config.js"
]
6 changes: 3 additions & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ packages/core/usage-data/core-usage-data-base-server-internal @elastic/kibana-co
packages/core/usage-data/core-usage-data-server @elastic/kibana-core
packages/core/usage-data/core-usage-data-server-internal @elastic/kibana-core
packages/core/usage-data/core-usage-data-server-mocks @elastic/kibana-core
packages/core/user-settings/core-user-settings-server @elastic/platform-security
packages/core/user-settings/core-user-settings-server-internal @elastic/platform-security
packages/core/user-settings/core-user-settings-server-mocks @elastic/platform-security
packages/core/user-settings/core-user-settings-server @elastic/kibana-security
packages/core/user-settings/core-user-settings-server-internal @elastic/kibana-security
packages/core/user-settings/core-user-settings-server-mocks @elastic/kibana-security
x-pack/plugins/cross_cluster_replication @elastic/platform-deployment-management
packages/kbn-crypto @elastic/kibana-security
packages/kbn-crypto-browser @elastic/kibana-core
Expand Down
14 changes: 14 additions & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@ xpack.security.showNavLinks: false
xpack.serverless.plugin.enabled: true
xpack.fleet.enableExperimental: ['fleetServerStandalone']
xpack.fleet.internal.disableILMPolicies: true

# Management team plugins
xpack.upgrade_assistant.enabled: false
xpack.rollup.enabled: false
xpack.watcher.enabled: false
xpack.ccr.enabled: false
xpack.ilm.enabled: false
xpack.remote_clusters.enabled: false
xpack.snapshot_restore.enabled: false
xpack.license_management.enabled: false

# Other disabled plugins
xpack.canvas.enabled: false
xpack.reporting.enabled: false
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/core-user-settings-server-internal",
"owner": "@elastic/platform-security",
"owner": "@elastic/kibana-security",
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/core-user-settings-server-mocks",
"owner": "@elastic/platform-security",
"owner": "@elastic/kibana-security",
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/core-user-settings-server",
"owner": "@elastic/platform-security",
"owner": "@elastic/kibana-security",
}
8 changes: 4 additions & 4 deletions packages/kbn-test/src/functional_tests/run_tests/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ export function parseFlags(flags: FlagsReader) {
installDir: flags.path('kibana-install-dir'),
grep: flags.string('grep'),
suiteTags: {
include: flags.arrayOfStrings('include-tag'),
exclude: flags.arrayOfStrings('exclude-tag'),
include: flags.arrayOfStrings('include-tag') ?? [],
exclude: flags.arrayOfStrings('exclude-tag') ?? [],
},
suiteFilters: {
include: flags.arrayOfPaths('include'),
exclude: flags.arrayOfPaths('exclude'),
include: flags.arrayOfPaths('include') ?? [],
exclude: flags.arrayOfPaths('exclude') ?? [],
},
};
}
23 changes: 22 additions & 1 deletion packages/kbn-test/src/functional_tests/run_tests/run_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,35 @@ export async function runTests(log: ToolingLog, options: RunTestsOptions) {
log.warning('❗️❗️❗️');
}

const settingOverrides = {
mochaOpts: {
bail: options.bail,
dryRun: options.dryRun,
grep: options.grep,
},
kbnTestServer: {
installDir: options.installDir,
},
suiteFiles: {
include: options.suiteFilters.include,
exclude: options.suiteFilters.exclude,
},
suiteTags: {
include: options.suiteTags.include,
exclude: options.suiteTags.exclude,
},
updateBaselines: options.updateBaselines,
updateSnapshots: options.updateSnapshots,
};

for (const [i, path] of options.configs.entries()) {
await log.indent(0, async () => {
if (options.configs.length > 1) {
const progress = `${i + 1}/${options.configs.length}`;
log.write(`--- [${progress}] Running ${Path.relative(REPO_ROOT, path)}`);
}

const config = await readConfigFile(log, options.esVersion, path);
const config = await readConfigFile(log, options.esVersion, path, settingOverrides);

const hasTests = await checkForEnabledTestsInFtrConfig({
config,
Expand Down
39 changes: 26 additions & 13 deletions x-pack/plugins/alerting/public/application/maintenance_windows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { Suspense } from 'react';
import ReactDOM from 'react-dom';
import { Redirect, Router, Switch } from 'react-router-dom';
import { Router, Switch } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Route } from '@kbn/shared-ux-router';
import { CoreStart } from '@kbn/core/public';
Expand All @@ -18,6 +18,7 @@ import { ManagementAppMountParams } from '@kbn/management-plugin/public';
import { EuiLoadingSpinner } from '@elastic/eui';
import { AlertingPluginStart } from '../plugin';
import { paths } from '../config';
import { useLicense } from '../hooks/use_license';

const MaintenanceWindowsLazy: React.FC = React.lazy(() => import('../pages/maintenance_windows'));
const MaintenanceWindowsCreateLazy: React.FC = React.lazy(
Expand All @@ -28,27 +29,39 @@ const MaintenanceWindowsEditLazy: React.FC = React.lazy(
);

const App = React.memo(() => {
const { isAtLeastPlatinum } = useLicense();
const hasLicense = isAtLeastPlatinum();

return (
<>
<Switch>
<Route path="/" exact>
<Suspense fallback={<EuiLoadingSpinner />}>
<MaintenanceWindowsLazy />
</Suspense>
</Route>
<Route path={paths.alerting.maintenanceWindowsCreate} exact>
<Switch>
{hasLicense ? (
<Route
key={paths.alerting.maintenanceWindowsCreate}
path={paths.alerting.maintenanceWindowsCreate}
exact
>
<Suspense fallback={<EuiLoadingSpinner />}>
<MaintenanceWindowsCreateLazy />
</Suspense>
</Route>
<Route path={paths.alerting.maintenanceWindowsEdit} exact>
) : null}
{hasLicense ? (
<Route
key={paths.alerting.maintenanceWindowsEdit}
path={paths.alerting.maintenanceWindowsEdit}
exact
>
<Suspense fallback={<EuiLoadingSpinner />}>
<MaintenanceWindowsEditLazy />
</Suspense>
</Route>
<Redirect from={'/edit'} to="/" />
</Switch>
</>
) : null}
<Route>
<Suspense fallback={<EuiLoadingSpinner />}>
<MaintenanceWindowsLazy />
</Suspense>
</Route>
</Switch>
);
});
App.displayName = 'App';
Expand Down
55 changes: 55 additions & 0 deletions x-pack/plugins/alerting/public/hooks/use_license.test.tsx
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 { licensingMock } from '@kbn/licensing-plugin/public/mocks';
import { renderHook } from '@testing-library/react-hooks';
import { useLicense } from './use_license';
import { AppMockRenderer, createAppMockRenderer } from '../lib/test_utils';

let appMockRenderer: AppMockRenderer;

describe('useLicense', () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe('isAtLeastPlatinum', () => {
it('returns true on a valid platinum license', () => {
const license = licensingMock.createLicense({
license: { type: 'platinum' },
});
appMockRenderer = createAppMockRenderer({ license });

const { result } = renderHook(
() => {
return useLicense();
},
{
wrapper: appMockRenderer.AppWrapper,
}
);

expect(result.current.isAtLeastPlatinum()).toBeTruthy();
});

it('returns false on a valid gold license', () => {
const license = licensingMock.createLicense({
license: { type: 'gold' },
});
appMockRenderer = createAppMockRenderer({ license });

const { result } = renderHook(
() => {
return useLicense();
},
{ wrapper: appMockRenderer.AppWrapper }
);

expect(result.current.isAtLeastPlatinum()).toBeFalsy();
});
});
});
34 changes: 34 additions & 0 deletions x-pack/plugins/alerting/public/hooks/use_license.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 type { ILicense, LicenseType } from '@kbn/licensing-plugin/public';
import { useCallback } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { Observable } from 'rxjs';
import { useKibana } from '../utils/kibana_react';

interface UseLicenseReturnValue {
isAtLeastPlatinum: () => boolean;
}

export const useLicense = (): UseLicenseReturnValue => {
const { licensing } = useKibana().services;
const license = useObservable<ILicense | null>(licensing?.license$ ?? new Observable(), null);

const isAtLeast = useCallback(
(level: LicenseType): boolean => {
return !!license && license.isAvailable && license.isActive && license.hasAtLeast(level);
},
[license]
);

const isAtLeastPlatinum = useCallback(() => isAtLeast('platinum'), [isAtLeast]);

return {
isAtLeastPlatinum,
};
};
20 changes: 17 additions & 3 deletions x-pack/plugins/alerting/public/lib/test_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,37 @@
*/

import React from 'react';
import { of } from 'rxjs';
import { of, BehaviorSubject } from 'rxjs';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { I18nProvider } from '@kbn/i18n-react';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { render as reactRender, RenderOptions, RenderResult } from '@testing-library/react';
import { CoreStart } from '@kbn/core/public';
import { coreMock } from '@kbn/core/public/mocks';
import { euiDarkVars } from '@kbn/ui-theme';
import type { ILicense } from '@kbn/licensing-plugin/public';
import { licensingMock } from '@kbn/licensing-plugin/public/mocks';

/* eslint-disable no-console */

type UiRender = (ui: React.ReactElement, options?: RenderOptions) => RenderResult;

interface AppMockRendererArgs {
license?: ILicense | null;
}

export interface AppMockRenderer {
render: UiRender;
coreStart: CoreStart;
queryClient: QueryClient;
AppWrapper: React.FC<{ children: React.ReactElement }>;
}

export const createAppMockRenderer = (): AppMockRenderer => {
export const createAppMockRenderer = ({ license }: AppMockRendererArgs = {}): AppMockRenderer => {
const theme$ = of({ eui: euiDarkVars, darkMode: true });

const licensingPluginMock = licensingMock.createStart();

const queryClient = new QueryClient({
defaultOptions: {
queries: {
Expand All @@ -46,7 +54,13 @@ export const createAppMockRenderer = (): AppMockRenderer => {
},
});
const core = coreMock.createStart();
const services = { ...core };
const services = {
...core,
licensing:
license != null
? { ...licensingPluginMock, license$: new BehaviorSubject(license) }
: licensingPluginMock,
};
const AppWrapper: React.FC<{ children: React.ReactElement }> = React.memo(({ children }) => (
<I18nProvider>
<KibanaThemeProvider theme$={theme$}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 React from 'react';
import { AppMockRenderer, createAppMockRenderer } from '../../../lib/test_utils';
import { LicensePrompt } from './license_prompt';

describe('LicensePrompt', () => {
let appMockRenderer: AppMockRenderer;

beforeEach(() => {
jest.clearAllMocks();
appMockRenderer = createAppMockRenderer();
});

test('it renders', () => {
const result = appMockRenderer.render(<LicensePrompt />);

expect(result.getByTestId('license-prompt-title')).toBeInTheDocument();
expect(result.getByTestId('license-prompt-upgrade')).toBeInTheDocument();
expect(result.getByTestId('license-prompt-trial')).toBeInTheDocument();
});
});
Loading

0 comments on commit 06c74bc

Please sign in to comment.