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
[Connector API] Support updating configuration values only #105249
[Connector API] Support updating configuration values only #105249
Conversation
Hi @jedrazb, I've created a changelog YAML for you. |
Pinging @elastic/ent-search-eng (Team:Enterprise Search) |
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.
Overall LGTM, left some comments and questions, nothing blocking, but wanted to check first. Feel free to address it after 8.13, don't want to block anything without a good reason before FF.
...arch/src/main/java/org/elasticsearch/xpack/application/connector/ConnectorConfiguration.java
Outdated
Show resolved
Hide resolved
...arch/src/main/java/org/elasticsearch/xpack/application/connector/ConnectorConfiguration.java
Outdated
Show resolved
Hide resolved
...earch/src/main/java/org/elasticsearch/xpack/application/connector/ConnectorIndexService.java
Outdated
Show resolved
Hide resolved
String updateConfigurationScript = String.format( | ||
Locale.ROOT, | ||
""" | ||
ctx._source.%s = params.%s; | ||
ctx._source.%s = params.%s; | ||
""", | ||
Connector.CONFIGURATION_FIELD.getPreferredName(), | ||
Connector.CONFIGURATION_FIELD.getPreferredName(), | ||
Connector.STATUS_FIELD.getPreferredName(), | ||
Connector.STATUS_FIELD.getPreferredName() | ||
); | ||
Script script = new Script( | ||
ScriptType.INLINE, | ||
"painless", | ||
updateConfigurationScript, | ||
Map.of( | ||
Connector.CONFIGURATION_FIELD.getPreferredName(), | ||
request.getConfiguration(), | ||
Connector.STATUS_FIELD.getPreferredName(), | ||
ConnectorStatus.CONFIGURED.toString() | ||
) | ||
); |
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.
Is this needed, because we don't know the configuration value field names in advance? Looks a bit intimidating at a first glance 😁
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.
This is needed because currently the update ES method is additive, it will merge two dictionaries (configurations): existing with provided one. This is problematic when updating service type where you need to override the config completely, doing it via script means you end up with only new config values (the old one is discarded).
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.
Fair point 👍
* This method supports full configuration replacement or individual configuration value updates. | ||
* If a full configuration is provided, it overwrites all existing configurations in non-additive way. | ||
* If only configuration values are provided, existing configuration object is updated with new values | ||
* provided in the request. | ||
* | ||
* @param request Request for updating connector configuration property. | ||
* @param listener Listener to respond to a successful response or an error. | ||
*/ | ||
public void updateConnectorConfiguration(UpdateConnectorConfigurationAction.Request request, ActionListener<UpdateResponse> listener) { |
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.
nit: The method body is quite long, maybe it's worth to refactor 2-3 blocks of logic out into private methods?
...org/elasticsearch/xpack/application/connector/action/UpdateConnectorConfigurationAction.java
Show resolved
Hide resolved
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.
One additional comment around integration tests
...c/yamlRestTest/resources/rest-api-spec/test/entsearch/335_connector_update_configuration.yml
Show resolved
Hide resolved
…/application/connector/ConnectorIndexService.java Co-authored-by: Tim Grein <tim@4greins.de>
…/application/connector/ConnectorConfiguration.java Co-authored-by: Tim Grein <tim@4greins.de>
…/application/connector/ConnectorConfiguration.java Co-authored-by: Tim Grein <tim@4greins.de>
Changes
{"configuration": {... full config obj..}}
as request payload to do itconfiguration
in request payload overrides config fullyvalues
uses default ES additive update of an objectValidations
values
andconfiguration
cannot both be present and both be nullvalues
keys have to be subset of existing configuration schema. If we have connector with configuration with fields:field_a
,field_b
,field_c
, then thevalues
cannot contain mapping to unknown key, e.g.field_d
but can contain subset, e.g. only update value for fields:field_a
,field_b
. If this is violated we throw informative error message and a 400 status code e.g.:"Unknown [configuration] fields in the request payload: [xd]. Remove them from request or register their schema first."
Testing