Skip to content

Commit

Permalink
Merge branch 'master' into 58669-multiple-alert-expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Feb 28, 2020
2 parents 876ef56 + 2b9dc43 commit 3e51ae0
Show file tree
Hide file tree
Showing 550 changed files with 5,334 additions and 8,956 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@
/x-pack/test/detection_engine_api_integration @elastic/siem
/x-pack/test/api_integration/apis/siem @elastic/siem
/x-pack/plugins/case @elastic/siem

# Security Intelligence And Analytics
/x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules @elastic/security-intelligence-analytics
/x-pack/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules @elastic/security-intelligence-analytics
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface SavedObjectsServiceSetup

When plugins access the Saved Objects client, a new client is created using the factory provided to `setClientFactory` and wrapped by all wrappers registered through `addClientWrapper`<!-- -->.

All the setup APIs will throw if called after the service has started, and therefor cannot be used from legacy plugin code. Legacy plugins should use the legacy savedObject service until migrated.

## Example 1


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [SavedObjectsTypeMappingDefinition](./kibana-plugin-server.savedobjectstypemappingdefinition.md) &gt; [dynamic](./kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md)

## SavedObjectsTypeMappingDefinition.dynamic property

The dynamic property of the mapping. either `false` or 'strict'. Defaults to strict

<b>Signature:</b>

```typescript
dynamic?: false | 'strict';
```
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ const typeDefinition: SavedObjectsTypeMappingDefinition = {

| Property | Type | Description |
| --- | --- | --- |
| [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md) | <code>SavedObjectsMappingProperties</code> | |
| [dynamic](./kibana-plugin-server.savedobjectstypemappingdefinition.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping. either <code>false</code> or 'strict'. Defaults to strict |
| [properties](./kibana-plugin-server.savedobjectstypemappingdefinition.properties.md) | <code>SavedObjectsMappingProperties</code> | The underlying properties of the type mapping |

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## SavedObjectsTypeMappingDefinition.properties property

The underlying properties of the type mapping

<b>Signature:</b>

```typescript
Expand Down
318 changes: 156 additions & 162 deletions src/cli/serve/integration_tests/reload_logging_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,180 +84,174 @@ function createConfigManager(configPath: string) {
}

describe('Server logging configuration', function() {
let child: Child.ChildProcess;
let child: undefined | Child.ChildProcess;

beforeEach(() => {
Fs.mkdirSync(tempDir, { recursive: true });
});

afterEach(async () => {
if (child !== undefined) {
child.kill();
// wait for child to be killed otherwise jest complains that process not finished
await new Promise(res => setTimeout(res, 1000));
const exitPromise = new Promise(resolve => child?.once('exit', resolve));
child.kill('SIGKILL');
await exitPromise;
}

Del.sync(tempDir, { force: true });
});

const isWindows = /^win/.test(process.platform);
if (isWindows) {
if (process.platform.startsWith('win')) {
it('SIGHUP is not a feature of Windows.', () => {
// nothing to do for Windows
});
} else {
describe('legacy logging', () => {
it(
'should be reloadable via SIGHUP process signaling',
async function() {
const configFilePath = Path.resolve(tempDir, 'kibana.yml');
Fs.copyFileSync(legacyConfig, configFilePath);

child = Child.spawn(process.execPath, [
kibanaPath,
'--oss',
'--config',
configFilePath,
'--verbose',
]);

const message$ = Rx.fromEvent(child.stdout, 'data').pipe(
map(messages =>
String(messages)
.split('\n')
.filter(Boolean)
)
);

await message$
.pipe(
// We know the sighup handler will be registered before this message logged
filter(messages => messages.some(m => m.includes('setting up root'))),
take(1)
)
.toPromise();

const lastMessage = await message$.pipe(take(1)).toPromise();
expect(containsJsonOnly(lastMessage)).toBe(true);

createConfigManager(configFilePath).modify(oldConfig => {
oldConfig.logging.json = false;
return oldConfig;
});

child.kill('SIGHUP');

await message$
.pipe(
filter(messages => !containsJsonOnly(messages)),
take(1)
)
.toPromise();
},
minute
);

it(
'should recreate file handle on SIGHUP',
async function() {
const logPath = Path.resolve(tempDir, 'kibana.log');
const logPathArchived = Path.resolve(tempDir, 'kibana_archive.log');

child = Child.spawn(process.execPath, [
kibanaPath,
'--oss',
'--config',
legacyConfig,
'--logging.dest',
logPath,
'--verbose',
]);

await watchFileUntil(logPath, /setting up root/, 30 * second);
// once the server is running, archive the log file and issue SIGHUP
Fs.renameSync(logPath, logPathArchived);
child.kill('SIGHUP');

await watchFileUntil(
logPath,
/Reloaded logging configuration due to SIGHUP/,
30 * second
);
},
minute
);
});

describe('platform logging', () => {
it(
'should be reloadable via SIGHUP process signaling',
async function() {
const configFilePath = Path.resolve(tempDir, 'kibana.yml');
Fs.copyFileSync(configFileLogConsole, configFilePath);

child = Child.spawn(process.execPath, [kibanaPath, '--oss', '--config', configFilePath]);

const message$ = Rx.fromEvent(child.stdout, 'data').pipe(
map(messages =>
String(messages)
.split('\n')
.filter(Boolean)
)
);

await message$
.pipe(
// We know the sighup handler will be registered before this message logged
filter(messages => messages.some(m => m.includes('setting up root'))),
take(1)
)
.toPromise();

const lastMessage = await message$.pipe(take(1)).toPromise();
expect(containsJsonOnly(lastMessage)).toBe(true);

createConfigManager(configFilePath).modify(oldConfig => {
oldConfig.logging.appenders.console.layout.kind = 'pattern';
return oldConfig;
});
child.kill('SIGHUP');

await message$
.pipe(
filter(messages => !containsJsonOnly(messages)),
take(1)
)
.toPromise();
},
30 * second
);
it(
'should recreate file handle on SIGHUP',
async function() {
const configFilePath = Path.resolve(tempDir, 'kibana.yml');
Fs.copyFileSync(configFileLogFile, configFilePath);

const logPath = Path.resolve(tempDir, 'kibana.log');
const logPathArchived = Path.resolve(tempDir, 'kibana_archive.log');

createConfigManager(configFilePath).modify(oldConfig => {
oldConfig.logging.appenders.file.path = logPath;
return oldConfig;
});

child = Child.spawn(process.execPath, [kibanaPath, '--oss', '--config', configFilePath]);

await watchFileUntil(logPath, /setting up root/, 30 * second);
// once the server is running, archive the log file and issue SIGHUP
Fs.renameSync(logPath, logPathArchived);
child.kill('SIGHUP');

await watchFileUntil(
logPath,
/Reloaded logging configuration due to SIGHUP/,
30 * second
);
},
minute
);
});
return;
}

describe('legacy logging', () => {
it(
'should be reloadable via SIGHUP process signaling',
async function() {
const configFilePath = Path.resolve(tempDir, 'kibana.yml');
Fs.copyFileSync(legacyConfig, configFilePath);

child = Child.spawn(process.execPath, [
kibanaPath,
'--oss',
'--config',
configFilePath,
'--verbose',
]);

const message$ = Rx.fromEvent(child.stdout, 'data').pipe(
map(messages =>
String(messages)
.split('\n')
.filter(Boolean)
)
);

await message$
.pipe(
// We know the sighup handler will be registered before this message logged
filter(messages => messages.some(m => m.includes('setting up root'))),
take(1)
)
.toPromise();

const lastMessage = await message$.pipe(take(1)).toPromise();
expect(containsJsonOnly(lastMessage)).toBe(true);

createConfigManager(configFilePath).modify(oldConfig => {
oldConfig.logging.json = false;
return oldConfig;
});

child.kill('SIGHUP');

await message$
.pipe(
filter(messages => !containsJsonOnly(messages)),
take(1)
)
.toPromise();
},
minute
);

it(
'should recreate file handle on SIGHUP',
async function() {
const logPath = Path.resolve(tempDir, 'kibana.log');
const logPathArchived = Path.resolve(tempDir, 'kibana_archive.log');

child = Child.spawn(process.execPath, [
kibanaPath,
'--oss',
'--config',
legacyConfig,
'--logging.dest',
logPath,
'--verbose',
]);

await watchFileUntil(logPath, /setting up root/, 30 * second);
// once the server is running, archive the log file and issue SIGHUP
Fs.renameSync(logPath, logPathArchived);
child.kill('SIGHUP');

await watchFileUntil(logPath, /Reloaded logging configuration due to SIGHUP/, 30 * second);
},
minute
);
});

describe('platform logging', () => {
it(
'should be reloadable via SIGHUP process signaling',
async function() {
const configFilePath = Path.resolve(tempDir, 'kibana.yml');
Fs.copyFileSync(configFileLogConsole, configFilePath);

child = Child.spawn(process.execPath, [kibanaPath, '--oss', '--config', configFilePath]);

const message$ = Rx.fromEvent(child.stdout, 'data').pipe(
map(messages =>
String(messages)
.split('\n')
.filter(Boolean)
)
);

await message$
.pipe(
// We know the sighup handler will be registered before this message logged
filter(messages => messages.some(m => m.includes('setting up root'))),
take(1)
)
.toPromise();

const lastMessage = await message$.pipe(take(1)).toPromise();
expect(containsJsonOnly(lastMessage)).toBe(true);

createConfigManager(configFilePath).modify(oldConfig => {
oldConfig.logging.appenders.console.layout.kind = 'pattern';
return oldConfig;
});
child.kill('SIGHUP');

await message$
.pipe(
filter(messages => !containsJsonOnly(messages)),
take(1)
)
.toPromise();
},
30 * second
);
it(
'should recreate file handle on SIGHUP',
async function() {
const configFilePath = Path.resolve(tempDir, 'kibana.yml');
Fs.copyFileSync(configFileLogFile, configFilePath);

const logPath = Path.resolve(tempDir, 'kibana.log');
const logPathArchived = Path.resolve(tempDir, 'kibana_archive.log');

createConfigManager(configFilePath).modify(oldConfig => {
oldConfig.logging.appenders.file.path = logPath;
return oldConfig;
});

child = Child.spawn(process.execPath, [kibanaPath, '--oss', '--config', configFilePath]);

await watchFileUntil(logPath, /setting up root/, 30 * second);
// once the server is running, archive the log file and issue SIGHUP
Fs.renameSync(logPath, logPathArchived);
child.kill('SIGHUP');

await watchFileUntil(logPath, /Reloaded logging configuration due to SIGHUP/, 30 * second);
},
minute
);
});
});
8 changes: 7 additions & 1 deletion src/core/MIGRATION_EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -917,4 +917,10 @@ Would be converted to:
```typescript
const migration: SavedObjectMigrationFn = (doc, { log }) => {...}
```
```
### Remarks
The `registerType` API will throw if called after the service has started, and therefor cannot be used from
legacy plugin code. Legacy plugins should use the legacy savedObjects service and the legacy way to register
saved object types until migrated.
Loading

0 comments on commit 3e51ae0

Please sign in to comment.