-
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
[ML] AIOps: Log Rate Analysis V2 REST API, replaces references to term
with item
.
#170274
[ML] AIOps: Log Rate Analysis V2 REST API, replaces references to term
with item
.
#170274
Conversation
a28b9c0
to
e2a7168
Compare
Pinging @elastic/ml-ui (:ml) |
setOverrides({ | ||
loaded, | ||
remainingFieldCandidates, | ||
significantItems: data.significantItems as AiopsLogRateAnalysisSchemaSignificantItem[], |
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.
Looks like there is a lot of type casting needed with 'as' - is there a way to remove the need for that?
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 looked into this and I think there is no way around it in this case, all the examples I found for conditional types do the same (or fall back to any
). There is an issue about this in the TypeScript repro which describes this problem, the issue was closed as a design limitation: microsoft/TypeScript#22735
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.
Gave this a test. Left a small comment but LGTM overall ⚡
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.
LGTM
I agree that this type based approach is an improvement over the last.
One observation, with the previous code duplication approach it would be easier to remove the old version (once enough time has passed).
With this approach, the version logic is more complicated and so removing previous versions will require more work.
However the git history problems caused by the code duplication approach outweigh any problems with this approach.
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: cc @walterra |
## Summary Follow up to #170274. Part of #181111 and #181603. We had v1 and v2 of the log rate analysis API for a while now (Nov 23). Originally we did this to practice API versioning for serverless. Enough time has passed so we can remove v1 which this PR does. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Summary
Update 2023-11-09
After the discussions we had I took another attempt at not duplicating all code but adapting the route handler in a way to support both API versions. The updated solution now uses conditional types to allow the handling of both versions. The more tricky bit turned out to be not the updated request body, but the response since it is an NDJSON stream where some messages were updated. In this case also the functions that create these messages were updated with conditional types to be able to create a message that fits the definition of the API version.
The API integration tests originally had these message identifiers in the
expected
section of theirtestData
. I changed that to use helper functions that retrieve the expected messages from the stream according to the expected version. All API integration tests are run on both versions. The functional tests are run only on the newer version since the UI is expected to work with version2
only.To review, I'd recommend using the diff view that ignores whitespace changes: https://github.com/elastic/kibana/pull/170274/files?w=1
Original Description 2023-11-06:
This is a first attempt at versioning a more complex REST API endpoint because of changing request/response bodies. This is for the
log_rate_analysis
endpoint for the AIOps plugin. At this stage of serverless as well as this being an internal endpoint, to do the versioning isn't critical but we thought it's worth doing for practicing the process and having a reference later on on how to do it.Working on this I discovered we probably have to deal with these trade offs:
git blame
.On top of that, I suspect there's not one solution that can be applied to every type of version change we'll encounter with other routes. We might want to settle on a shared directory structure for example though. Some updates might be easier to do and might even be possible to do with a single handler that's able to adapt for the changed route, sometimes it might not be feasible.
For the versioning IMHO it's essential to have API integration tests in place that cover both old and new API version. Again, I went with duplicating the code in this case. More or less the same trade off described above applies to the test code and assertions.
Nice side effect of this PR: I cleaned up the stuff that's being exported from the
common
area from the plugin which helped reduce the client side asynce bundle of theaiops
plugin by more than 200KBytes.General feedback on the structure and approach very welcome of course.
Review note: The duplicated code doesn't add any new logic, it is just about renaming the relevent bits from using
term
references toitem
.Checklist