Skip to content

Commit

Permalink
Merge branch 'master' into kbn-103915-remove-csp-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Oct 11, 2021
2 parents 96905c6 + a0b55b3 commit 6c86115
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ correctiveActions: {
body?: {
[key: string]: any;
};
omitContextFromBody?: boolean;
};
manualSteps: string[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface DeprecationsDetails

| Property | Type | Description |
| --- | --- | --- |
| [correctiveActions](./kibana-plugin-core-server.deprecationsdetails.correctiveactions.md) | <code>{</code><br/><code> api?: {</code><br/><code> path: string;</code><br/><code> method: 'POST' &#124; 'PUT';</code><br/><code> body?: {</code><br/><code> [key: string]: any;</code><br/><code> };</code><br/><code> };</code><br/><code> manualSteps: string[];</code><br/><code> }</code> | corrective action needed to fix this deprecation. |
| [correctiveActions](./kibana-plugin-core-server.deprecationsdetails.correctiveactions.md) | <code>{</code><br/><code> api?: {</code><br/><code> path: string;</code><br/><code> method: 'POST' &#124; 'PUT';</code><br/><code> body?: {</code><br/><code> [key: string]: any;</code><br/><code> };</code><br/><code> omitContextFromBody?: boolean;</code><br/><code> };</code><br/><code> manualSteps: string[];</code><br/><code> }</code> | corrective action needed to fix this deprecation. |
| [deprecationType](./kibana-plugin-core-server.deprecationsdetails.deprecationtype.md) | <code>'config' &#124; 'feature'</code> | (optional) Used to identify between different deprecation types. Example use case: in Upgrade Assistant, we may want to allow the user to sort by deprecation type or show each type in a separate tab.<!-- -->Feel free to add new types if necessary. Predefined types are necessary to reduce having similar definitions with different keywords across kibana deprecations. |
| [documentationUrl](./kibana-plugin-core-server.deprecationsdetails.documentationurl.md) | <code>string</code> | (optional) link to the documentation for more details on the deprecation. |
| [level](./kibana-plugin-core-server.deprecationsdetails.level.md) | <code>'warning' &#124; 'critical' &#124; 'fetch_error'</code> | levels: - warning: will not break deployment upon upgrade - critical: needs to be addressed before upgrade. - fetch\_error: Deprecations service failed to grab the deprecation details for the domain. |
Expand Down
33 changes: 33 additions & 0 deletions src/core/public/deprecations/deprecations_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,38 @@ describe('DeprecationsClient', () => {

expect(result).toEqual({ status: 'fail', reason: mockResponse });
});

it('omit deprecationDetails in the request of the body', async () => {
const deprecationsClient = new DeprecationsClient({ http });
const mockDeprecationDetails: DomainDeprecationDetails = {
title: 'some-title',
domainId: 'testPluginId-1',
message: 'some-message',
level: 'warning',
correctiveActions: {
api: {
path: 'some-path',
method: 'POST',
body: {
extra_param: 123,
},
omitContextFromBody: true,
},
manualSteps: ['manual-step'],
},
};
const result = await deprecationsClient.resolveDeprecation(mockDeprecationDetails);

expect(http.fetch).toBeCalledTimes(1);
expect(http.fetch).toBeCalledWith({
path: 'some-path',
method: 'POST',
asSystemRequest: true,
body: JSON.stringify({
extra_param: 123,
}),
});
expect(result).toEqual({ status: 'ok' });
});
});
});
4 changes: 2 additions & 2 deletions src/core/public/deprecations/deprecations_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export class DeprecationsClient {
};
}

