Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] [UA] Support API Deprecations #196081

Merged
merged 41 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4b24857
finish feature
Bamieh Oct 14, 2024
a46da40
Merge branch 'main' of github.com:elastic/kibana into core/api-deprec…
Bamieh Oct 14, 2024
0ba7595
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 14, 2024
fe1edbf
revert testing example
Bamieh Oct 14, 2024
4642236
update i18n messages
Bamieh Oct 14, 2024
98e1928
Merge branch 'core/api-deprecations' of github.com:Bamieh/kibana into…
Bamieh Oct 14, 2024
f6552c7
remove version example
Bamieh Oct 14, 2024
e4a4b21
i18n_check
Bamieh Oct 14, 2024
e14ff56
fix types
Bamieh Oct 14, 2024
62a3a61
Merge branch 'main' of github.com:elastic/kibana into core/api-deprec…
Bamieh Oct 15, 2024
96d88ef
code review changes
Bamieh Oct 15, 2024
cf26b2b
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 15, 2024
7b003e9
finish deprecated service unit tests
Bamieh Oct 17, 2024
e627a21
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Oct 17, 2024
2f47efd
[CI] Auto-commit changed files from 'make api-docs && make api-docs-s…
kibanamachine Oct 17, 2024
563f5cc
merge main and update types
Bamieh Oct 17, 2024
e34ccc1
tina code reviews
Bamieh Oct 17, 2024
bb3fea6
Merge branch 'core/api-deprecations' of github.com:Bamieh/kibana into…
Bamieh Oct 17, 2024
309b35a
openApi spec fixes
Bamieh Oct 20, 2024
2484b9a
merge main
Bamieh Oct 20, 2024
098e0a8
finalize open spec
Bamieh Oct 20, 2024
f1dc0bb
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Oct 20, 2024
4626672
[CI] Auto-commit changed files from 'make api-docs && make api-docs-s…
kibanamachine Oct 20, 2024
15eaa47
deprecated routes example
Bamieh Oct 20, 2024
21653e8
Merge branch 'core/api-deprecations' of github.com:Bamieh/kibana into…
Bamieh Oct 20, 2024
ae0d20b
update readme
Bamieh Oct 20, 2024
7d66a9f
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 20, 2024
77cb2d4
fix more tests
Bamieh Oct 20, 2024
72c6184
Merge branch 'core/api-deprecations' of github.com:Bamieh/kibana into…
Bamieh Oct 20, 2024
0a7d698
add integration test
Bamieh Oct 21, 2024
ecf62ad
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Oct 21, 2024
43f9a1e
add integration test
Bamieh Oct 21, 2024
a6e14d4
merge main
Bamieh Oct 21, 2024
00c79db
Merge branch 'core/api-deprecations' of github.com:Bamieh/kibana into…
Bamieh Oct 21, 2024
ffda5c3
Merge branch 'main' of github.com:elastic/kibana into core/api-deprec…
Bamieh Oct 21, 2024
a6a0608
update integration test
Bamieh Oct 22, 2024
1370c50
Merge branch 'main' of github.com:elastic/kibana into core/api-deprec…
Bamieh Oct 22, 2024
a1405a7
Update x-pack/plugins/upgrade_assistant/public/application/components…
Bamieh Oct 22, 2024
23c5126
fix type -> replace
Bamieh Oct 22, 2024
6bdb7fd
Merge branch 'core/api-deprecations' of github.com:Bamieh/kibana into…
Bamieh Oct 22, 2024
2e37e03
Merge branch 'main' into core/api-deprecations
elasticmachine Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 121 additions & 11 deletions oas_docs/bundle.json

Large diffs are not rendered by default.

127 changes: 116 additions & 11 deletions oas_docs/bundle.serverless.json

Large diffs are not rendered by default.

127 changes: 116 additions & 11 deletions oas_docs/output/kibana.serverless.staging.yaml

Large diffs are not rendered by default.

127 changes: 116 additions & 11 deletions oas_docs/output/kibana.serverless.yaml

Large diffs are not rendered by default.

132 changes: 121 additions & 11 deletions oas_docs/output/kibana.staging.yaml

Large diffs are not rendered by default.

