mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `9.0`: - [Add message in ua linking to deprecated debug logs docs (#208806)](https://github.com/elastic/kibana/pull/208806) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jesus Wahrman","email":"41008968+jesuswr@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-01-31T11:57:25Z","message":"Add message in ua linking to deprecated debug logs docs (#208806)\n\n## Summary\r\n\r\nResolves https://github.com/elastic/kibana/issues/208570\r\n\r\nAdd a message in UA with a link to the new config that enables debug\r\nlogs when a deprecated API is called.\r\n\r\n<img width=\"485\" alt=\"Screenshot 2025-01-29 at 17 16 33\"\r\nsrc=\"https://github.com/user-attachments/assets/ce796b38-c7af-4f0c-bcca-74512c909208\"\r\n/>\r\n\r\nTo try this you can call a deprecated API and look for the warnings in\r\nUA.\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] This was checked for breaking HTTP API changes, and any breaking\r\nchanges have been approved by the breaking-change committee. The\r\n`release_note:breaking` label should be applied in these situations.\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n### Identify risks\r\n\r\nDoes this PR introduce any risks? For example, consider risks like hard\r\nto test bugs, performance regression, potential of data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for each identified\r\nrisk. Invite stakeholders and evaluate how to proceed before merging.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by: florent-leborgne <florent.leborgne@elastic.co>","sha":"5774e8d402756a040037134c341b94d2dacd56ce","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:http","release_note:skip","deprecation_warnings","v9.0.0","backport:version","v8.18.0","v9.1.0","v8.19.0"],"title":"Add message in ua linking to deprecated debug logs docs","number":208806,"url":"https://github.com/elastic/kibana/pull/208806","mergeCommit":{"message":"Add message in ua linking to deprecated debug logs docs (#208806)\n\n## Summary\r\n\r\nResolves https://github.com/elastic/kibana/issues/208570\r\n\r\nAdd a message in UA with a link to the new config that enables debug\r\nlogs when a deprecated API is called.\r\n\r\n<img width=\"485\" alt=\"Screenshot 2025-01-29 at 17 16 33\"\r\nsrc=\"https://github.com/user-attachments/assets/ce796b38-c7af-4f0c-bcca-74512c909208\"\r\n/>\r\n\r\nTo try this you can call a deprecated API and look for the warnings in\r\nUA.\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] This was checked for breaking HTTP API changes, and any breaking\r\nchanges have been approved by the breaking-change committee. The\r\n`release_note:breaking` label should be applied in these situations.\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n### Identify risks\r\n\r\nDoes this PR introduce any risks? For example, consider risks like hard\r\nto test bugs, performance regression, potential of data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for each identified\r\nrisk. Invite stakeholders and evaluate how to proceed before merging.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by: florent-leborgne <florent.leborgne@elastic.co>","sha":"5774e8d402756a040037134c341b94d2dacd56ce"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/208806","number":208806,"mergeCommit":{"message":"Add message in ua linking to deprecated debug logs docs (#208806)\n\n## Summary\r\n\r\nResolves https://github.com/elastic/kibana/issues/208570\r\n\r\nAdd a message in UA with a link to the new config that enables debug\r\nlogs when a deprecated API is called.\r\n\r\n<img width=\"485\" alt=\"Screenshot 2025-01-29 at 17 16 33\"\r\nsrc=\"https://github.com/user-attachments/assets/ce796b38-c7af-4f0c-bcca-74512c909208\"\r\n/>\r\n\r\nTo try this you can call a deprecated API and look for the warnings in\r\nUA.\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] This was checked for breaking HTTP API changes, and any breaking\r\nchanges have been approved by the breaking-change committee. The\r\n`release_note:breaking` label should be applied in these situations.\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n### Identify risks\r\n\r\nDoes this PR introduce any risks? For example, consider risks like hard\r\nto test bugs, performance regression, potential of data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for each identified\r\nrisk. Invite stakeholders and evaluate how to proceed before merging.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by: florent-leborgne <florent.leborgne@elastic.co>","sha":"5774e8d402756a040037134c341b94d2dacd56ce"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Jesus Wahrman <41008968+jesuswr@users.noreply.github.com>
This commit is contained in:
parent
f78bb9ed43
commit
5ea7caa457
13 changed files with 162 additions and 20 deletions
|
@ -33,6 +33,7 @@ export const getIsAccessApiDeprecation = ({
|
|||
export const buildApiAccessDeprecationDetails = ({
|
||||
apiUsageStats,
|
||||
deprecatedApiDetails,
|
||||
docLinks,
|
||||
}: BuildApiDeprecationDetailsParams): DomainDeprecationDetails<ApiDeprecationDetails> => {
|
||||
const { apiId, apiTotalCalls, totalMarkedAsResolved } = apiUsageStats;
|
||||
const { routeVersion, routePath, routeDeprecationOptions, routeMethod } = deprecatedApiDetails;
|
||||
|
@ -43,7 +44,7 @@ export const buildApiAccessDeprecationDetails = ({
|
|||
apiId,
|
||||
title: getApiDeprecationTitle(deprecatedApiDetails),
|
||||
level: deprecationLevel,
|
||||
message: getApiDeprecationMessage(deprecatedApiDetails, apiUsageStats),
|
||||
message: getApiDeprecationMessage(deprecatedApiDetails, apiUsageStats, docLinks),
|
||||
documentationUrl: routeDeprecationOptions?.documentationUrl,
|
||||
correctiveActions: {
|
||||
manualSteps: getApiDeprecationsManualSteps(),
|
||||
|
|
|
@ -11,6 +11,8 @@ import { RouterDeprecatedApiDetails } from '@kbn/core-http-server';
|
|||
import { CoreDeprecatedApiUsageStats } from '@kbn/core-usage-data-server';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import moment from 'moment';
|
||||
import { DocLinksServiceSetup } from '@kbn/core-doc-links-server';
|
||||
import type { DeprecationDetailsMessage } from '@kbn/core-deprecations-common';
|
||||
|
||||
export const getApiDeprecationTitle = (
|
||||
details: Pick<RouterDeprecatedApiDetails, 'routePath' | 'routeMethod'>
|
||||
|
@ -31,8 +33,9 @@ export const getApiDeprecationMessage = (
|
|||
RouterDeprecatedApiDetails,
|
||||
'routePath' | 'routeMethod' | 'routeDeprecationOptions'
|
||||
>,
|
||||
apiUsageStats: CoreDeprecatedApiUsageStats
|
||||
): string[] => {
|
||||
apiUsageStats: CoreDeprecatedApiUsageStats,
|
||||
docLinks: DocLinksServiceSetup
|
||||
): Array<string | DeprecationDetailsMessage> => {
|
||||
const { routePath, routeMethod, routeDeprecationOptions } = details;
|
||||
const { apiLastCalledAt, apiTotalCalls, markedAsResolvedLastCalledAt, totalMarkedAsResolved } =
|
||||
apiUsageStats;
|
||||
|
@ -41,7 +44,7 @@ export const getApiDeprecationMessage = (
|
|||
const wasResolvedBefore = totalMarkedAsResolved > 0;
|
||||
const routeWithMethod = `${routeMethod.toUpperCase()} ${routePath}`;
|
||||
|
||||
const messages = [
|
||||
const messages: Array<string | DeprecationDetailsMessage> = [
|
||||
i18n.translate('core.deprecations.apiAccessDeprecation.apiCallsDetailsMessage', {
|
||||
defaultMessage:
|
||||
'The API "{routeWithMethod}" has been called {apiTotalCalls} times. The last call was on {apiLastCalledAt}.',
|
||||
|
@ -72,6 +75,16 @@ export const getApiDeprecationMessage = (
|
|||
'Internal APIs are meant to be used by Elastic services only. You should not use them. External access to these APIs will be restricted.',
|
||||
})
|
||||
);
|
||||
messages.push({
|
||||
type: 'markdown',
|
||||
content: i18n.translate('core.deprecations.apiAccessDeprecation.enableDebugLogsMessage', {
|
||||
defaultMessage:
|
||||
'To include information in debug logs about calls to APIs that are internal to Elastic, edit your Kibana configuration as detailed in [the documentation]({enableDeprecationHttpDebugLogsLink}).',
|
||||
values: {
|
||||
enableDeprecationHttpDebugLogsLink: docLinks.links.logging.enableDeprecationHttpDebugLogs,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
if (routeDeprecationOptions?.message) {
|
||||
// Surfaces additional deprecation messages passed into the route in UA
|
||||
|
|
|
@ -14,18 +14,24 @@ import {
|
|||
createGetApiDeprecations,
|
||||
} from './register_api_depercation_info';
|
||||
import { buildApiDeprecationId } from './api_deprecation_id';
|
||||
import { RouterDeprecatedApiDetails } from '@kbn/core-http-server';
|
||||
import type {
|
||||
RouterAccessDeprecatedApiDetails,
|
||||
RouterDeprecatedApiDetails,
|
||||
} from '@kbn/core-http-server';
|
||||
import { httpServiceMock } from '@kbn/core-http-server-mocks';
|
||||
import {
|
||||
coreUsageDataServiceMock,
|
||||
coreUsageStatsClientMock,
|
||||
} from '@kbn/core-usage-data-server-mocks';
|
||||
import { docLinksServiceMock } from '@kbn/core-doc-links-server-mocks';
|
||||
import _ from 'lodash';
|
||||
import type { DocLinksServiceSetup } from '@kbn/core-doc-links-server';
|
||||
import { CoreDeprecatedApiUsageStats } from '@kbn/core-usage-data-server';
|
||||
|
||||
describe('#registerApiDeprecationsInfo', () => {
|
||||
const deprecationsFactory = mockDeprecationsFactory.create();
|
||||
const deprecationsRegistry = mockDeprecationsRegistry.create();
|
||||
const docLinks: DocLinksServiceSetup = docLinksServiceMock.createSetupContract();
|
||||
let usageClientMock: ReturnType<typeof coreUsageStatsClientMock.create>;
|
||||
let http: ReturnType<typeof httpServiceMock.createInternalSetupContract>;
|
||||
let coreUsageData: ReturnType<typeof coreUsageDataServiceMock.createSetupContract>;
|
||||
|
@ -47,7 +53,7 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
|
||||
it('registers api deprecations', async () => {
|
||||
deprecationsFactory.getRegistry.mockReturnValue(deprecationsRegistry);
|
||||
registerApiDeprecationsInfo({ deprecationsFactory, coreUsageData, http });
|
||||
registerApiDeprecationsInfo({ deprecationsFactory, coreUsageData, http, docLinks });
|
||||
|
||||
expect(deprecationsFactory.getRegistry).toBeCalledWith('core.api_deprecations');
|
||||
expect(deprecationsRegistry.registerDeprecations).toBeCalledTimes(1);
|
||||
|
@ -77,6 +83,19 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
overrides
|
||||
);
|
||||
|
||||
const createInternalRouteDetails = (
|
||||
overrides?: Partial<RouterAccessDeprecatedApiDetails>
|
||||
): RouterAccessDeprecatedApiDetails =>
|
||||
_.merge(
|
||||
{
|
||||
routeAccess: 'internal',
|
||||
routeMethod: 'post',
|
||||
routePath: '/internal/api/',
|
||||
routeVersion: '1.0.0',
|
||||
} as RouterAccessDeprecatedApiDetails,
|
||||
overrides
|
||||
);
|
||||
|
||||
const createApiUsageStat = (
|
||||
apiId: string,
|
||||
overrides?: DeepPartial<CoreDeprecatedApiUsageStats>
|
||||
|
@ -93,7 +112,7 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
);
|
||||
|
||||
it('returns removed type deprecated route', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http });
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createDeprecatedRouteDetails({
|
||||
routePath: '/api/test_removed/',
|
||||
routeDeprecationOptions: { reason: { type: 'remove' } },
|
||||
|
@ -129,6 +148,10 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
"level": "critical",
|
||||
"message": Array [
|
||||
"The API \\"GET /api/test_removed/\\" has been called 13 times. The last call was on Sunday, September 1, 2024 6:06 AM -04:00.",
|
||||
Object {
|
||||
"content": "To include information about deprecated API calls in debug logs, edit your Kibana configuration as detailed in [the documentation](https://www.elastic.co/guide/en/kibana/test-branch/logging-settings.html#enable-http-debug-logs).",
|
||||
"type": "markdown",
|
||||
},
|
||||
"This issue has been marked as resolved on Thursday, October 17, 2024 8:06 AM -04:00 but the API has been called 12 times since.",
|
||||
],
|
||||
"title": "The \\"GET /api/test_removed/\\" route is removed",
|
||||
|
@ -138,7 +161,7 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
});
|
||||
|
||||
it('returns migrated type deprecated route', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http });
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createDeprecatedRouteDetails({
|
||||
routePath: '/api/test_migrated/',
|
||||
routeDeprecationOptions: {
|
||||
|
@ -176,6 +199,10 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
"level": "critical",
|
||||
"message": Array [
|
||||
"The API \\"GET /api/test_migrated/\\" has been called 13 times. The last call was on Sunday, September 1, 2024 6:06 AM -04:00.",
|
||||
Object {
|
||||
"content": "To include information about deprecated API calls in debug logs, edit your Kibana configuration as detailed in [the documentation](https://www.elastic.co/guide/en/kibana/test-branch/logging-settings.html#enable-http-debug-logs).",
|
||||
"type": "markdown",
|
||||
},
|
||||
"This issue has been marked as resolved on Thursday, October 17, 2024 8:06 AM -04:00 but the API has been called 12 times since.",
|
||||
],
|
||||
"title": "The \\"GET /api/test_migrated/\\" route is migrated to a different API",
|
||||
|
@ -185,7 +212,7 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
});
|
||||
|
||||
it('returns bumped type deprecated route', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http });
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createDeprecatedRouteDetails({
|
||||
routePath: '/api/test_bumped/',
|
||||
routeDeprecationOptions: { reason: { type: 'bump', newApiVersion: '444' } },
|
||||
|
@ -221,6 +248,10 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
"level": "critical",
|
||||
"message": Array [
|
||||
"The API \\"GET /api/test_bumped/\\" has been called 13 times. The last call was on Sunday, September 1, 2024 6:06 AM -04:00.",
|
||||
Object {
|
||||
"content": "To include information about deprecated API calls in debug logs, edit your Kibana configuration as detailed in [the documentation](https://www.elastic.co/guide/en/kibana/test-branch/logging-settings.html#enable-http-debug-logs).",
|
||||
"type": "markdown",
|
||||
},
|
||||
"This issue has been marked as resolved on Thursday, October 17, 2024 8:06 AM -04:00 but the API has been called 12 times since.",
|
||||
],
|
||||
"title": "The \\"GET /api/test_bumped/\\" route has a newer version available",
|
||||
|
@ -230,7 +261,7 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
});
|
||||
|
||||
it('returns deprecated type deprecated route', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http });
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createDeprecatedRouteDetails({
|
||||
routePath: '/api/test_deprecated/',
|
||||
routeDeprecationOptions: { reason: { type: 'deprecate' }, message: 'additional message' },
|
||||
|
@ -265,6 +296,10 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
"level": "critical",
|
||||
"message": Array [
|
||||
"The API \\"GET /api/test_deprecated/\\" has been called 13 times. The last call was on Sunday, September 1, 2024 6:06 AM -04:00.",
|
||||
Object {
|
||||
"content": "To include information about deprecated API calls in debug logs, edit your Kibana configuration as detailed in [the documentation](https://www.elastic.co/guide/en/kibana/test-branch/logging-settings.html#enable-http-debug-logs).",
|
||||
"type": "markdown",
|
||||
},
|
||||
"This issue has been marked as resolved on Thursday, October 17, 2024 8:06 AM -04:00 but the API has been called 12 times since.",
|
||||
"additional message",
|
||||
],
|
||||
|
@ -275,7 +310,7 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
});
|
||||
|
||||
it('does not return resolved deprecated route', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http });
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createDeprecatedRouteDetails({ routePath: '/api/test_resolved/' });
|
||||
http.getRegisteredDeprecatedApis.mockReturnValue([deprecatedRoute]);
|
||||
usageClientMock.getDeprecatedApiUsageStats.mockResolvedValue([
|
||||
|
@ -290,7 +325,7 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
});
|
||||
|
||||
it('returns never resolved deprecated route', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http });
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createDeprecatedRouteDetails({
|
||||
routePath: '/api/test_never_resolved/',
|
||||
});
|
||||
|
@ -328,6 +363,10 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
"level": "critical",
|
||||
"message": Array [
|
||||
"The API \\"GET /api/test_never_resolved/\\" has been called 13 times. The last call was on Sunday, September 1, 2024 6:06 AM -04:00.",
|
||||
Object {
|
||||
"content": "To include information about deprecated API calls in debug logs, edit your Kibana configuration as detailed in [the documentation](https://www.elastic.co/guide/en/kibana/test-branch/logging-settings.html#enable-http-debug-logs).",
|
||||
"type": "markdown",
|
||||
},
|
||||
],
|
||||
"title": "The \\"GET /api/test_never_resolved/\\" route is removed",
|
||||
},
|
||||
|
@ -335,8 +374,57 @@ describe('#registerApiDeprecationsInfo', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
it('returns internal route access deprecation', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createInternalRouteDetails({});
|
||||
http.getRegisteredDeprecatedApis.mockReturnValue([deprecatedRoute]);
|
||||
usageClientMock.getDeprecatedApiUsageStats.mockResolvedValue([
|
||||
createApiUsageStat(buildApiDeprecationId(deprecatedRoute), {
|
||||
totalMarkedAsResolved: 0,
|
||||
markedAsResolvedLastCalledAt: undefined,
|
||||
}),
|
||||
]);
|
||||
|
||||
const deprecations = await getDeprecations();
|
||||
expect(deprecations).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"apiId": "1.0.0|post|/internal/api",
|
||||
"correctiveActions": Object {
|
||||
"manualSteps": Array [
|
||||
"Identify the origin of these API calls.",
|
||||
"Delete any requests you have that use this API. Check the learn more link for possible alternatives.",
|
||||
"Once you have successfully stopped using this API, mark this issue as resolved. It will no longer appear in the Upgrade Assistant unless another call using this API is detected.",
|
||||
],
|
||||
"mark_as_resolved_api": Object {
|
||||
"apiTotalCalls": 13,
|
||||
"routeMethod": "post",
|
||||
"routePath": "/internal/api/",
|
||||
"routeVersion": "1.0.0",
|
||||
"timestamp": 2024-10-17T12:06:41.224Z,
|
||||
"totalMarkedAsResolved": 0,
|
||||
},
|
||||
},
|
||||
"deprecationType": "api",
|
||||
"documentationUrl": undefined,
|
||||
"domainId": "core.http.access-deprecations",
|
||||
"level": "warning",
|
||||
"message": Array [
|
||||
"The API \\"POST /internal/api/\\" has been called 13 times. The last call was on Sunday, September 1, 2024 6:06 AM -04:00.",
|
||||
"Internal APIs are meant to be used by Elastic services only. You should not use them. External access to these APIs will be restricted.",
|
||||
Object {
|
||||
"content": "To include information in debug logs about calls to APIs that are internal to Elastic, edit your Kibana configuration as detailed in [the documentation](https://www.elastic.co/guide/en/kibana/test-branch/logging-settings.html#enable-http-debug-logs).",
|
||||
"type": "markdown",
|
||||
},
|
||||
],
|
||||
"title": "The \\"POST /internal/api/\\" API is internal to Elastic",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('does not return deprecated routes that have never been called', async () => {
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http });
|
||||
const getDeprecations = createGetApiDeprecations({ coreUsageData, http, docLinks });
|
||||
const deprecatedRoute = createDeprecatedRouteDetails({
|
||||
routePath: '/api/test_never_resolved/',
|
||||
});
|
||||
|
|
|
@ -15,7 +15,11 @@ import { buildApiDeprecationId } from './api_deprecation_id';
|
|||
import type { ApiDeprecationsServiceDeps } from './types';
|
||||
|
||||
export const createGetApiDeprecations =
|
||||
({ http, coreUsageData }: Pick<ApiDeprecationsServiceDeps, 'coreUsageData' | 'http'>) =>
|
||||
({
|
||||
http,
|
||||
coreUsageData,
|
||||
docLinks,
|
||||
}: Pick<ApiDeprecationsServiceDeps, 'coreUsageData' | 'http' | 'docLinks'>) =>
|
||||
async (): Promise<DeprecationsDetails[]> => {
|
||||
const usageClient = coreUsageData.getClient();
|
||||
const deprecatedApis = http.getRegisteredDeprecatedApis();
|
||||
|
@ -43,6 +47,7 @@ export const createGetApiDeprecations =
|
|||
return buildApiRouteDeprecationDetails({
|
||||
apiUsageStats,
|
||||
deprecatedApiDetails,
|
||||
docLinks,
|
||||
});
|
||||
}
|
||||
// if no access is specified then internal is the default
|
||||
|
@ -51,6 +56,7 @@ export const createGetApiDeprecations =
|
|||
return buildApiAccessDeprecationDetails({
|
||||
apiUsageStats,
|
||||
deprecatedApiDetails,
|
||||
docLinks,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -61,10 +67,11 @@ export const registerApiDeprecationsInfo = ({
|
|||
deprecationsFactory,
|
||||
http,
|
||||
coreUsageData,
|
||||
docLinks,
|
||||
}: ApiDeprecationsServiceDeps): void => {
|
||||
const deprecationsRegistery = deprecationsFactory.getRegistry('core.api_deprecations');
|
||||
|
||||
deprecationsRegistery.registerDeprecations({
|
||||
getDeprecations: createGetApiDeprecations({ http, coreUsageData }),
|
||||
getDeprecations: createGetApiDeprecations({ http, coreUsageData, docLinks }),
|
||||
});
|
||||
};
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
|
||||
import { RouterDeprecatedApiDetails } from '@kbn/core-http-server';
|
||||
import { CoreDeprecatedApiUsageStats } from '@kbn/core-usage-data-server';
|
||||
import type { DeprecationDetailsMessage } from '@kbn/core-deprecations-common';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import moment from 'moment';
|
||||
import { DocLinksServiceSetup } from '@kbn/core-doc-links-server';
|
||||
|
||||
export const getApiDeprecationTitle = (details: RouterDeprecatedApiDetails) => {
|
||||
const { routePath, routeMethod, routeDeprecationOptions } = details;
|
||||
|
@ -37,8 +39,9 @@ export const getApiDeprecationTitle = (details: RouterDeprecatedApiDetails) => {
|
|||
|
||||
export const getApiDeprecationMessage = (
|
||||
details: RouterDeprecatedApiDetails,
|
||||
apiUsageStats: CoreDeprecatedApiUsageStats
|
||||
): string[] => {
|
||||
apiUsageStats: CoreDeprecatedApiUsageStats,
|
||||
docLinks: DocLinksServiceSetup
|
||||
): Array<string | DeprecationDetailsMessage> => {
|
||||
const { routePath, routeMethod, routeDeprecationOptions } = details;
|
||||
if (!routeDeprecationOptions) {
|
||||
throw new Error(`Router "deprecated" param is missing for path "${routePath}".`);
|
||||
|
@ -50,7 +53,7 @@ export const getApiDeprecationMessage = (
|
|||
const wasResolvedBefore = totalMarkedAsResolved > 0;
|
||||
const routeWithMethod = `${routeMethod.toUpperCase()} ${routePath}`;
|
||||
|
||||
const messages = [
|
||||
const messages: Array<string | DeprecationDetailsMessage> = [
|
||||
i18n.translate('core.deprecations.apiRouteDeprecation.apiCallsDetailsMessage', {
|
||||
defaultMessage:
|
||||
'The API "{routeWithMethod}" has been called {apiTotalCalls} times. The last call was on {apiLastCalledAt}.',
|
||||
|
@ -60,6 +63,16 @@ export const getApiDeprecationMessage = (
|
|||
apiLastCalledAt: moment(apiLastCalledAt).format('LLLL Z'),
|
||||
},
|
||||
}),
|
||||
{
|
||||
type: 'markdown',
|
||||
content: i18n.translate('core.deprecations.apiRouteDeprecation.enableDebugLogsMessage', {
|
||||
defaultMessage:
|
||||
'To include information about deprecated API calls in debug logs, edit your Kibana configuration as detailed in [the documentation]({enableDeprecationHttpDebugLogsLink}).',
|
||||
values: {
|
||||
enableDeprecationHttpDebugLogsLink: docLinks.links.logging.enableDeprecationHttpDebugLogs,
|
||||
},
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
if (wasResolvedBefore) {
|
||||
|
|
|
@ -33,6 +33,7 @@ export const getIsRouteApiDeprecation = ({
|
|||
export const buildApiRouteDeprecationDetails = ({
|
||||
apiUsageStats,
|
||||
deprecatedApiDetails,
|
||||
docLinks,
|
||||
}: BuildApiDeprecationDetailsParams): DomainDeprecationDetails<ApiDeprecationDetails> => {
|
||||
const { apiId, apiTotalCalls, totalMarkedAsResolved } = apiUsageStats;
|
||||
const { routeVersion, routePath, routeDeprecationOptions, routeMethod } = deprecatedApiDetails;
|
||||
|
@ -46,7 +47,7 @@ export const buildApiRouteDeprecationDetails = ({
|
|||
apiId,
|
||||
title: getApiDeprecationTitle(deprecatedApiDetails),
|
||||
level: deprecationLevel,
|
||||
message: getApiDeprecationMessage(deprecatedApiDetails, apiUsageStats),
|
||||
message: getApiDeprecationMessage(deprecatedApiDetails, apiUsageStats, docLinks),
|
||||
documentationUrl: routeDeprecationOptions.documentationUrl,
|
||||
correctiveActions: {
|
||||
manualSteps: getApiDeprecationsManualSteps(deprecatedApiDetails),
|
||||
|
|
|
@ -11,15 +11,18 @@ import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
|
|||
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
|
||||
import type { RouterDeprecatedApiDetails } from '@kbn/core-http-server';
|
||||
import type { CoreDeprecatedApiUsageStats } from '@kbn/core-usage-data-server';
|
||||
import { DocLinksServiceSetup } from '@kbn/core-doc-links-server';
|
||||
import type { DeprecationsFactory } from '../../deprecations_factory';
|
||||
|
||||
export interface ApiDeprecationsServiceDeps {
|
||||
deprecationsFactory: DeprecationsFactory;
|
||||
http: InternalHttpServiceSetup;
|
||||
coreUsageData: InternalCoreUsageDataSetup;
|
||||
docLinks: DocLinksServiceSetup;
|
||||
}
|
||||
|
||||
export interface BuildApiDeprecationDetailsParams {
|
||||
apiUsageStats: CoreDeprecatedApiUsageStats;
|
||||
deprecatedApiDetails: RouterDeprecatedApiDetails;
|
||||
docLinks: DocLinksServiceSetup;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import { coreUsageDataServiceMock } from '@kbn/core-usage-data-server-mocks';
|
|||
import { configServiceMock } from '@kbn/config-mocks';
|
||||
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
|
||||
import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
|
||||
import { docLinksServiceMock } from '@kbn/core-doc-links-server-mocks';
|
||||
import type { DocLinksServiceSetup } from '@kbn/core-doc-links-server';
|
||||
import { DeprecationsService, DeprecationsSetupDeps } from './deprecations_service';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
|
||||
|
@ -37,7 +39,8 @@ describe('DeprecationsService', () => {
|
|||
coreUsageData = coreUsageDataServiceMock.createSetupContract();
|
||||
router = httpServiceMock.createRouter();
|
||||
http.createRouter.mockReturnValue(router);
|
||||
deprecationsCoreSetupDeps = { http, coreUsageData, logging: loggingMock };
|
||||
const docLinks: DocLinksServiceSetup = docLinksServiceMock.createSetupContract();
|
||||
deprecationsCoreSetupDeps = { http, coreUsageData, logging: loggingMock, docLinks };
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
@ -22,6 +22,7 @@ import type {
|
|||
import { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
|
||||
import type { KibanaRequest } from '@kbn/core-http-server';
|
||||
import { type InternalLoggingServiceSetup } from '@kbn/core-logging-server-internal';
|
||||
import { DocLinksServiceSetup } from '@kbn/core-doc-links-server';
|
||||
import { DeprecationsFactory } from './deprecations_factory';
|
||||
import { registerRoutes } from './routes';
|
||||
import { config as deprecationConfig, DeprecationConfigType } from './deprecation_config';
|
||||
|
@ -51,6 +52,7 @@ export interface DeprecationsSetupDeps {
|
|||
http: InternalHttpServiceSetup;
|
||||
coreUsageData: InternalCoreUsageDataSetup;
|
||||
logging: InternalLoggingServiceSetup;
|
||||
docLinks: DocLinksServiceSetup;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
@ -70,6 +72,7 @@ export class DeprecationsService
|
|||
http,
|
||||
coreUsageData,
|
||||
logging,
|
||||
docLinks,
|
||||
}: DeprecationsSetupDeps): Promise<InternalDeprecationsServiceSetup> {
|
||||
this.logger.debug('Setting up Deprecations service');
|
||||
|
||||
|
@ -106,6 +109,7 @@ export class DeprecationsService
|
|||
deprecationsFactory: this.deprecationsFactory,
|
||||
http,
|
||||
coreUsageData,
|
||||
docLinks,
|
||||
});
|
||||
|
||||
const deprecationsFactory = this.deprecationsFactory;
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
"@kbn/core-usage-data-server-mocks",
|
||||
"@kbn/core-http-router-server-internal",
|
||||
"@kbn/core-logging-server-internal",
|
||||
"@kbn/core-doc-links-server",
|
||||
"@kbn/core-doc-links-server-mocks",
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*",
|
||||
|
|
|
@ -308,6 +308,7 @@ export class Server {
|
|||
http: httpSetup,
|
||||
coreUsageData: coreUsageDataSetup,
|
||||
logging: loggingSetup,
|
||||
docLinks: docLinksSetup,
|
||||
});
|
||||
|
||||
const savedObjectsSetup = await this.savedObjects.setup({
|
||||
|
|
|
@ -414,6 +414,9 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
|
|||
server: {
|
||||
protocol: `${KIBANA_DOCS}settings.html#server-protocol`,
|
||||
},
|
||||
logging: {
|
||||
enableDeprecationHttpDebugLogs: `${KIBANA_DOCS}logging-settings.html#enable-http-debug-logs`,
|
||||
},
|
||||
securitySolution: {
|
||||
artifactControl: `${SECURITY_SOLUTION_DOCS}artifact-control.html`,
|
||||
avcResults: `${ELASTIC_WEBSITE_URL}blog/elastic-security-av-comparatives-business-test`,
|
||||
|
|
|
@ -279,6 +279,9 @@ export interface DocLinks {
|
|||
readonly server: {
|
||||
readonly protocol: string;
|
||||
};
|
||||
readonly logging: {
|
||||
readonly enableDeprecationHttpDebugLogs: string;
|
||||
};
|
||||
readonly securitySolution: {
|
||||
readonly aiAssistant: string;
|
||||
readonly artifactControl: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue