[Improve][Connector-V2] Migrate Elasticsearch validation to declarative OptionRule#11122
[Improve][Connector-V2] Migrate Elasticsearch validation to declarative OptionRule#11122nzw921rx wants to merge 3 commits into
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for working on this. I went through the full diff and traced the actual source / sink / catalog creation paths on the current dev base.
The source-side and sink-side migration to declarative OptionRule + Conditions is moving in the right direction. In both paths the new rules are on the real hot path:
Source creation
-> FactoryUtil.createAndPrepareSource(...) [seatunnel-api/.../FactoryUtil.java:184-193]
-> ConfigValidator.validate(sourceFactory.optionRule()) [L191]
-> ElasticsearchSourceFactory.createSource(...)
-> new ElasticsearchSource(...)
Sink creation
-> FactoryUtil.createAndPrepareSink(...) [seatunnel-api/.../FactoryUtil.java:210-260]
-> ConfigValidator.validate(tableSinkFactory.optionRule()) [L252]
-> ElasticsearchSinkFactory.createSink(...)
I did find one blocker before this can merge:
ElasticSearchCatalogFactory.optionRule()is not on the real catalog creation path today.- Real path:
Catalog resolution
-> CatalogTableUtil.getCatalogTables(...) [seatunnel-api/.../CatalogTableUtil.java:101-142]
-> FactoryUtil.createOptionalCatalog(...) [seatunnel-api/.../FactoryUtil.java:287-295]
-> optionalFactory.map(catalogFactory -> catalogFactory.createCatalog(...))
- Unlike the source/sink paths,
FactoryUtil.createOptionalCatalog(...)does not callConfigValidator.of(options).validate(catalogFactory.optionRule())beforecreateCatalog(...). - Because of that, the new rules in
connector-elasticsearch/.../ElasticSearchCatalogFactory.java:58-90are effectively dead on the currentdevbase. They only run in the new unit test, where the test invokesConfigValidatormanually. - That means the PR description currently overstates the result for catalogs: invalid Elasticsearch catalog configs are still not rejected on the real submission path; they can still fail later in
catalog.open()/catalog.getTables(...).
The factory tests themselves look deterministic and non-flaky, but they do not cover this real catalog runtime path, so they miss the gap above.
My merge conclusion for the current head is: fix before merge.
What I would suggest:
- Option A: include the missing catalog validation in
FactoryUtil.createOptionalCatalog(...), so the catalog path matches the source/sink validation model end-to-end. - Option B: if you want to keep this PR scoped to Elasticsearch only, then please drop the catalog migration/tests from this PR for now and land them after the shared catalog validation path is available.
Happy to re-review once you push an update.
@DanielLeens thanks your review ,PR #11127 Fixed |
|
Thanks for the update. The catalog-validation gap I called out is the shared |
153ad14 to
9782157
Compare
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for the migration work here. I re-checked the current head from the source factory rule through the shared validator helpers and the added tests, and I do not see a source-level blocker.
What this PR fixes
- User pain: Elasticsearch index/auth/sql-query validation was scattered and gave inconsistent submission-time feedback.
- Fix approach: The PR moves the connector to declarative
OptionRulevalidation and sharedElasticsearchValidatorshelpers across source/sink/catalog. - One-line summary: On the current head, the submission-time validation contract is much closer to the real Elasticsearch runtime expectations.
Runtime path I traced
Job submission
-> `ElasticsearchSourceFactory.optionRule()` requires index/index_list, validates auth combinations, and requires `sql_query` for SQL search
Shared helper path
-> `ElasticsearchValidators.ApiKeyEncodedFormatValidator` validates the encoded `id:key` form
Result
-> invalid Elasticsearch configs fail earlier and more consistently
Key findings
- The normal submission path hits these rules directly.
- The shared encoded-key validator makes the auth contract more consistent across entry points.
- I do not see a source-level blocker on the current head.
Blocking items
None at the source-code level on the current head.
Other review notes
- No additional non-blocking source-level comments from this round.
Compatibility and side effects
- Compatibility: Fully backward compatible. This mostly makes invalid configs fail earlier.
- Side effects: No meaningful performance or resource-model downside from the new rules.
- Error handling / logging: Submission-time validation feedback is more complete and consistent now.
- Tests: The added tests cover the key index/auth/sql-query cases and do not show obvious flaky patterns.
- Docs: No extra docs update is required for this validation migration.
- CI: The red CI I traced is a Windows unit-test failure complaining that
PulsarSinkFactoryis missingMULTI_TABLE_SINK_REPLICA. That is unrelated to this Elasticsearch PR and should go away once the branch is rebased onto adevthat already contains #11160 (or the equivalent fix).
Merge verdict
- I do not see a blocker on the current head. The declarative Elasticsearch validation path looks consistent with the expected runtime contract.
…k for username/password
9782157 to
dfc5560
Compare
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. I re-reviewed the latest head from the real Elasticsearch source / sink / catalog creation paths again, not only the newly added validator helpers.
I also rechecked the exact blocker from my earlier review. That blocker is now resolved on the current head because the shared catalog entry path does validate catalogFactory.optionRule() before createCatalog(...):
Catalog creation
-> FactoryUtil.createOptionalCatalog(...) [FactoryUtil.java:287-299]
-> ConfigValidator.validate(catalogFactory.optionRule())
-> ElasticSearchCatalogFactory.createCatalog(...)
What this PR solves
- User pain: Elasticsearch config validation used to be scattered across source / sink / auth-provider runtime checks, which led to inconsistent submission-time feedback.
- Fix approach: the PR moves those checks into declarative
OptionRule + Conditionsrules, plus shared reusable validators. - One-line summary: on the current head, the Elasticsearch submission-time validation contract is now consistently enforced on the real source, sink, and catalog paths.
Runtime chain I checked
Source creation
-> FactoryUtil.createAndPrepareSource(...)
-> ConfigValidator.validate(ElasticsearchSourceFactory.optionRule())
-> ElasticsearchSourceFactory.createSource(...)
-> new ElasticsearchSource(...)
Sink creation
-> FactoryUtil.createAndPrepareSink(...)
-> ConfigValidator.validate(ElasticsearchSinkFactory.optionRule())
-> ElasticsearchSinkFactory.createSink(...)
Catalog creation
-> FactoryUtil.createOptionalCatalog(...)
-> ConfigValidator.validate(ElasticSearchCatalogFactory.optionRule())
-> ElasticSearchCatalogFactory.createCatalog(...)
Findings
- The earlier catalog-path blocker is fixed on the current head.
- The shared encoded API-key validator is now reused consistently across source / sink / catalog.
- I do not see a reopened source-level blocker in the current diff.
Tests / stability
- The new tests are still structurally stable: pure in-memory validation tests, no sleeps, no ports, no containers, and no async timing assumptions.
- Coverage is materially better now for auth combinations, SQL search validation, and catalog validation.
CI
- The latest
Buildis green on the current head. - I am not relying on CI alone here; the source-level blocker from the earlier review is also resolved.
Merge conclusion
Conclusion: can merge
- Blocking items
- None from Daniel's side on the current head.
- Suggested but non-blocking follow-up
- The note in
ElasticsearchSourceabout per-entryindex_listconfigs not being declaratively validated is reasonable to keep visible for future hardening, but I am not treating that as a blocker for this PR.
Overall this looks good to me on the latest revision.
Purpose of this pull request
Related #11007
OptionRule + ConditionsoptionRule()Scope migrated:
ElasticsearchSourceFactoryElasticsearchSinkFactoryElasticSearchCatalogFactoryElasticsearchSource(remove constructor-side config checks now handled byoptionRule)BasicAuthProvider/ApiKeyAuthProvider/ApiKeyEncodedAuthProvider(remove redundant validate checks)ElasticsearchValidatorsDoes this PR introduce any user-facing change?
Yes, minor validation behavior improvements:
Earlier and clearer submission-time validation
index/index_listsearch_type=SQLrequires non-blanksql_queryusername/passwordmust appear togetherauth_type=api_keyrequires non-blankauth.api_key_idandauth.api_keyauth_type=api_key_encodedrequires non-blank and valid Base64id:keyformatAggregated validation errors
ConditionExtensionvalidators returnfalse(instead of throwing), so multiple config issues can be returned together in one validation result.Catalog validation is now fully declared
ElasticSearchCatalogFactorynow defines required/optional/auth-related rules inoptionRule(), enabling consistent validation metadata export via REST API and CLI.How was this patch tested?