Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-91932
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Mar 2, 2021
2 parents 57ed7af + 30322c4 commit 1eebe39
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 149 deletions.
2 changes: 1 addition & 1 deletion docs/user/alerting/alert-types.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ For domain-specific alerts, refer to the documentation for that app.
* {observability-guide}/create-alerts.html[Observability alerts]
* {security-guide}/prebuilt-rules.html[Security alerts]
* <<geo-alerting, Maps alerts>>
* <<xpack-ml, ML alerts>>
* {ml-docs}/ml-configuring-alerts.html[{ml-cap} alerts]

[NOTE]
==============================================
Expand Down
2 changes: 1 addition & 1 deletion docs/user/alerting/alerting-getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

--

Alerting allows you to detect complex conditions within different {kib} apps and trigger actions when those conditions are met. Alerting is integrated with {observability-guide}/create-alerts.html[*Observability*], {security-guide}/prebuilt-rules.html[*Security*], <<geo-alerting,*Maps*>> and <<xpack-ml,*ML*>>, can be centrally managed from the <<management,*Management*>> UI, and provides a set of built-in <<action-types, actions>> and <<alert-types, alerts>> (known as stack alerts) for you to use.
Alerting allows you to detect complex conditions within different {kib} apps and trigger actions when those conditions are met. Alerting is integrated with {observability-guide}/create-alerts.html[*Observability*], {security-guide}/prebuilt-rules.html[*Security*], <<geo-alerting,*Maps*>> and {ml-docs}/ml-configuring-alerts.html[*{ml-app}*], can be centrally managed from the <<management,*Management*>> UI, and provides a set of built-in <<action-types, actions>> and <<alert-types, alerts>> (known as stack alerts) for you to use.

image::images/alerting-overview.png[Alerts and actions UI]

Expand Down
2 changes: 1 addition & 1 deletion docs/user/alerting/defining-alerts.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[[defining-alerts]]
== Defining alerts

{kib} alerts can be created in a variety of apps including <<xpack-apm,*APM*>>, <<metrics-app,*Metrics*>>, <<xpack-siem,*Security*>>, <<uptime-app,*Uptime*>> and from <<management,*Management*>> UI. While alerting details may differ from app to app, they share a common interface for defining and configuring alerts that this section describes in more detail.
{kib} alerts can be created in a variety of apps including <<xpack-apm,*APM*>>, <<xpack-ml,*{ml-app}*>>, <<metrics-app,*Metrics*>>, <<xpack-siem,*Security*>>, <<uptime-app,*Uptime*>> and from <<management,*Management*>> UI. While alerting details may differ from app to app, they share a common interface for defining and configuring alerts that this section describes in more detail.

[float]
=== Alert flyout
Expand Down
121 changes: 57 additions & 64 deletions x-pack/plugins/reporting/server/config/create_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,26 @@
* 2.0.
*/

import * as Rx from 'rxjs';
import { CoreSetup, PluginInitializerContext } from 'src/core/server';
import { coreMock } from 'src/core/server/mocks';
import { LevelLogger } from '../lib';
import { createMockConfigSchema } from '../test_helpers';
import { createConfig$ } from './create_config';
import { ReportingConfigType } from './schema';

interface KibanaServer {
hostname?: string;
port?: number;
protocol?: string;
}

const makeMockInitContext = (config: {
capture?: Partial<ReportingConfigType['capture']>;
encryptionKey?: string;
kibanaServer: Partial<ReportingConfigType['kibanaServer']>;
}): PluginInitializerContext =>
({
config: {
create: () =>
Rx.of({
...config,
capture: config.capture || { browser: { chromium: { disableSandbox: false } } },
kibanaServer: config.kibanaServer || {},
}),
},
} as PluginInitializerContext);

const makeMockCoreSetup = (serverInfo: KibanaServer): CoreSetup =>
({ http: { getServerInfo: () => serverInfo } } as any);

describe('Reporting server createConfig$', () => {
let mockCoreSetup: CoreSetup;
let mockInitContext: PluginInitializerContext;
let mockLogger: LevelLogger;

beforeEach(() => {
mockCoreSetup = makeMockCoreSetup({ hostname: 'kibanaHost', port: 5601, protocol: 'http' });
mockInitContext = makeMockInitContext({
kibanaServer: {},
});
mockCoreSetup = coreMock.createSetup();
mockInitContext = coreMock.createPluginInitializerContext(
createMockConfigSchema({ kibanaServer: {} })
);
mockLogger = ({
warn: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
clone: jest.fn().mockImplementation(() => mockLogger),
} as unknown) as LevelLogger;
});
Expand All @@ -58,14 +34,18 @@ describe('Reporting server createConfig$', () => {
});

it('creates random encryption key and default config using host, protocol, and port from server info', async () => {
mockInitContext = coreMock.createPluginInitializerContext({
...createMockConfigSchema({ kibanaServer: {} }),
encryptionKey: undefined,
});
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

expect(result.encryptionKey).toMatch(/\S{32,}/); // random 32 characters
expect(result.kibanaServer).toMatchInlineSnapshot(`
Object {
"hostname": "kibanaHost",
"port": 5601,
"hostname": "localhost",
"port": 80,
"protocol": "http",
}
`);
Expand All @@ -76,25 +56,28 @@ describe('Reporting server createConfig$', () => {
});

it('uses the user-provided encryption key', async () => {
mockInitContext = makeMockInitContext({
encryptionKey: 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii',
kibanaServer: {},
});
mockInitContext = coreMock.createPluginInitializerContext(
createMockConfigSchema({
encryptionKey: 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii',
})
);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
expect(result.encryptionKey).toMatch('iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii');
expect((mockLogger.warn as any).mock.calls.length).toBe(0);
});

it('uses the user-provided encryption key, reporting kibanaServer settings to override server info', async () => {
mockInitContext = makeMockInitContext({
encryptionKey: 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii',
kibanaServer: {
hostname: 'reportingHost',
port: 5677,
protocol: 'httpsa',
},
});
mockInitContext = coreMock.createPluginInitializerContext(
createMockConfigSchema({
encryptionKey: 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii',
kibanaServer: {
hostname: 'reportingHost',
port: 5677,
protocol: 'httpsa',
},
})
);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

Expand All @@ -103,25 +86,34 @@ describe('Reporting server createConfig$', () => {
"capture": Object {
"browser": Object {
"chromium": Object {
"disableSandbox": false,
"disableSandbox": true,
},
},
},
"csv": Object {},
"encryptionKey": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",
"index": ".reporting",
"kibanaServer": Object {
"hostname": "reportingHost",
"port": 5677,
"protocol": "httpsa",
},
"queue": Object {
"indexInterval": "week",
"pollEnabled": true,
"pollInterval": 3000,
"timeout": 120000,
},
}
`);
expect((mockLogger.warn as any).mock.calls.length).toBe(0);
});

it('show warning when kibanaServer.hostName === "0"', async () => {
mockInitContext = makeMockInitContext({
mockInitContext = coreMock.createPluginInitializerContext({
encryptionKey: 'aaaaaaaaaaaaabbbbbbbbbbbbaaaaaaaaa',
kibanaServer: { hostname: '0' },
kibanaServer: { hostname: '0', port: 5601 },
capture: { browser: { chromium: {} } },
});
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();
Expand All @@ -133,18 +125,15 @@ describe('Reporting server createConfig$', () => {
"protocol": "http",
}
`);
expect((mockLogger.warn as any).mock.calls.length).toBe(1);
expect((mockLogger.warn as any).mock.calls[0]).toMatchObject([
`Found 'server.host: \"0\"' in Kibana configuration. This is incompatible with Reporting. To enable Reporting to work, 'xpack.reporting.kibanaServer.hostname: 0.0.0.0' is being automatically ` +
`to the configuration. You can change the setting to 'server.host: 0.0.0.0' or add 'xpack.reporting.kibanaServer.hostname: 0.0.0.0' in kibana.yml to prevent this message.`,
]);
});

it('uses user-provided disableSandbox: false', async () => {
mockInitContext = makeMockInitContext({
encryptionKey: '888888888888888888888888888888888',
capture: { browser: { chromium: { disableSandbox: false } } },
} as ReportingConfigType);
mockInitContext = coreMock.createPluginInitializerContext(
createMockConfigSchema({
encryptionKey: '888888888888888888888888888888888',
capture: { browser: { chromium: { disableSandbox: false } } },
})
);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

Expand All @@ -153,10 +142,12 @@ describe('Reporting server createConfig$', () => {
});

it('uses user-provided disableSandbox: true', async () => {
mockInitContext = makeMockInitContext({
encryptionKey: '888888888888888888888888888888888',
capture: { browser: { chromium: { disableSandbox: true } } },
} as ReportingConfigType);
mockInitContext = coreMock.createPluginInitializerContext(
createMockConfigSchema({
encryptionKey: '888888888888888888888888888888888',
capture: { browser: { chromium: { disableSandbox: true } } },
})
);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

Expand All @@ -165,9 +156,11 @@ describe('Reporting server createConfig$', () => {
});

it('provides a default for disableSandbox', async () => {
mockInitContext = makeMockInitContext({
encryptionKey: '888888888888888888888888888888888',
} as ReportingConfigType);
mockInitContext = coreMock.createPluginInitializerContext(
createMockConfigSchema({
encryptionKey: '888888888888888888888888888888888',
})
);
const mockConfig$: any = mockInitContext.config.create();
const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ export const runTaskFnFactory: RunTaskFnFactory<
> = function executeJobFactoryFn(reporting, parentLogger) {
const config = reporting.getConfig();
const encryptionKey = config.get('encryptionKey');
const logger = parentLogger.clone([PNG_JOB_TYPE, 'execute']);

return async function runTask(jobId, job, cancellationToken) {
const apmTrans = apm.startTransaction('reporting execute_job png', 'reporting');
const apmGetAssets = apmTrans?.startSpan('get_assets', 'setup');
let apmGeneratePng: { end: () => void } | null | undefined;

const generatePngObservable = await generatePngObservableFactory(reporting);
const jobLogger = logger.clone([jobId]);
const jobLogger = parentLogger.clone([PNG_JOB_TYPE, 'execute', jobId]);
const process$: Rx.Observable<TaskRunResult> = Rx.of(1).pipe(
mergeMap(() => decryptJobHeaders(encryptionKey, job.headers, logger)),
mergeMap(() => decryptJobHeaders(encryptionKey, job.headers, jobLogger)),
map((decryptedHeaders) => omitBlockedHeaders(decryptedHeaders)),
map((filteredHeaders) => getConditionalHeaders(config, filteredHeaders)),
mergeMap((conditionalHeaders) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@ export const runTaskFnFactory: RunTaskFnFactory<
const encryptionKey = config.get('encryptionKey');

return async function runTask(jobId, job, cancellationToken) {
const logger = parentLogger.clone([PDF_JOB_TYPE, 'execute-job', jobId]);
const jobLogger = parentLogger.clone([PDF_JOB_TYPE, 'execute-job', jobId]);
const apmTrans = apm.startTransaction('reporting execute_job pdf', 'reporting');
const apmGetAssets = apmTrans?.startSpan('get_assets', 'setup');
let apmGeneratePdf: { end: () => void } | null | undefined;

const generatePdfObservable = await generatePdfObservableFactory(reporting);

const jobLogger = logger.clone([jobId]);
const process$: Rx.Observable<TaskRunResult> = Rx.of(1).pipe(
mergeMap(() => decryptJobHeaders(encryptionKey, job.headers, logger)),
mergeMap(() => decryptJobHeaders(encryptionKey, job.headers, jobLogger)),
map((decryptedHeaders) => omitBlockedHeaders(decryptedHeaders)),
map((filteredHeaders) => getConditionalHeaders(config, filteredHeaders)),
mergeMap((conditionalHeaders) =>
getCustomLogo(reporting, conditionalHeaders, job.spaceId, logger)
getCustomLogo(reporting, conditionalHeaders, job.spaceId, jobLogger)
),
mergeMap(({ logo, conditionalHeaders }) => {
const urls = getFullUrls(config, job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { createInterface } from 'readline';
import { setupServer } from 'src/core/server/test_utils';
import supertest from 'supertest';
import { ReportingCore } from '../..';
import { createMockLevelLogger, createMockReportingCore } from '../../test_helpers';
import {
createMockLevelLogger,
createMockPluginSetup,
createMockReportingCore,
} from '../../test_helpers';
import { registerDiagnoseBrowser } from './browser';
import type { ReportingRequestHandlerContext } from '../../types';

Expand Down Expand Up @@ -55,12 +59,12 @@ describe('POST /diagnose/browser', () => {
() => ({})
);

const mockSetupDeps = ({
const mockSetupDeps = createMockPluginSetup({
elasticsearch: {
legacy: { client: { callAsInternalUser: jest.fn() } },
},
router: httpSetup.createRouter(''),
} as unknown) as any;
});

core = await createMockReportingCore(config, mockSetupDeps);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { UnwrapPromise } from '@kbn/utility-types';
import { setupServer } from 'src/core/server/test_utils';
import supertest from 'supertest';
import { ReportingCore } from '../..';
import { createMockReportingCore, createMockLevelLogger } from '../../test_helpers';
import {
createMockReportingCore,
createMockLevelLogger,
createMockPluginSetup,
} from '../../test_helpers';
import { registerDiagnoseConfig } from './config';
import type { ReportingRequestHandlerContext } from '../../types';

Expand All @@ -33,7 +37,7 @@ describe('POST /diagnose/config', () => {
() => ({})
);

mockSetupDeps = ({
mockSetupDeps = createMockPluginSetup({
elasticsearch: {
legacy: { client: { callAsInternalUser: jest.fn() } },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { UnwrapPromise } from '@kbn/utility-types';
import { setupServer } from 'src/core/server/test_utils';
import supertest from 'supertest';
import { ReportingCore } from '../..';
import { createMockReportingCore, createMockLevelLogger } from '../../test_helpers';
import {
createMockReportingCore,
createMockLevelLogger,
createMockPluginSetup,
} from '../../test_helpers';
import { registerDiagnoseScreenshot } from './screenshot';
import type { ReportingRequestHandlerContext } from '../../types';

Expand Down Expand Up @@ -52,12 +56,12 @@ describe('POST /diagnose/screenshot', () => {
() => ({})
);

const mockSetupDeps = ({
const mockSetupDeps = createMockPluginSetup({
elasticsearch: {
legacy: { client: { callAsInternalUser: jest.fn() } },
},
router: httpSetup.createRouter(''),
} as unknown) as any;
});

core = await createMockReportingCore(config, mockSetupDeps);
});
Expand Down
Loading

0 comments on commit 1eebe39

Please sign in to comment.