Skip to content
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

Conversation

jedrazb
Copy link
Member

@jedrazb jedrazb commented Feb 7, 2024

Changes

  • Support updating connector configuration values directly with:
PUT _connector/{id}/_configuration
{
   "values": {"key1": "value", "key2": 42}
}
  • Connector full configuration schema has to be registered first, you can pass {"configuration": {... full config obj..}} as request payload to do it
  • passing configuration in request payload overrides config fully
  • passing values uses default ES additive update of an object

Validations

  • values and configuration cannot both be present and both be null
  • values keys have to be subset of existing configuration schema. If we have connector with configuration with fields: field_a , field_b, field_c, then the values 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

  • Added unit tests - but need to skip given that we still didn't figure out how to register connector index template mappings for unit tests, mappings are inferred for nested object and this makes tests to fail
  • Comprehensive e2e tests
  • Tested manually

@jedrazb jedrazb added >enhancement :EnterpriseSearch/Application Enterprise Search Team:Enterprise Search Meta label for Enterprise Search team labels Feb 7, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @jedrazb, I've created a changelog YAML for you.

@jedrazb jedrazb marked this pull request as ready for review February 7, 2024 15:42
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ent-search-eng (Team:Enterprise Search)

Copy link
Contributor

@timgrein timgrein left a 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.

Comment on lines +409 to +430
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()
)
);
Copy link
Contributor

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 😁

Copy link
Member Author

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).

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor

@timgrein timgrein left a 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

jedrazb and others added 4 commits February 8, 2024 16:57
…/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>
@jedrazb jedrazb merged commit 6811616 into elastic:main Feb 12, 2024
14 checks passed
martijnvg pushed a commit to martijnvg/elasticsearch that referenced this pull request Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :EnterpriseSearch/Application Enterprise Search Team:Enterprise Search Meta label for Enterprise Search team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants