Skip to content

Commit

Permalink
[8.x] [UA][Core] Surface integrations with internal APIs in upgrade a…
Browse files Browse the repository at this point in the history
…ssistant (#199026) (#199764)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[UA][Core] Surface integrations with internal APIs in upgrade
assistant (#199026)](#199026)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Ahmad
Bamieh","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-12T11:19:22Z","message":"[UA][Core]
Surface integrations with internal APIs in upgrade assistant
(#199026)\n\n## Summary\r\n\r\n> In
#117241 we're surfacing\r\nusage
of APIs marked as `deprecated: true` in the Upgrade Assistant to\r\nhelp
users prepare for a major upgrade. While internal APIs aren't\r\nreally
deprecated in the same sense we are making a breaking change
by\r\nblocking external integrations with these APIs. Since this could
be\r\nequally disruptive to users depending on these APIs it would help
our\r\nusers to surface such usage in the UA too.\r\n\r\nThe `api`
deprecations now have two sub types:\r\n1. routes deprecations
`options.deprecated: { … }`\r\n2. access deprecations `options.access:
'internal'`\r\n\r\nThis PR adds the second `api` deprecation subtype.
The reason i kept one\r\n`api` deprecation type and i didnt create a new
type is that they have\r\nexactly the same registration process but are
triggered by different\r\nattributes. The `api` deprecation is fully
managed by the core team\r\ninternal services and are configured by the
user through the route\r\ninterface so it makes sense to keep them as
one type. I also can see us\r\nadding more subtypes to this and just
piggybacking on the current flow\r\ninstead of duplicating it
everytime.\r\n\r\n\r\n**Checklist**\r\n- [x] Create deprecation
subtype\r\n- [x] Example plugin\r\n- [x] Surface the deprecation in
UA\r\n- [x] Api access deprecation copy (@florent-leborgne )\r\n- [x]
Update README and code annotations\r\n- [x] Unit tests\r\n- [x]
Integration tests\r\n\r\n\r\nCloses
https://github.com/elastic/kibana/issues/194675\r\n\r\n### Design
decisions:\r\nIf the API has both route deprecation
(`options.deprecated: { … }` ) AND\r\nis an internal api
`options.access: 'internal'`\r\n\r\nThe current behavior i went for in
my PR:\r\nI show this API once in the UA under the internal access
deprecation.\r\nWhile showing the route deprecation details if defined.
This seems to\r\nmake the most sense since users should stop using this
API altogether.\r\n\r\n### Copy decisions:\r\n@florent-leborgne wrote
the copy for this deprecation subtype.\r\n<img width=\"1319\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/9a32f6d1-686a-4405-aec6-786ac5e10130\">\r\n\r\n<img
width=\"713\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/1304c98d-4c64-468e-a7d6-19c1193bf678\">\r\n\r\n\r\n##
Testing\r\n\r\nRun kibana locally with the test example plugin that has
deprecated\r\nroutes\r\n```\r\nyarn start
--plugin-path=examples/routing_example
--plugin-path=examples/developer_examples\r\n```\r\n\r\nThe following
comprehensive deprecated routes examples are registered\r\ninside the
folder:\r\n`examples/routing_example/server/routes/deprecated_routes`\r\n\r\nRun
them in the dev console to trigger the deprecation condition so
they\r\nshow up in the UA:\r\n\r\n```\r\nGET
kbn:/api/routing_example/d/internal_deprecated_route?elasticInternalOrigin=false\r\nGET
kbn:/internal/routing_example/d/internal_only_route?elasticInternalOrigin=false\r\nGET
kbn:/internal/routing_example/d/internal_versioned_route?apiVersion=1&elasticInternalOrigin=false\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"a10eb1fe4e55aa0cfbbb4b12a8d740a867463283","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","v8.17.0"],"number":199026,"url":"https://github.com/elastic/kibana/pull/199026","mergeCommit":{"message":"[UA][Core]
Surface integrations with internal APIs in upgrade assistant
(#199026)\n\n## Summary\r\n\r\n> In
#117241 we're surfacing\r\nusage
of APIs marked as `deprecated: true` in the Upgrade Assistant to\r\nhelp
users prepare for a major upgrade. While internal APIs aren't\r\nreally
deprecated in the same sense we are making a breaking change
by\r\nblocking external integrations with these APIs. Since this could
be\r\nequally disruptive to users depending on these APIs it would help
our\r\nusers to surface such usage in the UA too.\r\n\r\nThe `api`
deprecations now have two sub types:\r\n1. routes deprecations
`options.deprecated: { … }`\r\n2. access deprecations `options.access:
'internal'`\r\n\r\nThis PR adds the second `api` deprecation subtype.
The reason i kept one\r\n`api` deprecation type and i didnt create a new
type is that they have\r\nexactly the same registration process but are
triggered by different\r\nattributes. The `api` deprecation is fully
managed by the core team\r\ninternal services and are configured by the
user through the route\r\ninterface so it makes sense to keep them as
one type. I also can see us\r\nadding more subtypes to this and just
piggybacking on the current flow\r\ninstead of duplicating it
everytime.\r\n\r\n\r\n**Checklist**\r\n- [x] Create deprecation
subtype\r\n- [x] Example plugin\r\n- [x] Surface the deprecation in
UA\r\n- [x] Api access deprecation copy (@florent-leborgne )\r\n- [x]
Update README and code annotations\r\n- [x] Unit tests\r\n- [x]
Integration tests\r\n\r\n\r\nCloses
https://github.com/elastic/kibana/issues/194675\r\n\r\n### Design
decisions:\r\nIf the API has both route deprecation
(`options.deprecated: { … }` ) AND\r\nis an internal api
`options.access: 'internal'`\r\n\r\nThe current behavior i went for in
my PR:\r\nI show this API once in the UA under the internal access
deprecation.\r\nWhile showing the route deprecation details if defined.
This seems to\r\nmake the most sense since users should stop using this
API altogether.\r\n\r\n### Copy decisions:\r\n@florent-leborgne wrote
the copy for this deprecation subtype.\r\n<img width=\"1319\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/9a32f6d1-686a-4405-aec6-786ac5e10130\">\r\n\r\n<img
width=\"713\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/1304c98d-4c64-468e-a7d6-19c1193bf678\">\r\n\r\n\r\n##
Testing\r\n\r\nRun kibana locally with the test example plugin that has
deprecated\r\nroutes\r\n```\r\nyarn start
--plugin-path=examples/routing_example
--plugin-path=examples/developer_examples\r\n```\r\n\r\nThe following
comprehensive deprecated routes examples are registered\r\ninside the
folder:\r\n`examples/routing_example/server/routes/deprecated_routes`\r\n\r\nRun
them in the dev console to trigger the deprecation condition so
they\r\nshow up in the UA:\r\n\r\n```\r\nGET
kbn:/api/routing_example/d/internal_deprecated_route?elasticInternalOrigin=false\r\nGET
kbn:/internal/routing_example/d/internal_only_route?elasticInternalOrigin=false\r\nGET
kbn:/internal/routing_example/d/internal_versioned_route?apiVersion=1&elasticInternalOrigin=false\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"a10eb1fe4e55aa0cfbbb4b12a8d740a867463283"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199026","number":199026,"mergeCommit":{"message":"[UA][Core]
Surface integrations with internal APIs in upgrade assistant
(#199026)\n\n## Summary\r\n\r\n> In
#117241 we're surfacing\r\nusage
of APIs marked as `deprecated: true` in the Upgrade Assistant to\r\nhelp
users prepare for a major upgrade. While internal APIs aren't\r\nreally
deprecated in the same sense we are making a breaking change
by\r\nblocking external integrations with these APIs. Since this could
be\r\nequally disruptive to users depending on these APIs it would help
our\r\nusers to surface such usage in the UA too.\r\n\r\nThe `api`
deprecations now have two sub types:\r\n1. routes deprecations
`options.deprecated: { … }`\r\n2. access deprecations `options.access:
'internal'`\r\n\r\nThis PR adds the second `api` deprecation subtype.
The reason i kept one\r\n`api` deprecation type and i didnt create a new
type is that they have\r\nexactly the same registration process but are
triggered by different\r\nattributes. The `api` deprecation is fully
managed by the core team\r\ninternal services and are configured by the
user through the route\r\ninterface so it makes sense to keep them as
one type. I also can see us\r\nadding more subtypes to this and just
piggybacking on the current flow\r\ninstead of duplicating it
everytime.\r\n\r\n\r\n**Checklist**\r\n- [x] Create deprecation
subtype\r\n- [x] Example plugin\r\n- [x] Surface the deprecation in
UA\r\n- [x] Api access deprecation copy (@florent-leborgne )\r\n- [x]
Update README and code annotations\r\n- [x] Unit tests\r\n- [x]
Integration tests\r\n\r\n\r\nCloses
https://github.com/elastic/kibana/issues/194675\r\n\r\n### Design
decisions:\r\nIf the API has both route deprecation
(`options.deprecated: { … }` ) AND\r\nis an internal api
`options.access: 'internal'`\r\n\r\nThe current behavior i went for in
my PR:\r\nI show this API once in the UA under the internal access
deprecation.\r\nWhile showing the route deprecation details if defined.
This seems to\r\nmake the most sense since users should stop using this
API altogether.\r\n\r\n### Copy decisions:\r\n@florent-leborgne wrote
the copy for this deprecation subtype.\r\n<img width=\"1319\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/9a32f6d1-686a-4405-aec6-786ac5e10130\">\r\n\r\n<img
width=\"713\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/1304c98d-4c64-468e-a7d6-19c1193bf678\">\r\n\r\n\r\n##
Testing\r\n\r\nRun kibana locally with the test example plugin that has
deprecated\r\nroutes\r\n```\r\nyarn start
--plugin-path=examples/routing_example
--plugin-path=examples/developer_examples\r\n```\r\n\r\nThe following
comprehensive deprecated routes examples are registered\r\ninside the
folder:\r\n`examples/routing_example/server/routes/deprecated_routes`\r\n\r\nRun
them in the dev console to trigger the deprecation condition so
they\r\nshow up in the UA:\r\n\r\n```\r\nGET
kbn:/api/routing_example/d/internal_deprecated_route?elasticInternalOrigin=false\r\nGET
kbn:/internal/routing_example/d/internal_only_route?elasticInternalOrigin=false\r\nGET
kbn:/internal/routing_example/d/internal_versioned_route?apiVersion=1&elasticInternalOrigin=false\r\n```\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"a10eb1fe4e55aa0cfbbb4b12a8d740a867463283"}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Bamieh and elasticmachine authored Nov 12, 2024
1 parent 32d487f commit cf6110a
Show file tree
Hide file tree
Showing 41 changed files with 921 additions and 310 deletions.
5 changes: 4 additions & 1 deletion examples/routing_example/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ export const DEPRECATED_ROUTES = {
DEPRECATED_ROUTE: '/api/routing_example/d/deprecated_route',
REMOVED_ROUTE: '/api/routing_example/d/removed_route',
MIGRATED_ROUTE: '/api/routing_example/d/migrated_route',
VERSIONED_ROUTE: '/api/routing_example/d/versioned',
VERSIONED_ROUTE: '/api/routing_example/d/versioned_route',
INTERNAL_DEPRECATED_ROUTE: '/api/routing_example/d/internal_deprecated_route',
INTERNAL_ONLY_ROUTE: '/internal/routing_example/d/internal_only_route',
VERSIONED_INTERNAL_ROUTE: '/internal/routing_example/d/internal_versioned_route',
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import { IRouter } from '@kbn/core/server';
import { registerDeprecatedRoute } from './unversioned';
import { registerVersionedDeprecatedRoute } from './versioned';
import { registerInternalDeprecatedRoute } from './internal';

export function registerDeprecatedRoutes(router: IRouter) {
registerDeprecatedRoute(router);
registerVersionedDeprecatedRoute(router);
registerInternalDeprecatedRoute(router);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { IRouter } from '@kbn/core/server';
import { DEPRECATED_ROUTES } from '../../../common';

export const registerInternalDeprecatedRoute = (router: IRouter) => {
router.get(
{
path: DEPRECATED_ROUTES.INTERNAL_DEPRECATED_ROUTE,
validate: false,
options: {
// Explicitly set access is to internal
access: 'internal',
deprecated: {
documentationUrl: 'https://elastic.co/',
severity: 'critical',
message: 'Additonal message for internal deprecated api',
reason: { type: 'deprecate' },
},
},
},
async (ctx, req, res) => {
return res.ok({
body: {
result:
'Called deprecated route with `access: internal`. Check UA to see the deprecation.',
},
});
}
);

router.get(
{
path: DEPRECATED_ROUTES.INTERNAL_ONLY_ROUTE,
validate: false,
// If no access is specified then it defaults to internal
},
async (ctx, req, res) => {
return res.ok({
body: {
result:
'Called route with `access: internal` Although this API is not marked as deprecated it will show in UA. Check UA to see the deprecation.',
},
});
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,72 @@ import type { IRouter } from '@kbn/core/server';
import { DEPRECATED_ROUTES } from '../../../common';

export const registerVersionedDeprecatedRoute = (router: IRouter) => {
const versionedRoute = router.versioned.get({
path: DEPRECATED_ROUTES.VERSIONED_ROUTE,
description: 'Routing example plugin deprecated versioned route.',
access: 'internal',
options: {
excludeFromOAS: true,
},
enableQueryVersion: true,
});

versionedRoute.addVersion(
{
router.versioned
.get({
path: DEPRECATED_ROUTES.VERSIONED_ROUTE,
description: 'Routing example plugin deprecated versioned route.',
access: 'public',
options: {
deprecated: {
documentationUrl: 'https://elastic.co/',
severity: 'warning',
reason: { type: 'bump', newApiVersion: '2' },
excludeFromOAS: true,
},
enableQueryVersion: true,
})
.addVersion(
{
options: {
deprecated: {
documentationUrl: 'https://elastic.co/',
severity: 'warning',
reason: { type: 'deprecate' },
},
},
validate: false,
version: '2023-10-31',
},
validate: false,
version: '1',
},
(ctx, req, res) => {
return res.ok({
body: { result: 'Called deprecated version of the API. API version 1 -> 2' },
});
}
);
(ctx, req, res) => {
return res.ok({
body: { result: 'Called deprecated version of the API "2023-10-31"' },
});
}
);

versionedRoute.addVersion(
{
version: '2',
validate: false,
},
(ctx, req, res) => {
return res.ok({ body: { result: 'Called API version 2' } });
}
);
router.versioned
.get({
path: DEPRECATED_ROUTES.VERSIONED_INTERNAL_ROUTE,
description: 'Routing example plugin deprecated versioned route.',
access: 'internal',
options: {
excludeFromOAS: true,
},
enableQueryVersion: true,
})
.addVersion(
{
options: {
deprecated: {
documentationUrl: 'https://elastic.co/',
severity: 'warning',
reason: { type: 'bump', newApiVersion: '2' },
},
},
validate: false,
version: '1',
},
(ctx, req, res) => {
return res.ok({
body: { result: 'Called internal deprecated version of the API 1.' },
});
}
)
.addVersion(
{
validate: false,
version: '2',
},
(ctx, req, res) => {
return res.ok({
body: { result: 'Called non-deprecated version of the API.' },
});
}
);
};
3 changes: 3 additions & 0 deletions examples/routing_example/server/routes/message_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export function registerGetMessageByIdRoute(router: IRouter) {
router.get(
{
path: `${INTERNAL_GET_MESSAGE_BY_ID_ROUTE}/{id}`,
options: {
access: 'internal',
},
validate: {
params: schema.object({
id: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type {
BaseDeprecationDetails,
ConfigDeprecationDetails,
FeatureDeprecationDetails,
ApiDeprecationDetails,
DeprecationsDetails,
DomainDeprecationDetails,
DeprecationsGetResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export type DeprecationsDetails =
/**
* @public
*/
export type DomainDeprecationDetails = DeprecationsDetails & {
export type DomainDeprecationDetails<ExtendedDetails = DeprecationsDetails> = ExtendedDetails & {
domainId: string;
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type {
ApiDeprecationDetails,
DomainDeprecationDetails,
} from '@kbn/core-deprecations-common';

import type { PostValidationMetadata } from '@kbn/core-http-server';
import type { BuildApiDeprecationDetailsParams } from '../types';
import {
getApiDeprecationMessage,
getApiDeprecationsManualSteps,
getApiDeprecationTitle,
} from './i18n_texts';

export const getIsAccessApiDeprecation = ({
isInternalApiRequest,
isPublicAccess,
}: PostValidationMetadata): boolean => {
const isNotPublicAccess = !isPublicAccess;
const isNotInternalRequest = !isInternalApiRequest;

return !!(isNotPublicAccess && isNotInternalRequest);
};

export const buildApiAccessDeprecationDetails = ({
apiUsageStats,
deprecatedApiDetails,
}: BuildApiDeprecationDetailsParams): DomainDeprecationDetails<ApiDeprecationDetails> => {
const { apiId, apiTotalCalls, totalMarkedAsResolved } = apiUsageStats;
const { routeVersion, routePath, routeDeprecationOptions, routeMethod } = deprecatedApiDetails;

const deprecationLevel = routeDeprecationOptions?.severity || 'warning';

return {
apiId,
title: getApiDeprecationTitle(deprecatedApiDetails),
level: deprecationLevel,
message: getApiDeprecationMessage(deprecatedApiDetails, apiUsageStats),
documentationUrl: routeDeprecationOptions?.documentationUrl,
correctiveActions: {
manualSteps: getApiDeprecationsManualSteps(),
mark_as_resolved_api: {
routePath,
routeMethod,
routeVersion,
apiTotalCalls,
totalMarkedAsResolved,
timestamp: new Date(),
},
},
deprecationType: 'api',
domainId: 'core.http.access-deprecations',
};
};
Loading

0 comments on commit cf6110a

Please sign in to comment.