const { body, method, path } = correctiveActions.api;
const { body, method, path, omitContextFromBody = false } = correctiveActions.api;
try {
await this.http.fetch<void>({
path,
method,
asSystemRequest: true,
body: JSON.stringify({
...body,
deprecationDetails: { domainId },
...(omitContextFromBody ? {} : { deprecationDetails: { domainId } }),
}),
});
return { status: 'ok' };
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/deprecations/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async function getDeprecations({ esClient, savedObjectsClient }: GetDeprecations
The deprecations API allows plugins to provide an API call that can be used to automatically fix specific deprecations.
To do so create a `PUT` or `POST` route in your plugin and specify data you want to be passed in the payload for the deprecation.

In the example above, `/internal/security/users/test_dashboard_user` will be called when users click on `Quick Resolve` in the UA. The service will automatically pass the body provided in the api corrective action to provide context to the route for fixing the deprecation.
In the example above, `/internal/security/users/test_dashboard_user` will be called when users click on `Quick Resolve` in the UA. The service will automatically pass the body provided in the api corrective action to provide context to the route for fixing the deprecation. If you need to omit the deprecation details context in the request of the body, you can use the property `omitContextFromBody`.

The deprecations service expects a `200` status code to recognize the corrective action as a success.

Expand Down
2 changes: 2 additions & 0 deletions src/core/server/deprecations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface DeprecationsDetails {
body?: {
[key: string]: any;
};
/* Allow to omit context in the request of the body */
omitContextFromBody?: boolean;
};
/**
* Specify a list of manual steps users need to follow to
Expand Down
26 changes: 26 additions & 0 deletions src/core/server/environment/environment_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ describe('UuidService', () => {
expect(logger.get('process').warn).not.toHaveBeenCalled();
});
});

describe('unhandledRejection warnings', () => {
it('logs warn for an unhandeld promise rejected with an Error', async () => {
await service.preboot();

const err = new Error('something went wrong');
process.emit('unhandledRejection', err, new Promise((res, rej) => rej(err)));

expect(logger.get('process').warn).toHaveBeenCalledTimes(1);
expect(loggingSystemMock.collect(logger).warn[0][0]).toMatch(
/Detected an unhandled Promise rejection: Error: something went wrong\n.*at /
);
});

it('logs warn for an unhandeld promise rejected with a string', async () => {
await service.preboot();

const err = 'something went wrong';
process.emit('unhandledRejection', err, new Promise((res, rej) => rej(err)));

expect(logger.get('process').warn).toHaveBeenCalledTimes(1);
expect(loggingSystemMock.collect(logger).warn[0][0]).toMatch(
/Detected an unhandled Promise rejection: "something went wrong"/
);
});
});
});

describe('#setup()', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/core/server/environment/environment_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export class EnvironmentService {
this.configService.atPath<PidConfigType>(pidConfigDef.path).pipe(take(1)).toPromise(),
]);

// was present in the legacy `pid` file.
// Log unhandled rejections so that we can fix them in preparation for https://github.com/elastic/kibana/issues/77469
process.on('unhandledRejection', (reason) => {
this.log.warn(`Detected an unhandled Promise rejection.\n${reason}`);
const message = (reason as Error)?.stack ?? JSON.stringify(reason);
this.log.warn(`Detected an unhandled Promise rejection: ${message}`);
});

process.on('warning', (warning) => {
Expand Down
1 change: 1 addition & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ export interface DeprecationsDetails {
body?: {
[key: string]: any;
};
omitContextFromBody?: boolean;
};
manualSteps: string[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function ({ getPageObjects, getService }) {
describe.skip('docvalue_fields', () => {
before(async () => {
await security.testUser.setRoles(['global_maps_read', 'test_logstash_reader'], false);
await PageObjects.maps.loadSavedMap('document example');
});

after(async () => {
Expand Down Expand Up @@ -46,11 +45,14 @@ export default function ({ getPageObjects, getService }) {
it('should format date fields as epoch_millis when data driven styling is applied to a date field', async () => {
await PageObjects.maps.loadSavedMap('document example with data driven styles on date field');
const { rawResponse: response } = await PageObjects.maps.getResponse();
const firstHit = response.hits.hits[0];
expect(firstHit).to.only.have.keys(['_id', '_index', '_score', 'fields']);
expect(firstHit.fields).to.only.have.keys(['@timestamp', 'bytes', 'geo.coordinates']);
expect(firstHit.fields['@timestamp']).to.be.an('array');
expect(firstHit.fields['@timestamp'][0]).to.eql('1442709321445');
const targetHit = response.hits.hits.find((hit) => {
return hit._id === 'AU_x3_g4GFA8no6QjkSR';
});
expect(targetHit).not.to.be(undefined);
expect(targetHit).to.only.have.keys(['_id', '_index', '_score', 'fields']);
expect(targetHit.fields).to.only.have.keys(['@timestamp', 'bytes', 'geo.coordinates']);
expect(targetHit.fields['@timestamp']).to.be.an('array');
expect(targetHit.fields['@timestamp'][0]).to.eql('1442709321445');
});
});
}

0 comments on commit 6c86115

Please sign in to comment.