Move datasource/extractor validations to datalayer runtime.#2357
Move datasource/extractor validations to datalayer runtime.#2357elevran wants to merge 1 commit intokubernetes-sigs:mainfrom
Conversation
- Extractors declare their expected input type (unchanged) - DataSource declare their output type and expected Extractor type (new) - Compatibility validation utility functions and tests in plugins/datalayer/source (new, moved) - Datalayer WithConfig() validates compatbility before calling AddExtractor (new) - DataSource can optionaly implement validating interface method to perform specific compatibility checks (new) - Current DataSource checks on AddExtractor and their tests are not changed to minimize the code changes. Signed-off-by: Etai Lev Ran <elevran@gmail.com>
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: elevran The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@elevran: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
|
||
| // ValidateInputTypeCompatible checks if the extractor's expected input type is | ||
| // compatible with the DataSource's output type. | ||
| func ValidateInputTypeCompatible(dataSourceOutput, extractorInput reflect.Type) error { |
There was a problem hiding this comment.
do we expect that those validation checks will be run by anyone other than the runtime? Do we expect the plugins to execute them for example or llm-d main? If not, then this belongs more in the runtime pkg.
There was a problem hiding this comment.
if by runtime you mean pkg/epp/datalayer then it was moved here based on previous feedback (avoid framework from importing packages outside).
I prefer to leave it here to allow framework/*/source implementations to call these if needed.
datalayer.WithConfig() will only call these when working with configuration files (e.g., not in tests or when the datalayer is configured directly - not in code) so we leave it up open for failures in some cases.
There was a problem hiding this comment.
if by runtime you mean pkg/epp/datalayer then it was moved here based on previous feedback (avoid framework from importing packages outside).
Yes, but the main question was: do we expect any logic other than runtime to call it in the first place? if not, why make it part of the interface?
The initial implementation was expecting the plugins to invoke it, but then we discussed that this validation logic should be executed by the runtime (which processes the config and instantiates the plugins), the plugins themselves are not supposed to call it, and so this logic can live in the epp/datalayer as private functions.
There was a problem hiding this comment.
See comments below on calling on addExtractor vs calling on ExtractNotification/Extract.
Let me know which approach you prefer
- leave in framework and validate on adding an extractor (withConfig calling it is redundant in that case); or
- validate on every extraction
Will change to whichever is preferred.
There was a problem hiding this comment.
I think we only need to validate once, the runtime does that before calling AddExtractor (which I think we should remove as well, see the other comment)
| // the data source output type. | ||
| func (dataSrc *HTTPDataSource) AddExtractor(extractor fwkdl.Extractor) error { | ||
| if err := datalayer.ValidateExtractorType(dataSrc.outputType, extractor.ExpectedInputType()); err != nil { | ||
| if err := source.ValidateInputTypeCompatible(dataSrc.OutputType(), extractor.ExpectedInputType()); err != nil { |
There was a problem hiding this comment.
Why do we call it here still? the datalayer runtime calls it already
There was a problem hiding this comment.
when dispatching to an extractor we can trust it to be of the right type (it was validated) or we need to verify the interface at runtime and fail if incompatible.
There was a problem hiding this comment.
I am not following, the epp/datalayer already calls this before it runs AddExtractor, why does the plugin itself has to do it again? The plugin already defined what it produces and what it expects, the runtime is the entity responsible for enforcement when setting things up.
I also think the source should not expose an AddExtractor interface, the runtime is the one that should maintain which extractors are configured for which source and invoke them, the runtime
- maintains the source <-> extractor mapping
- runs the iteration that we currently force all plugins to execute inside the Collect function to invoke Extract on each extractor. To enable this, the
Collectinterface changes to return the data, that the datalayer runtime pass that to the extract call when it iterates over the extractors.
There was a problem hiding this comment.
The idea is to move all mechanical logic to be done by the runtime (validations, maintaining source<->extractor mapping as per the config, invoking the extractors on each collect etc.), the plugins are focused on implementing the plugin specific logic only.
| return fmt.Errorf("extractor %s does not implement NotificationExtractor", ext.TypedName()) | ||
| extractorType := reflect.TypeOf(ext) | ||
| expectedType := reflect.TypeOf((*fwkdl.NotificationExtractor)(nil)).Elem() | ||
| if err := source.ValidateExtractorCompatible(extractorType, expectedType); err != nil { |
There was a problem hiding this comment.
Why do we have to call it here still? The validation is done by the runtime.
There was a problem hiding this comment.
ditto.
Do we validate once on adding the extractor (regardless of if by config or not) or do we validate on every call to Extarct (and if there are multiple extractors, I presume we would want log a message and continue, but not spam the log file...?)
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Following up on comments in #2228:
Notes (relating to comments on #2228)
Which issue(s) this PR fixes:
Fixes #2234
Replaces #2336
Does this PR introduce a user-facing change?: