Skip to content

Commit

Permalink
Move real plugins out of 'fixtures' dirs (#148756)
Browse files Browse the repository at this point in the history
The location of plugins was previously somewhat irrelevant, but as we
move into packages it's more important that we can find all plugins in
the repository, and we would like to be able to do that without needing
to maintain a manifest somewhere to accomplish this. In order to make
this possible we plan to find any plugin/package by spotting all
kibana.json files which are not "fixtures". This allows plugin-like code
(but not actual plugin code) to exist for testing purposes, but it must
be within some form of "fixtures" directory, and any plugin that isn't
in a fixtures directory will be automatically pulled into the system
(though test plugins, examples, etc. will still only be loaded when the
plugin's path is passed via `--plugin-path`, the system will know about
them and use that knowledge for other things).

Since this is just a rename Operations will review and merge by EOD Jan
12th unless someone has a blocking concern.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
Spencer and kibanamachine authored Jan 12, 2023
1 parent ce026d3 commit c8f83ed
Show file tree
Hide file tree
Showing 234 changed files with 312 additions and 246 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
/x-pack/test/plugin_api_integration/test_suites/task_manager/ @elastic/response-ops
/x-pack/plugins/triggers_actions_ui/ @elastic/response-ops
/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/ @elastic/response-ops
/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/ @elastic/response-ops
/x-pack/test/functional_with_es_ssl/plugins/alerts/ @elastic/response-ops
/docs/user/alerting/ @elastic/response-ops
/docs/management/connectors/ @elastic/response-ops
/x-pack/plugins/stack_alerts/ @elastic/response-ops
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ fleet-server.yml
/packages/kbn-synthetic-package-map/
**/.synthetics/
**/.journeys/
x-pack/test/security_api_integration/plugins/audit_log/audit.log
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function validateProjectOwnership(
if (isNotInTsProject.length) {
failed = true;
log.error(
`The following files do not belong to a tsconfig.json file, or that tsconfig.json file is not listed in packages/kbn-ts-projects/projects.ts\n${isNotInTsProject
`The following files do not belong to a tsconfig.json file\n${isNotInTsProject
.map((file) => ` - ${file.repoRel}`)
.join('\n')}`
);
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-plugin-discovery/src/plugin_search_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ function getPluginSearchPaths({ rootDir, oss, examples, testPlugins }) {
resolve(rootDir, '..', 'kibana-extra'),
...(testPlugins
? [
resolve(rootDir, 'test/analytics/fixtures/plugins'),
resolve(rootDir, 'test/analytics/plugins'),
resolve(rootDir, 'test/health_gateway/plugins'),
resolve(rootDir, 'test/plugin_functional/plugins'),
resolve(rootDir, 'test/interpreter_functional/plugins'),
resolve(rootDir, 'test/common/fixtures/plugins'),
resolve(rootDir, 'test/server_integration/__fixtures__/plugins'),
resolve(rootDir, 'test/common/plugins'),
resolve(rootDir, 'test/server_integration/plugins'),
]
: []),
...(testPlugins && !oss
? [
resolve(rootDir, 'x-pack/test/plugin_functional/plugins'),
resolve(rootDir, 'x-pack/test/functional_with_es_ssl/fixtures/plugins'),
resolve(rootDir, 'x-pack/test/functional_with_es_ssl/plugins'),
resolve(rootDir, 'x-pack/test/alerting_api_integration/plugins'),
resolve(rootDir, 'x-pack/test/plugin_api_integration/plugins'),
resolve(rootDir, 'x-pack/test/plugin_api_perf/plugins'),
resolve(rootDir, 'x-pack/test/licensing_plugin/plugins'),
resolve(rootDir, 'x-pack/test/usage_collection/plugins'),
resolve(rootDir, 'x-pack/test/security_functional/fixtures/common'),
resolve(rootDir, 'x-pack/test/security_functional/plugins'),
]
: []),
];
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-telemetry-tools/src/tools/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import * as path from 'path';
import { REPO_ROOT } from '@kbn/repo-info';
import { parseTelemetryRC } from './config';

describe('parseTelemetryRC', () => {
Expand All @@ -16,7 +17,7 @@ describe('parseTelemetryRC', () => {
});

it('returns parsed rc file', async () => {
const configRoot = path.join(process.cwd(), 'src', 'fixtures', 'telemetry_collectors');
const configRoot = path.resolve(REPO_ROOT, 'src/fixtures/telemetry_collectors');
const config = await parseTelemetryRC(configRoot);
expect(config).toStrictEqual([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import * as ts from 'typescript';
import * as path from 'path';
import { REPO_ROOT } from '@kbn/repo-info';
import { extractCollectors, getProgramPaths } from './extract_collectors';
import { parseTelemetryRC } from './config';
import { allExtractedCollectors } from './__fixture__/all_extracted_collectors';

describe('extractCollectors', () => {
it('extracts collectors given rc file', async () => {
const configRoot = path.join(process.cwd(), 'src', 'fixtures', 'telemetry_collectors');
const configRoot = path.join(REPO_ROOT, 'src/fixtures/telemetry_collectors');
const tsConfig = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json');
if (!tsConfig) {
throw new Error('Could not find a valid tsconfig.json.');
Expand Down
8 changes: 3 additions & 5 deletions packages/kbn-telemetry-tools/src/tools/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@

import * as ts from 'typescript';
import * as path from 'path';
import { REPO_ROOT } from '@kbn/repo-info';
import { getDescriptor, TelemetryKinds } from './serializer';
import { traverseNodes } from './ts_parser';
import { compilerHost } from './compiler_host';

export function loadFixtureProgram(fixtureName: string) {
const fixturePath = path.resolve(
process.cwd(),
'src',
'fixtures',
'telemetry_collectors',
`${fixtureName}.ts`
REPO_ROOT,
`src/fixtures/telemetry_collectors/${fixtureName}.ts`
);
const tsConfig = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json');
if (!tsConfig) {
Expand Down
9 changes: 2 additions & 7 deletions packages/kbn-telemetry-tools/src/tools/ts_parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { parseUsageCollection } from './ts_parser';
import * as ts from 'typescript';
import * as path from 'path';
import { REPO_ROOT } from '@kbn/repo-info';
import { compilerHost } from './compiler_host';
import { parsedWorkingCollector } from './__fixture__/parsed_working_collector';
import { parsedNestedCollector } from './__fixture__/parsed_nested_collector';
Expand All @@ -20,13 +21,7 @@ import { parsedStatsCollector } from './__fixture__/parsed_stats_collector';
import { parsedImportedInterfaceFromExport } from './__fixture__/parsed_imported_interface_from_export';

export function loadFixtureProgram(fixtureName: string) {
const fixturePath = path.resolve(
process.cwd(),
'src',
'fixtures',
'telemetry_collectors',
`${fixtureName}`
);
const fixturePath = path.resolve(REPO_ROOT, `src/fixtures/telemetry_collectors/${fixtureName}`);
const tsConfig = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json');
if (!tsConfig) {
throw new Error('Could not find a valid tsconfig.json.');
Expand Down
2 changes: 1 addition & 1 deletion test/analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ expect(events).to...

If you are reusing these helpers in another suite, please remember to make sure to optIn via `await getService('kibana_ebt_ui').setOptIn(true);`

Refer to [`EBTHelpersContract`](./fixtures/plugins/analytics_ftr_helpers/common/types.ts#:~:text=EBTHelpersContract) for more details about the existing APIs and all the options they accept.
Refer to [`EBTHelpersContract`](./plugins/analytics_ftr_helpers/common/types.ts#:~:text=EBTHelpersContract) for more details about the existing APIs and all the options they accept.
4 changes: 2 additions & 2 deletions test/analytics/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
serverArgs: [
...functionalConfig.get('kbnTestServer.serverArgs'),
'--telemetry.optIn=true',
`--plugin-path=${path.resolve(__dirname, './fixtures/plugins/analytics_plugin_a')}`,
`--plugin-path=${path.resolve(__dirname, './fixtures/plugins/analytics_ftr_helpers')}`,
`--plugin-path=${path.resolve(__dirname, './plugins/analytics_plugin_a')}`,
`--plugin-path=${path.resolve(__dirname, './plugins/analytics_ftr_helpers')}`,
],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

module.exports = {
preset: '@kbn/test',
rootDir: '../../../../..',
roots: ['<rootDir>/test/analytics/fixtures/plugins/analytics_ftr_helpers'],
rootDir: '../../../..',
roots: ['<rootDir>/test/analytics/plugins/analytics_ftr_helpers'],
coverageDirectory:
'<rootDir>/target/kibana-coverage/jest/test/analytics/fixtures/plugins/analytics_ftr_helpers',
'<rootDir>/target/kibana-coverage/jest/test/analytics/plugins/analytics_ftr_helpers',
coverageReporters: ['text', 'html'],
collectCoverageFrom: [
'<rootDir>/test/analytics/fixtures/plugins/analytics_ftr_helpers/{common,public,server}/**/*.{ts,tsx}',
'<rootDir>/test/analytics/plugins/analytics_ftr_helpers/{common,public,server}/**/*.{ts,tsx}',
],
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "analytics_ftr_helpers",
"version": "1.0.0",
"main": "target/test/analytics/fixtures/plugins/analytics_ftr_helpers",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../../../../tsconfig.base.json",
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
},
Expand All @@ -8,7 +8,7 @@
"common/**/*.ts",
"public/**/*.ts",
"server/**/*.ts",
"../../../../../typings/**/*",
"../../../../typings/**/*",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "analytics_plugin_a",
"version": "1.0.0",
"main": "target/test/analytics/fixtures/plugins/analytics_plugin_a",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"extends": "../../../../../tsconfig.base.json",
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
},
"include": [
"index.ts",
"public/**/*.ts",
"server/**/*.ts",
"../../../../../typings/**/*",
"../../../../typings/**/*",
],
"exclude": [
"target/**/*",
Expand Down
4 changes: 2 additions & 2 deletions test/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default function () {
'--telemetry.sendUsageTo=staging',
`--server.maxPayload=1679958`,
// newsfeed mock service
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'newsfeed')}`,
`--plugin-path=${path.join(__dirname, 'plugins', 'newsfeed')}`,
// otel mock service
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'otel_metrics')}`,
`--plugin-path=${path.join(__dirname, 'plugins', 'otel_metrics')}`,
`--newsfeed.service.urlRoot=${servers.kibana.protocol}://${servers.kibana.hostname}:${servers.kibana.port}`,
`--newsfeed.service.pathTemplate=/api/_newsfeed-FTS-external-service-simulators/kibana/v{VERSION}.json`,
`--logging.appenders.deprecation=${JSON.stringify({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "newsfeedFixtures",
"id": "newsfeedTestPlugin",
"owner": {
"name": "Core",
"githubTeam": "kibana-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class NewsFeedSimulatorPlugin implements Plugin {
items: [
{
title: { en: `You are functionally testing the newsfeed widget with fixtures!` },
description: { en: 'See test/common/fixtures/plugins/newsfeed/newsfeed_simulation' },
description: { en: 'See test/common/plugins/newsfeed/newsfeed_simulation' },
link_text: { en: 'Generic feed-viewer could go here' },
link_url: { en: 'https://feeds.elastic.co' },
languages: null,
Expand Down
16 changes: 16 additions & 0 deletions test/common/plugins/newsfeed/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types"
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*",
],
"kbn_references": [
"@kbn/core",
]
}
16 changes: 16 additions & 0 deletions test/common/plugins/otel_metrics/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types"
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*",
],
"kbn_references": [
"@kbn/core",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { services } from './services';
export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const xPackAPITestsConfig = await readConfigFile(require.resolve('../api_integration/config'));

const testEndpointsPlugin = resolve(__dirname, './fixtures/test_endpoints');
const testEndpointsPlugin = resolve(__dirname, './plugins/test_endpoints');

const tempKibanaYamlFile = join(getDataPath(), `interactive_setup_kibana_${Date.now()}.yml`);
await fs.writeFile(tempKibanaYamlFile, '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {

const testEndpointsPlugin = resolve(
__dirname,
'../interactive_setup_api_integration/fixtures/test_endpoints'
'../interactive_setup_api_integration/plugins/test_endpoints'
);

const tempKibanaYamlFile = join(getDataPath(), `interactive_setup_kibana_${Date.now()}.yml`);
Expand Down
6 changes: 3 additions & 3 deletions test/scripts/jenkins_build_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ node scripts/build_kibana_platform_plugins \
--scan-dir "$KIBANA_DIR/test/plugin_functional/plugins" \
--scan-dir "$KIBANA_DIR/test/health_gateway/plugins" \
--scan-dir "$KIBANA_DIR/test/interpreter_functional/plugins" \
--scan-dir "$KIBANA_DIR/test/common/fixtures/plugins" \
--scan-dir "$KIBANA_DIR/test/common/plugins" \
--scan-dir "$KIBANA_DIR/examples" \
--scan-dir "$KIBANA_DIR/test/plugin_functional/plugins" \
--scan-dir "$KIBANA_DIR/test/common/fixtures/plugins" \
--scan-dir "$KIBANA_DIR/test/common/plugins" \
--scan-dir "$XPACK_DIR/test/plugin_functional/plugins" \
--scan-dir "$XPACK_DIR/test/functional_with_es_ssl/fixtures/plugins" \
--scan-dir "$XPACK_DIR/test/functional_with_es_ssl/plugins" \
--scan-dir "$XPACK_DIR/test/alerting_api_integration/plugins" \
--scan-dir "$XPACK_DIR/test/plugin_api_integration/plugins" \
--scan-dir "$XPACK_DIR/test/plugin_api_perf/plugins" \
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/jenkins_xpack_build_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ source src/dev/ci_setup/setup_env.sh
echo " -> building kibana platform plugins"
node scripts/build_kibana_platform_plugins \
--scan-dir "$KIBANA_DIR/test/plugin_functional/plugins" \
--scan-dir "$KIBANA_DIR/test/common/fixtures/plugins" \
--scan-dir "$KIBANA_DIR/test/common/plugins" \
--scan-dir "$XPACK_DIR/test/plugin_functional/plugins" \
--scan-dir "$XPACK_DIR/test/functional_with_es_ssl/fixtures/plugins" \
--scan-dir "$XPACK_DIR/test/functional_with_es_ssl/plugins" \
--scan-dir "$XPACK_DIR/test/alerting_api_integration/plugins" \
--scan-dir "$XPACK_DIR/test/plugin_api_integration/plugins" \
--scan-dir "$XPACK_DIR/test/plugin_api_perf/plugins" \
Expand Down
13 changes: 4 additions & 9 deletions test/server_integration/http/platform/config.status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import { FtrConfigProviderContext } from '@kbn/test';
export default async function ({ readConfigFile }: FtrConfigProviderContext) {
const httpConfig = await readConfigFile(require.resolve('../../config.base.js'));

// Find all folders in __fixtures__/plugins since we treat all them as plugin folder
const allFiles = fs.readdirSync(path.resolve(__dirname, '../../__fixtures__/plugins'));
const plugins = allFiles.filter((file) =>
fs.statSync(path.resolve(__dirname, '../../__fixtures__/plugins', file)).isDirectory()
);
// Find all folders in plugins since we treat all them as plugin folder
const pluginDir = path.resolve(__dirname, '../../plugins');
const pluginsDirs = fs.readdirSync(pluginDir).map((name) => path.resolve(pluginDir, name));

return {
testFiles: [
Expand All @@ -43,10 +41,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
...httpConfig.get('kbnTestServer'),
serverArgs: [
...httpConfig.get('kbnTestServer.serverArgs'),
...plugins.map(
(pluginDir) =>
`--plugin-path=${path.resolve(__dirname, '../../__fixtures__/plugins', pluginDir)}`
),
...pluginsDirs.map((p) => `--plugin-path=${p}`),
],
runOptions: {
...httpConfig.get('kbnTestServer.runOptions'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "status_plugin_a",
"version": "1.0.0",
"main": "target/test/server_integration/__fixtures__/plugins/status_plugin_a",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"extends": "../../../../../tsconfig.base.json",
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
},
"include": [
"index.ts",
"server/**/*.ts",
"../../../../../../typings/**/*",
"../../../../typings/**/*",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "status_plugin_b",
"version": "1.0.0",
"main": "target/test/server_integration/__fixtures__/plugins/status_plugin_b",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"extends": "../../../../../tsconfig.base.json",
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types"
},
"include": [
"index.ts",
"server/**/*.ts",
"../../../../../typings/**/*",
"../../../../typings/**/*",
],
"exclude": [
"target/**/*",
Expand Down
Loading

0 comments on commit c8f83ed

Please sign in to comment.