Skip to content

Support dependent validation for index settings #70144

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

Conversation

henningandersen
Copy link
Contributor

A setting validator can declare settings that the validation depends on,
but when updating index settings, we eagerly validate the settings
before submitting the cluster state update and here we do not know the
existing settings. With this commit, we ensure that the pre-validation
works with such validators, letting the validator validate syntax
(validate(value)) only.

Relates #70141.

A setting validator can declare settings that the validation depends on,
but when updating index settings, we eagerly validate the settings
before submitting the cluster state update and here we do not know the
existing settings. With this commit, we ensure that the pre-validation
works with such validators, letting the validator validate syntax
(validate(value)) only.

Relates elastic#70141.
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Mar 9, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@rjernst
Copy link
Member

rjernst commented Mar 10, 2021

After reading through this, I was surprised to learn about this validateWithoutDependencies method. I did not realize it even existed, and it appears it is only used in exactly one place (for updates) and does not have any tests. A method with a single use is something we are likely to re-evaluate its usefulness, and here I think it is no different. I'm not sure if a PR came up today adding this method that we would accept it.

With that said, I'm trying to understand more about why not validating dependent settings is necessary in this case.

we eagerly validate the settings before submitting the cluster state update and here we do not know the existing settings

Why would we not know all the settings? If we need to wait for a cluster state update, should the master be doing this validation and the update code should defer to that and trust the cluster state update will take care of it?

Ultimately I'm concerned that adding more uses of an untested method will make it harder to cleanup the settings infrastructure, which is in dire need of some work.

@henningandersen
Copy link
Contributor Author

@rjernst thanks for looking into this.

I believe you are right for a long term solution, we could certainly improve this. However, this needs to go into 7.12.0 and I think shaking the code too much is not the right choice there.

The line causing this to fail for index settings with validators that depend on other settings is this:

where we validate most of the incoming settings. Then we validate some more inside the cluster state update. It is not entirely clear to me why we prevalidate the settings. If we remove that, the need for the validateDependencies boolean also goes away. We can also let the prevalidation calculate the combined settings first based on "current state".

There is a little bit of trickyness in removing it:

  • The check inside the cluster state update deliberately does not check private settings (but only those listed in IndexScopedSettings.isPrivateSetting. The prevalidation also checks those.
  • The check inside the cluster state update only checks if a change happens. Hopefully existing settings are valid, so not a big deal.

I will try to work on an alternative today.

Index update settings does prevalidation primarily to ensure all keys
are valid. With this change, we skip validating values during
prevalidation, the final settings applied to each index are still
validated in MetadataUpdateSettingsService.
@henningandersen
Copy link
Contributor Author

AFAICS, we prevalidate the settings primarily to ensure the keys are valid before trying to apply it to all the indices. I went in the direction of disabling value validation for this prevalidation, alleviating your concern about the extra use of the validateWithoutDependencies method.

This gives an error report of all illegal keys up front and then for the first failing index an error report of the illegal values.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Henning! Changing this parameter to validateValues makes a lot more sense to me, and I'm glad you were able to avoid using validateWithoutDependencies. LGTM.

@henningandersen
Copy link
Contributor Author

Thanks for the speedy review, Ryan.

@henningandersen henningandersen merged commit 5de056b into elastic:master Mar 10, 2021
henningandersen added a commit to henningandersen/elasticsearch that referenced this pull request Mar 10, 2021
A setting validator can declare settings that the validation depends on,
but when updating index settings, we eagerly validate the settings
before submitting the cluster state update and here we do not know the
existing settings. With this commit, we ensure that the pre-validation
only validates the keys and not the values, leaving the value validation
to after we have combined existing settings with the new settings on a
per index basis.
henningandersen added a commit that referenced this pull request Mar 11, 2021
A setting validator can declare settings that the validation depends on,
but when updating index settings, we eagerly validate the settings
before submitting the cluster state update and here we do not know the
existing settings. With this commit, we ensure that the pre-validation
only validates the keys and not the values, leaving the value validation
to after we have combined existing settings with the new settings on a
per index basis.
henningandersen added a commit that referenced this pull request Mar 11, 2021
A setting validator can declare settings that the validation depends on,
but when updating index settings, we eagerly validate the settings
before submitting the cluster state update and here we do not know the
existing settings. With this commit, we ensure that the pre-validation
only validates the keys and not the values, leaving the value validation
to after we have combined existing settings with the new settings on a
per index basis.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Settings Settings infrastructure and APIs >non-issue Team:Core/Infra Meta label for core/infra team v7.12.0 v7.13.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants