Skip to content

Conversation

felixbarny
Copy link
Member

As discussed in #132566, we'd like to provide private index settings with an IndexSettingsProvider. This is currently not possible because it fails validation for composable index templates (template v2). That's because we first merge all settings from the index template with the ones from the IndexSettingsProviders and then check whether there are private settings.

I've added a way so pass down the settings provided by the IndexSettingsProviders to the validation so that these system-provided settings are allowed to contain private settings.

Another area that needs to be enhanced is to allow downsampling to create indices containing private settings that are copied from the source index. For that reason, I've added a settingsSystemProvided flag to CreateIndexClusterStateUpdateRequest.

@felixbarny felixbarny self-assigned this Aug 29, 2025
@felixbarny felixbarny added >non-issue :Core/Infra/Settings Settings infrastructure and APIs labels Aug 29, 2025
@felixbarny felixbarny marked this pull request as ready for review August 29, 2025 08:00
@elasticsearchmachine elasticsearchmachine added Team:Core/Infra Meta label for core/infra team v9.2.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Aug 29, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@kkrik-es
Copy link
Contributor

The LogsdbIndexModeSettingsProvider already injects private settings:
https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsdbIndexModeSettingsProvider.java#L143

I'm probably missing something here..

@felixbarny
Copy link
Member Author

felixbarny commented Aug 29, 2025

Looks like we're skipping adding the private settings during template validation via this hack:

if (MetadataIndexTemplateService.VALIDATE_INDEX_NAME.equals(indexName)) {
// This index name is used when validating component and index templates, we should skip this check in that case.
// (See MetadataIndexTemplateService#validateIndexTemplateV2(...) method)
return MappingHints.EMPTY;
}

I'd rather have the template validation work on the actual settings than the provider behaving differently during validation.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

I looked at this and left a couple of comments (nothing of substance). I keep having a sneaking suspicion that there's a more elegant way to do this, but it might be the late-Friday-afternoon brain telling me that. I'm going to take another look at it next week.

Comment on lines 1642 to +1651
for (final String key : settings.keySet()) {
final Setting<?> setting = indexScopedSettings.get(key);
if (setting == null) {
assert indexScopedSettings.isPrivateSetting(key) : "expected [" + key + "] to be private but it was not";
} else if (setting.isPrivateIndex()) {
validationErrors.add("private index setting [" + key + "] can not be set explicitly");
}
} else if (setting.isPrivateIndex()
// System-provided settings are always allowed to configure private settings.
// These are typically coming from an IndexSettingProvider.
&& (systemProvided == null || settings.get(key).equals(systemProvided.get(key)) == false)) {
validationErrors.add("private index setting [" + key + "] can not be set explicitly");
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to leave the if statements alone and instead do something like:

for (final String key : settings.filter(s -> systemProvided.hasValue(s.getKey()) == false)).keySet()) {
    …
}

to filter the system-provided settings out of the validation list at the beginning?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would be possible but we can't filter out all settings if they're also in the systemProvided settings. We also need to check if the value is the same to avoid allowing users to override private settings that are also system provided with a different value.

At this point, I'm not sure if the filtering is more readable. Another option to make it more readable is to extract an isSystemProvided method so that the condition becomes:

else if (setting.isPrivateIndex() && isSystemProvided(key, settings, systemProvided) == false)

@@ -961,7 +961,7 @@ private void createDownsampleIndex(
projectId,
downsampleIndexName,
downsampleIndexName
).settings(builder.build()).mappings(mapping).waitForActiveShards(ActiveShardCount.ONE);
).settings(builder.build()).settingsSystemProvided(true).mappings(mapping).waitForActiveShards(ActiveShardCount.ONE);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment about which setting requires this flag?

Copy link
Member Author

Choose a reason for hiding this comment

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

None, yet. I can remove this from the PR and re-add it when introducing the index.dimensions setting in #132566.

@dakrone dakrone self-requested a review August 29, 2025 21:48
@felixbarny felixbarny requested a review from martijnvg September 1, 2025 15:55
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 external-contributor Pull request authored by a developer outside the Elasticsearch team >non-issue Team:Core/Infra Meta label for core/infra team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants