[APM] POC: type-check aggregations based on runtime types#43080
Closed
dgieselaar wants to merge 1 commit intoelastic:masterfrom
Closed
[APM] POC: type-check aggregations based on runtime types#43080dgieselaar wants to merge 1 commit intoelastic:masterfrom
dgieselaar wants to merge 1 commit intoelastic:masterfrom
Conversation
Contributor
💚 Build Succeeded |
Contributor
Author
|
Closing in favor of #48394. IMHO, TypeScript is more expressive, and while |
Contributor
💔 Build Failed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We're currently exploring across observability how
io-tscould help us. Infra + Logs addedio-tsfor their routes as well as for decoding Elasticsearch responses.io-tsis capable of generating both runtime checks and types from the same source. @sqren pointed out that this is a safer way of getting type safety as the runtime checks mean that our assumptions about Elasticsearch responses (which could be wrong) will be verified. However, leaving it up to the consumer to explicitly decode (and thus type) responses can (will) be cumbersome.This is a quick demo of how we could have runtime checks + inferred type safety for ES queries from the same source of truth. It adds
io-tsruntime types for both input and output of aggregations, and uses the TS types generated to check the ES query input and infer the type for its response.Some thoughts:
io-tstypes are incorrect, but our code can still successfully run, perhaps because we don't care about the part where ourio-tstype is incorrect. One benefit of the explicit typing that infra+logs use is that the broadness of the check is less of a concern.io-tstypes to be able to compare both approaches properly. Any volunteers? 👻io-tstype forhitsas well, but I'm stubbing that right now because we'd otherwise have to createio-tsfor all our documents.(I didn't actually implement the runtime type checks for input & output, but I imagine the types are the hard part, and the runtime code should be fairly easy to implement (knocks on wood)).