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

Prepare the connector GetAll API for versioning #162799

Merged
merged 18 commits into from
Aug 23, 2023

Conversation

ersin-erdal
Copy link
Contributor

@ersin-erdal ersin-erdal commented Jul 31, 2023

Part of: https://github.com/elastic/response-ops-team/issues/125

This PR intends to prepare the GET ${BASE_ACTION_API_PATH}/connectors API for versioning as shown in the above issue.

@ersin-erdal ersin-erdal added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.10.0 labels Jul 31, 2023
@ersin-erdal ersin-erdal marked this pull request as ready for review August 2, 2023 11:25
@ersin-erdal ersin-erdal requested a review from a team as a code owner August 2, 2023 11:25
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

Copy link
Contributor Author

@ersin-erdal ersin-erdal Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use this to validate getAll API response?

@ymao1 ymao1 requested a review from JiaweiWu August 2, 2023 12:26
id: schema.string(),
name: schema.string(),
actionTypeId: schema.string(),
config: schema.maybe(schema.recordOf(schema.string(), schema.any())),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we get the config schema from the connectorType (validate.config.schema) and use here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be worth exploring as a follow up. We may need a fn like getConnectorSchema where it returns this schema with the config and secrets having proper validation.

ersin-erdal and others added 2 commits August 9, 2023 11:53
# Conflicts:
#	x-pack/plugins/actions/server/actions_client/actions_client.ts
Copy link
Contributor

@JiaweiWu JiaweiWu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good generally, just some comments regarding using versioned types in versioned files

isSystemAction,
...res
}) => ({
...res,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should avoid spreading for transforms, especially for versioned transforms to avoid properties accidentally getting into response types. I think it would be better if we were more specific about the properties.


export const transformGetAllConnectorsResponse: RewriteResponseCase<FindConnectorResult[]> = (
results
): ConnectorResponse[] => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the versioned type here since this is also a versioned file (ConnectorResponseV1). It let's us know to increment this file when the underlying schema has changed

import { ConnectorResponse } from '../../../../../../common/routes/connector/response';
import { RewriteResponseCase } from '../../../../../../common/rewrite_request_case';

export const transformGetAllConnectorsResponse: RewriteResponseCase<FindConnectorResult[]> = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using RewriteResponseCase, I think we should be explicit with the type transforms. I address this in a later comment.

const actionsClient = (await context.actions).getActionsClient();
const result = await actionsClient.getAll();
return res.ok({
body: transformGetAllConnectorsResponse(result),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the V1 version of the transform, it will let us know when the response schema has changed.

Also I like to version the body explicitly:

const responseBody: ConnectorResponseV1 = transformGetAllConnectorsResponse(result)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing Jiawei. I addressed all the comments.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
actions 269 261 -8

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
actions 27 28 +1
Unknown metric groups

API count

id before after diff
actions 275 267 -8

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@ersin-erdal ersin-erdal self-assigned this Aug 16, 2023
Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM after @JiaweiWu 's feedback 👍 great work and thanks for doing the terminology renames at the same time, it will make things much easier for everyone to understand 🙏

id: schema.string(),
name: schema.string(),
actionTypeId: schema.string(),
config: schema.maybe(schema.recordOf(schema.string(), schema.any())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be worth exploring as a follow up. We may need a fn like getConnectorSchema where it returns this schema with the config and secrets having proper validation.

@ersin-erdal ersin-erdal merged commit d65b02c into elastic:main Aug 23, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 23, 2023
@ersin-erdal ersin-erdal deleted the 125-move-get-all branch August 23, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.11.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

6 participants