Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into actions/executi…
Browse files Browse the repository at this point in the history
…on-source
  • Loading branch information
ymao1 committed Mar 8, 2023
2 parents 6b3609b + 1853f7a commit 0318ba9
Show file tree
Hide file tree
Showing 93 changed files with 650 additions and 2,193 deletions.
10 changes: 5 additions & 5 deletions docs/index-custom-title-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ <h2>Bring your data to life</h2>
</div>
</div>

<h3>Explore by use case</h3>
<h3>Explore by Elastic solution</h3>

<div class="row my-4">
<div class="col-md-4 col-12 mb-2">
<a class="no-text-decoration" href="https://www.elastic.co/guide/en/enterprise-search/current/start.html">
<div class="card h-100">
<h4 class="mt-3">
<span class="inline-block float-left icon mr-2" style="background-image: url('https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/blt11200907c1c033aa/634d9da119d8652169cf9b2b/enterprise-search-logo-color-32px.png');"></span>
Search my data
Enterprise Search
</h4>
<p>Create search experiences for your content, wherever it lives.</p>
</div>
Expand All @@ -90,9 +90,9 @@ <h4 class="mt-3">
<div class="card h-100">
<h4 class="mt-3">
<span class="inline-block float-left icon mr-2" style="background-image: url('https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/bltaa08b370a00bbecc/634d9da14e565f1cdce27f7c/observability-logo-color-32px.png');"></span>
Observe my data
Observability
</h4>
<p>Follow our guides to monitor logs, metrics, and traces.</p>
<p>Learn how to monitor logs, metrics, and traces.</p>
</div>
</a>
</div>
Expand All @@ -101,7 +101,7 @@ <h4 class="mt-3">
<div class="card h-100">
<h4 class="mt-3">
<span class="inline-block float-left icon mr-2" style="background-image: url('https://images.contentstack.io/v3/assets/bltefdd0b53724fa2ce/blt5e0e0ad9a13e6b8c/634d9da18473831f96bbdf1e/security-logo-color-32px.png');"></span>
Protect my environment
Security
</h4>
<p>Learn how to defend against threats across your environment.</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@
"usng.js": "^0.4.5",
"utility-types": "^3.10.0",
"uuid": "9.0.0",
"vega": "^5.23.0",
"vega": "5.22.1",
"vega-interpreter": "^1.0.4",
"vega-lite": "^5.5.0",
"vega-schema-url-parser": "^2.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const rolesConfig = schema.arrayOf(
]),
{
defaultValue: [NODE_WILDCARD_CHAR],
minSize: 1,
validate: (value) => {
if (value.length > 1) {
if (value.includes(NODE_WILDCARD_CHAR)) {
Expand All @@ -51,7 +52,6 @@ export const rolesConfig = schema.arrayOf(
}
}
},
minSize: 1,
}
);

Expand Down
13 changes: 8 additions & 5 deletions packages/core/root/core-root-server-internal/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getPackages } from '@kbn/repo-packages';
import { CliArgs, Env, RawConfigService } from '@kbn/config';
import { CriticalError } from '@kbn/core-base-server-internal';
import { Root } from './root';
import { MIGRATION_EXCEPTION_CODE } from './constants';

interface BootstrapArgs {
configs: string[];
Expand Down Expand Up @@ -114,11 +115,13 @@ export async function bootstrap({ configs, cliArgs, applyConfigOverrides }: Boot

function onRootShutdown(reason?: any) {
if (reason !== undefined) {
// There is a chance that logger wasn't configured properly and error that
// that forced root to shut down could go unnoticed. To prevent this we always
// mirror such fatal errors in standard output with `console.error`.
// eslint-disable-next-line no-console
console.error(`\n${chalk.white.bgRed(' FATAL ')} ${reason}\n`);
if (reason.code !== MIGRATION_EXCEPTION_CODE) {
// There is a chance that logger wasn't configured properly and error that
// that forced root to shut down could go unnoticed. To prevent this we always
// mirror such fatal errors in standard output with `console.error`.
// eslint-disable-next-line no-console
console.error(`\n${chalk.white.bgRed(' FATAL ')} ${reason}\n`);
}

process.exit(reason instanceof CriticalError ? reason.processExitCode : 1);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/core/root/core-root-server-internal/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export const MIGRATION_EXCEPTION_CODE = 'MigrationOnlyNode';
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const mockServer = {
setupCoreConfig: jest.fn(),
preboot: jest.fn(),
setup: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
configService,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { rawConfigService, configService, logger, mockServer } from './index.tes

import { BehaviorSubject } from 'rxjs';
import { filter, first } from 'rxjs/operators';
import { CriticalError } from '@kbn/core-base-server-internal';
import { REPO_ROOT } from '@kbn/repo-info';
import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
Expand Down Expand Up @@ -239,3 +240,16 @@ test('stops services if consequent logger upgrade fails', async () => {

expect(mockConsoleError.mock.calls).toMatchSnapshot();
});

test('handles migrator-only node exception', async () => {
const mockOnShutdown = jest.fn();
const root = new Root(rawConfigService, env, mockOnShutdown);
mockServer.start.mockImplementation(() => {
throw new CriticalError('Test', 'MigratioOnlyNode', 0);
});
await root.preboot();
await root.setup();
await expect(() => root.start()).rejects.toBeInstanceOf(CriticalError);
expect(mockServer.stop).toHaveBeenCalledTimes(1);
expect(mockOnShutdown).toHaveBeenCalledTimes(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import apm from 'elastic-apm-node';
import { isEqual } from 'lodash';
import type { ElasticConfigType } from './elastic_config';
import { Server } from '../server';
import { MIGRATION_EXCEPTION_CODE } from '../constants';

/**
* Top-level entry point to kick off the app and start the Kibana server.
Expand Down Expand Up @@ -89,7 +90,9 @@ export class Root {
);
}

this.log.fatal(reason);
if (reason.code !== MIGRATION_EXCEPTION_CODE) {
this.log.fatal(reason);
}
}

await this.server.stop();
Expand Down
34 changes: 34 additions & 0 deletions packages/core/root/core-root-server-internal/src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ import { REPO_ROOT } from '@kbn/repo-info';
import { Env } from '@kbn/config';
import { rawConfigServiceMock, getEnvOptions } from '@kbn/config-mocks';
import { Server } from './server';
import { MIGRATION_EXCEPTION_CODE } from './constants';

import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import type { InternalNodeServicePreboot } from '@kbn/core-node-server-internal';
import { CriticalError } from '@kbn/core-base-server-internal';

const env = Env.createDefault(REPO_ROOT, getEnvOptions());
const logger = loggingSystemMock.create();
Expand All @@ -58,6 +61,7 @@ beforeEach(() => {

afterEach(() => {
jest.clearAllMocks();
mockEnsureValidConfiguration.mockReset();
});

test('preboot services on "preboot"', async () => {
Expand Down Expand Up @@ -252,3 +256,33 @@ test(`doesn't preboot core services if config validation fails`, async () => {
expect(mockPluginsService.preboot).not.toHaveBeenCalled();
expect(mockPrebootService.preboot).not.toHaveBeenCalled();
});

test('migrator-only node throws exception during start', async () => {
rawConfigService.getConfig$.mockReturnValue(
new BehaviorSubject({ node: { roles: ['migrator'] } })
);
const nodeServiceContract: InternalNodeServicePreboot = {
roles: { migrator: true, ui: false, backgroundTasks: false },
};
mockNodeService.preboot.mockResolvedValue(nodeServiceContract);
mockNodeService.start.mockReturnValue(nodeServiceContract);

const server = new Server(rawConfigService, env, logger);

await server.preboot();
await server.setup();

let migrationException: undefined | CriticalError;
expect(mockSavedObjectsService.start).not.toHaveBeenCalled();
await server.start().catch((e) => (migrationException = e));

expect(mockSavedObjectsService.start).toHaveBeenCalledTimes(1);
expect(mockSavedObjectsService.start).toHaveNthReturnedWith(1, expect.anything());

expect(migrationException).not.toBeUndefined();
expect(migrationException).toBeInstanceOf(CriticalError);
expect(migrationException!.message).toBe('Migrations completed, shutting down Kibana');
expect(migrationException!.code).toBe(MIGRATION_EXCEPTION_CODE);
expect(migrationException!.processExitCode).toBe(0);
expect(migrationException!.cause).toBeUndefined();
});
17 changes: 17 additions & 0 deletions packages/core/root/core-root-server-internal/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import apm from 'elastic-apm-node';
import { reportPerformanceMetricEvent } from '@kbn/ebt-tools';
import type { Logger, LoggerFactory } from '@kbn/logging';
import type { NodeRoles } from '@kbn/core-node-server';
import { CriticalError } from '@kbn/core-base-server-internal';
import { ConfigService, Env, RawConfigurationProvider } from '@kbn/config';
import { DocLinksService } from '@kbn/core-doc-links-server-internal';
import { LoggingService, ILoggingSystem } from '@kbn/core-logging-server-internal';
Expand Down Expand Up @@ -51,6 +53,7 @@ import type {
import { DiscoveredPlugins, PluginsService } from '@kbn/core-plugins-server-internal';
import { CoreAppsService } from '@kbn/core-apps-server-internal';
import { registerServiceConfig } from './register_service_config';
import { MIGRATION_EXCEPTION_CODE } from './constants';

const coreId = Symbol('core');
const KIBANA_STARTED_EVENT = 'kibana_started';
Expand Down Expand Up @@ -103,6 +106,7 @@ export class Server {
private coreStart?: InternalCoreStart;
private discoveredPlugins?: DiscoveredPlugins;
private readonly logger: LoggerFactory;
private nodeRoles?: NodeRoles;

private readonly uptimePerStep: Partial<UptimeSteps> = {};

Expand Down Expand Up @@ -159,6 +163,8 @@ export class Server {
const environmentPreboot = await this.environment.preboot({ analytics: analyticsPreboot });
const nodePreboot = await this.node.preboot({ loggingSystem: this.loggingSystem });

this.nodeRoles = nodePreboot.roles;

// Discover any plugins before continuing. This allows other systems to utilize the plugin dependency graph.
this.discoveredPlugins = await this.plugins.discover({
environment: environmentPreboot,
Expand Down Expand Up @@ -364,6 +370,17 @@ export class Server {
await this.resolveSavedObjectsStartPromise!(savedObjectsStart);

soStartSpan?.end();

if (this.nodeRoles?.migrator === true) {
startTransaction?.end();
this.log.info('Detected migrator node role; shutting down Kibana...');
throw new CriticalError(
'Migrations completed, shutting down Kibana',
MIGRATION_EXCEPTION_CODE,
0
);
}

const capabilitiesStart = this.capabilities.start();
const uiSettingsStart = await this.uiSettings.start();
const customBrandingStart = this.customBranding.start();
Expand Down
1 change: 1 addition & 0 deletions packages/core/root/core-root-server-internal/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@kbn/core-custom-branding-server-internal",
"@kbn/core-custom-branding-server-mocks",
"@kbn/repo-packages",
"@kbn/core-node-server",
],
"exclude": [
"target/**/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function getWebpackConfig(
// already bundled with all its necessary dependencies
noParse: [
/[\/\\]node_modules[\/\\]lodash[\/\\]index\.js$/,
/[\/\\]node_modules[\/\\]vega[\/\\]build-es5[\/\\]vega\.js$/,
/[\/\\]node_modules[\/\\]vega[\/\\]build[\/\\]vega\.js$/,
],

rules: [
Expand Down
Loading

0 comments on commit 0318ba9

Please sign in to comment.