-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[RAM] Rule API Type Versioning POC - Create Rule #158786
Conversation
My take on the open questions:
I sort of feel like we should. We haven't in the past because we figured TS would protect us, but there are lot of folks casting stuff in Kibana, prolly not going to be LESS of that with versioned APIs :-).
Would anything that Mike has done with task state help here?
Would Zod help? :-) (I like Zod and I think it's under consideration here). I think worse case we can define these as any, then add a custom validation. We've also extended config-schema before (for
if "domain" only includes types in our public APIs, I think that's fine. Internally, we do need to do some partial stuff, for example when updating runtime status of rules - but I don't think that really matters in this discussion.
Might be nice to have no |
@elasticmachine merge upstream |
…Wu/kibana into rules-versioned-api-types
@elasticmachine merge upstream |
Pinging @elastic/response-ops (Team:ResponseOps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As expected!!!!
lastExecutionDate, | ||
error: null, | ||
warning: null, | ||
}); | ||
|
||
export const getRuleExecutionStatusPending = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can delete this one!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh so this is being used in the new create_rule
file
@@ -0,0 +1,27 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using saved_object.ts
in the file name we can just do so.ts
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Public APIs missing exports
Unknown metric groupsAPI count
ESLint disabled line counts
References to deprecated APIs
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
Resolves: #157883
Summary:
This PR acts as a POC for how we would want to version our rule API types in preparation for the versioning of our HTTP endpoints.
There is now an ES persisted type (called
RuleAttributes
, akin to the oldRawRule
type). This type should never be used at the business logic level as we want the ability not to reference saved object attributes directly in the application. Instead, we should transform this saved-object to its corresponding domain object type.HTTP types (
CreateBodyParams
,RuleResponse
) are now located inx-pack/plugins/alerting/common/routes/rule
with a versioning structure like:And follows the guideline here: https://docs.elastic.dev/kibana-dev-docs/versioning-interfaces
Domain object types (rule for example) are derived from the
config-schema
schemas usingTypeOf
, this was done to facilitate the reuse of validation schemas that we might want to run for strict IO validation, potentially at therulesClient
level.API:
Only the
createRule
endpoint has been converted for the sake of this POC, other endpoints might have broken types that will be fixed once we have a finalized pattern for dealing with versioned types.At the API route level, I think it would be wise to import versioned types in our APIs, this way, it forces the developer to deal with broken types when we have a breaking change to our rule domain object.
The API route level is also responsible for transforming domain objects to response types, usually, this just entails renaming property names from camel case to snake case.
in
create_rule_route.ts
RulesClient -> Create
At the rules client level, we now need to transform saved-objects to the domain objects after we perform CRUD operations on them. We can also consider validating schemas here too since other solutions are using our rules client directly instead of through the API.
I don't think we need to version rules client input and output types since the route level types should deal with breaking changes already. Therefore, we can freely import the latest of any domain object types (Rule, for example)
The flow is the following:
Open questions:
Should we validate input params at both the route and the rules client level? I think we should since our rules client is shared.
How do we want to version and validate rule params? Right now they're typed as generics.
Should we leave all date fields as
string
, even for domain objects? Since config-schema is unable to define aDate
type.Should we support partial rule domain object types at all? I can't really think why we should even for
updates
, since we need to reconstruct the overall rule to send back to the client.Should we have
undefined | null
types in the domain object? I know we neednull
specifically for the ES types since there is a different between updating a field asundefined
ornull
, but this shouldn't manifest itself in the business logic.Checklist