132 changes: 121 additions & 11 deletions oas_docs/output/kibana.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { i18n } from '@kbn/i18n';
import type { HttpStart } from '@kbn/core-http-browser';
import type { HttpFetchOptionsWithPath, HttpStart } from '@kbn/core-http-browser';
import type {
DomainDeprecationDetails,
DeprecationsGetResponse,
Expand Down Expand Up @@ -47,31 +47,70 @@ export class DeprecationsClient {
return typeof details.correctiveActions.api === 'object';
};

public resolveDeprecation = async (
private getResolveFetchDetails = (
details: DomainDeprecationDetails
): Promise<ResolveDeprecationResponse> => {
): HttpFetchOptionsWithPath | undefined => {
const { domainId, correctiveActions } = details;
// explicit check required for TS type guard
if (typeof correctiveActions.api !== 'object') {
return {
status: 'fail',
reason: i18n.translate('core.deprecations.noCorrectiveAction', {
defaultMessage: 'This deprecation cannot be resolved automatically.',
}),
};
}

const { body, method, path, omitContextFromBody = false } = correctiveActions.api;
try {
await this.http.fetch<void>({
if (correctiveActions.api) {
const { body, method, path, omitContextFromBody = false } = correctiveActions.api;

return {
path,
method,
asSystemRequest: true,
body: JSON.stringify({
...body,
...(omitContextFromBody ? {} : { deprecationDetails: { domainId } }),
}),
});
};
}

if (correctiveActions.mark_as_resolved_api) {
const { routeMethod, routePath, routeVersion, apiTotalCalls, totalMarkedAsResolved } =
correctiveActions.mark_as_resolved_api;
const incrementBy = apiTotalCalls - totalMarkedAsResolved;

return {
path: '/api/deprecations/mark_as_resolved/',
method: 'POST',
asSystemRequest: true,
body: JSON.stringify({
domainId,
routeMethod,
routePath,
routeVersion,
incrementBy,
}),
};
}
};

public resolveDeprecation = async (
details: DomainDeprecationDetails
): Promise<ResolveDeprecationResponse> => {
const { correctiveActions } = details;
const noCorrectiveActionFail = {
status: 'fail' as const,
reason: i18n.translate('core.deprecations.noCorrectiveAction', {
defaultMessage: 'This deprecation cannot be resolved automatically or marked as resolved.',
}),
};

if (
typeof correctiveActions.api !== 'object' &&
typeof correctiveActions.mark_as_resolved_api !== 'object'
) {
return noCorrectiveActionFail;
}

try {
const fetchParams = this.getResolveFetchDetails(details);
if (!fetchParams) {
return noCorrectiveActionFail;
}

await this.http.fetch<void>(fetchParams);
return { status: 'ok' };
} catch (err) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface BaseDeprecationDetails {
* Predefined types are necessary to reduce having similar definitions with different keywords
* across kibana deprecations.
*/
deprecationType?: 'config' | 'feature';
deprecationType?: 'config' | 'api' | 'feature';
/** (optional) link to the documentation for more details on the deprecation. */
documentationUrl?: string;
/** (optional) specify the fix for this deprecation requires a full kibana restart. */
Expand Down Expand Up @@ -70,9 +70,31 @@ export interface BaseDeprecationDetails {
* Check the README for writing deprecations in `src/core/server/deprecations/README.mdx`
*/
manualSteps: string[];
/**
* (optional) The api to be called to mark the deprecation as resolved
* This corrective action when called should not resolve the deprecation
* instead it helps users track manually deprecated apis
* If the API used does resolve the deprecation use `correctiveActions.api`
*/
mark_as_resolved_api?: {
apiTotalCalls: number;
totalMarkedAsResolved: number;
timestamp: Date | number | string;
routePath: string;
routeMethod: string;
routeVersion?: string;
};
};
}

/**
* @public
*/
export interface ApiDeprecationDetails extends BaseDeprecationDetails {
apiId: string;
deprecationType: 'api';
}

/**
* @public
*/
Expand All @@ -91,7 +113,10 @@ export interface FeatureDeprecationDetails extends BaseDeprecationDetails {
/**
* @public
*/
export type DeprecationsDetails = ConfigDeprecationDetails | FeatureDeprecationDetails;
export type DeprecationsDetails =
| ConfigDeprecationDetails
| ApiDeprecationDetails
| FeatureDeprecationDetails;

/**
* @public
Expand Down
Loading