Skip to content

Commit

Permalink
Merge branch 'master' into refactor_connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Apr 30, 2020
2 parents 269d164 + 9112b6c commit 42fbd47
Show file tree
Hide file tree
Showing 58 changed files with 640 additions and 143 deletions.
58 changes: 58 additions & 0 deletions src/core/server/http/http_server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,14 @@ describe('setup contract', () => {
await create();
expect(create()).rejects.toThrowError('A cookieSessionStorageFactory was already created');
});

it('does not throw if called after stop', async () => {
const { createCookieSessionStorageFactory } = await server.setup(config);
await server.stop();
expect(() => {
createCookieSessionStorageFactory(cookieOptions);
}).not.toThrow();
});
});

describe('#isTlsEnabled', () => {
Expand Down Expand Up @@ -1113,4 +1121,54 @@ describe('setup contract', () => {
expect(getServerInfo().protocol).toEqual('https');
});
});

describe('#registerStaticDir', () => {
it('does not throw if called after stop', async () => {
const { registerStaticDir } = await server.setup(config);
await server.stop();
expect(() => {
registerStaticDir('/path1/{path*}', '/path/to/resource');
}).not.toThrow();
});
});

describe('#registerOnPreAuth', () => {
test('does not throw if called after stop', async () => {
const { registerOnPreAuth } = await server.setup(config);
await server.stop();
expect(() => {
registerOnPreAuth((req, res) => res.unauthorized());
}).not.toThrow();
});
});

describe('#registerOnPostAuth', () => {
test('does not throw if called after stop', async () => {
const { registerOnPostAuth } = await server.setup(config);
await server.stop();
expect(() => {
registerOnPostAuth((req, res) => res.unauthorized());
}).not.toThrow();
});
});

describe('#registerOnPreResponse', () => {
test('does not throw if called after stop', async () => {
const { registerOnPreResponse } = await server.setup(config);
await server.stop();
expect(() => {
registerOnPreResponse((req, res, t) => t.next());
}).not.toThrow();
});
});

describe('#registerAuth', () => {
test('does not throw if called after stop', async () => {
const { registerAuth } = await server.setup(config);
await server.stop();
expect(() => {
registerAuth((req, res) => res.unauthorized());
}).not.toThrow();
});
});
});
28 changes: 27 additions & 1 deletion src/core/server/http/http_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class HttpServer {
private registeredRouters = new Set<IRouter>();
private authRegistered = false;
private cookieSessionStorageCreated = false;
private stopped = false;

private readonly log: Logger;
private readonly authState: AuthStateStorage;
Expand Down Expand Up @@ -144,6 +145,10 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Http server is not setup up yet');
}
if (this.stopped) {
this.log.warn(`start called after stop`);
return;
}
this.log.debug('starting http server');

for (const router of this.registeredRouters) {
Expand Down Expand Up @@ -189,13 +194,13 @@ export class HttpServer {
}

public async stop() {
this.stopped = true;
if (this.server === undefined) {
return;
}

this.log.debug('stopping http server');
await this.server.stop();
this.server = undefined;
}

private getAuthOption(
Expand Down Expand Up @@ -234,6 +239,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`setupConditionalCompression called after stop`);
}

const { enabled, referrerWhitelist: list } = config.compression;
if (!enabled) {
Expand Down Expand Up @@ -261,6 +269,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerOnPostAuth called after stop`);
}

this.server.ext('onPostAuth', adoptToHapiOnPostAuthFormat(fn, this.log));
}
Expand All @@ -269,6 +280,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerOnPreAuth called after stop`);
}

this.server.ext('onRequest', adoptToHapiOnPreAuthFormat(fn, this.log));
}
Expand All @@ -277,6 +291,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerOnPreResponse called after stop`);
}

this.server.ext('onPreResponse', adoptToHapiOnPreResponseFormat(fn, this.log));
}
Expand All @@ -288,6 +305,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`createCookieSessionStorageFactory called after stop`);
}
if (this.cookieSessionStorageCreated) {
throw new Error('A cookieSessionStorageFactory was already created');
}
Expand All @@ -305,6 +325,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
this.log.warn(`registerAuth called after stop`);
}
if (this.authRegistered) {
throw new Error('Auth interceptor was already registered');
}
Expand Down Expand Up @@ -348,6 +371,9 @@ export class HttpServer {
if (this.server === undefined) {
throw new Error('Http server is not setup up yet');
}
if (this.stopped) {
this.log.warn(`registerStaticDir called after stop`);
}

this.server.route({
path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const hostMiddlewareFactory: ImmutableMiddlewareFactory<HostState> = core
type: 'serverReturnedHostDetails',
payload: response,
});
// FIXME: once we have the API implementation in place, we should call it parallel with the above api call and then dispatch this with the results of the second call
dispatch({
type: 'serverReturnedHostPolicyResponse',
payload: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export const getRequestData = async (
reqData.fromIndex = reqData.pageIndex * reqData.pageSize;
}

// See: https://github.com/elastic/elasticsearch-js/issues/662
// and https://github.com/elastic/endpoint-app-team/issues/221
if (
reqData.searchBefore !== undefined &&
reqData.searchBefore[0] === '' &&
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/endpoint/server/routes/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ async function enrichHostMetadata(
try {
/**
* Get agent status by elastic agent id if available or use the host id.
* https://github.com/elastic/endpoint-app-team/issues/354
*/

if (!elasticAgentId) {
Expand Down
13 changes: 10 additions & 3 deletions x-pack/plugins/event_log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,28 @@ PUT _ilm/policy/event_log_policy
"hot": {
"actions": {
"rollover": {
"max_size": "5GB",
"max_size": "50GB",
"max_age": "30d"
}
}
},
"delete": {
"min_age": "90d",
"actions": {
"delete": {}
}
}
}
}
}
```

This means that ILM would "rollover" the current index, say
`.kibana-event-log-000001` by creating a new index `.kibana-event-log-000002`,
`.kibana-event-log-8.0.0-000001` by creating a new index `.kibana-event-log-8.0.0-000002`,
which would "inherit" everything from the index template, and then ILM will
set the write index of the the alias to the new index. This would happen
when the original index grew past 5 GB, or was created more than 30 days ago.
when the original index grew past 50 GB, or was created more than 30 days ago.
After rollover, the indices will be removed after 90 days to avoid disks to fill up.

For more relevant information on ILM, see:
[getting started with ILM doc][] and [write index alias behavior][]:
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/event_log/server/es/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ export function getIlmPolicy() {
hot: {
actions: {
rollover: {
max_size: '5GB',
max_size: '50GB',
max_age: '30d',
// max_docs: 1, // you know, for testing
},
},
},
delete: {
min_age: '90d',
actions: {
delete: {},
},
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
EuiText,
EuiFormRow,
EuiButtonEmpty,
EuiCheckbox,
EuiToolTip,
EuiIcon,
EuiFieldSearch,
} from '@elastic/eui';
import { IFieldType } from 'src/plugins/data/public';
Expand Down Expand Up @@ -57,6 +60,7 @@ interface Props {
groupBy?: string;
filterQuery?: string;
sourceId?: string;
alertOnNoData?: boolean;
};
alertsContext: AlertsContextValue<AlertContextMeta>;
setAlertParams(key: string, value: any): void;
Expand Down Expand Up @@ -282,6 +286,28 @@ export const Expressions: React.FC<Props> = props => {
</EuiButtonEmpty>
</div>

<EuiSpacer size={'m'} />
<EuiCheckbox
id="metrics-alert-no-data-toggle"
label={
<>
{i18n.translate('xpack.infra.metrics.alertFlyout.alertOnNoData', {
defaultMessage: "Alert me if there's no data",
})}{' '}
<EuiToolTip
content={i18n.translate('xpack.infra.metrics.alertFlyout.noDataHelpText', {
defaultMessage:
'Enable this to trigger the action if the metric(s) do not report any data over the expected time period, or if the alert fails to query Elasticsearch',
})}
>
<EuiIcon type="questionInCircle" color="subdued" />
</EuiToolTip>
</>
}
checked={alertParams.alertOnNoData}
onChange={e => setAlertParams('alertOnNoData', e.target.checked)}
/>

<EuiSpacer size={'m'} />

<EuiFormRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export function getAlertType(): AlertTypeModel {
defaultActionMessage: i18n.translate(
'xpack.infra.metrics.alerting.threshold.defaultActionMessage',
{
defaultMessage: `\\{\\{alertName\\}\\} - \\{\\{context.group\\}\\}
defaultMessage: `\\{\\{alertName\\}\\} - \\{\\{context.group\\}\\} is in a state of \\{\\{context.alertState\\}\\}
\\{\\{context.metricOf.condition0\\}\\} has crossed a threshold of \\{\\{context.thresholdOf.condition0\\}\\}
Current value is \\{\\{context.valueOf.condition0\\}\\}
Reason:
\\{\\{context.reason\\}\\}
`,
}
),
Expand Down
Loading

0 comments on commit 42fbd47

Please sign in to comment.