Skip to content

New per-project only settings can be defined and used by components #127280

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

Merged
merged 21 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7a5d446
New per-project only settings can be defined and used by components
alexey-ivanov-es Apr 23, 2025
6eedbb4
Update docs/changelog/127252.yaml
alexey-ivanov-es Apr 23, 2025
a7ab20d
Merge branch 'main' into per-project-settings
alexey-ivanov-es Apr 23, 2025
0c45219
[CI] Auto commit changes from spotless
elasticsearchmachine Apr 23, 2025
20732ae
Fix tests
alexey-ivanov-es Apr 23, 2025
671ae16
Remove comments
alexey-ivanov-es Apr 23, 2025
efebd32
[CI] Auto commit changes from spotless
elasticsearchmachine Apr 23, 2025
1d42716
Update docs/changelog/127280.yaml
alexey-ivanov-es Apr 23, 2025
0d60756
Delete old changelog file
alexey-ivanov-es Apr 23, 2025
94b9fcd
Address review comments
alexey-ivanov-es Apr 23, 2025
a8a31c3
Move ProjectSettingsUpdater to serverless
alexey-ivanov-es Apr 24, 2025
1d6ae73
Delete docs/changelog/127280.yaml
alexey-ivanov-es Apr 24, 2025
eebe304
Merge branch 'main' into per-project-settings
alexey-ivanov-es Apr 24, 2025
e040c9d
Fix tests
alexey-ivanov-es Apr 24, 2025
0234193
Fix a bug in the cluster state application
alexey-ivanov-es Apr 28, 2025
90f3c75
Make abstract
alexey-ivanov-es Apr 28, 2025
910fd79
Merge branch 'main' into per-project-settings
alexey-ivanov-es Apr 28, 2025
dfc13a3
Make ingest.geoip.downloader.enabled project-scoped
alexey-ivanov-es Apr 29, 2025
53d12e5
Merge branch 'main' into per-project-settings
alexey-ivanov-es Apr 29, 2025
589105e
Merge branch 'main' into per-project-settings
alexey-ivanov-es Apr 30, 2025
59adba1
Merge branch 'main' into per-project-settings
alexey-ivanov-es Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public final class GeoIpDownloaderTaskExecutor extends PersistentTasksExecutor<G
"ingest.geoip.downloader.enabled",
ENABLED_DEFAULT,
Setting.Property.Dynamic,
Setting.Property.NodeScope
Setting.Property.NodeScope,
Setting.Property.ProjectScope
);
public static final Setting<TimeValue> POLL_INTERVAL_SETTING = Setting.timeSetting(
"ingest.geoip.downloader.poll.interval",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ static TransportVersion def(int id) {
public static final TransportVersion RANDOM_SAMPLER_QUERY_BUILDER = def(9_063_0_00);
public static final TransportVersion SETTINGS_IN_DATA_STREAMS = def(9_064_0_00);
public static final TransportVersion INTRODUCE_FAILURES_LIFECYCLE = def(9_065_0_00);
public static final TransportVersion PROJECT_METADATA_SETTINGS = def(9_066_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,13 @@ private MetadataDiff(StreamInput in) throws IOException {
RESERVED_DIFF_VALUE_READER
);

singleProject = new ProjectMetadata.ProjectMetadataDiff(indices, templates, projectCustoms, DiffableUtils.emptyDiff());
singleProject = new ProjectMetadata.ProjectMetadataDiff(
indices,
templates,
projectCustoms,
DiffableUtils.emptyDiff(),
Settings.EMPTY_DIFF
);
multiProject = null;
} else {
fromNodeBeforeMultiProjectsSupport = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public class ProjectMetadata implements Iterable<IndexMetadata>, Diffable<Projec
private volatile SortedMap<String, IndexAbstraction> indicesLookup;
private final Map<String, MappingMetadata> mappingsByHash;

private final Settings settings;

private final IndexVersion oldestIndexVersion;

@SuppressWarnings("this-escape")
Expand All @@ -122,6 +124,7 @@ private ProjectMetadata(
String[] visibleClosedIndices,
SortedMap<String, IndexAbstraction> indicesLookup,
Map<String, MappingMetadata> mappingsByHash,
Settings settings,
IndexVersion oldestIndexVersion
) {
this.id = id;
Expand All @@ -140,6 +143,7 @@ private ProjectMetadata(
this.visibleClosedIndices = visibleClosedIndices;
this.indicesLookup = indicesLookup;
this.mappingsByHash = mappingsByHash;
this.settings = settings;
this.oldestIndexVersion = oldestIndexVersion;
assert assertConsistent();
}
Expand Down Expand Up @@ -221,6 +225,7 @@ public ProjectMetadata withLifecycleState(Index index, LifecycleExecutionState l
visibleClosedIndices,
indicesLookup,
mappingsByHash,
settings,
oldestIndexVersion
);
}
Expand Down Expand Up @@ -254,6 +259,7 @@ public ProjectMetadata withIndexSettingsUpdates(Map<Index, Settings> updates) {
visibleClosedIndices,
indicesLookup,
mappingsByHash,
settings,
oldestIndexVersion
);
}
Expand Down Expand Up @@ -288,6 +294,7 @@ public ProjectMetadata withAllocationAndTermUpdatesOnly(Map<String, IndexMetadat
visibleClosedIndices,
indicesLookup,
mappingsByHash,
settings,
oldestIndexVersion
);
}
Expand Down Expand Up @@ -376,6 +383,7 @@ public ProjectMetadata withAddedIndex(IndexMetadata index) {
updatedVisibleClosedIndices,
null,
updatedMappingsByHash,
settings,
IndexVersion.min(index.getCompatibilityVersion(), oldestIndexVersion)
);
}
Expand Down Expand Up @@ -727,6 +735,10 @@ public Map<String, IndexTemplateMetadata> templates() {
return templates;
}

public Settings settings() {
return settings;
}

/**
* Checks whether the provided index is a data stream.
*/
Expand Down Expand Up @@ -1097,6 +1109,9 @@ public boolean isIndexManagedByILM(IndexMetadata indexMetadata) {
}

static boolean isStateEquals(ProjectMetadata project1, ProjectMetadata project2) {
if (project1.settings().equals(project2.settings()) == false) {
return false;
}
if (project1.templates().equals(project2.templates()) == false) {
return false;
}
Expand Down Expand Up @@ -1130,6 +1145,7 @@ public static class Builder {
private final ImmutableOpenMap.Builder<String, IndexTemplateMetadata> templates;
private final ImmutableOpenMap.Builder<String, Metadata.ProjectCustom> customs;
private final ImmutableOpenMap.Builder<String, ReservedStateMetadata> reservedStateMetadata;
private Settings settings = Settings.EMPTY;

private SortedMap<String, IndexAbstraction> previousIndicesLookup;

Expand All @@ -1147,6 +1163,7 @@ public static class Builder {
this.templates = ImmutableOpenMap.builder(projectMetadata.templates);
this.customs = ImmutableOpenMap.builder(projectMetadata.customs);
this.reservedStateMetadata = ImmutableOpenMap.builder(projectMetadata.reservedStateMetadata);
this.settings = projectMetadata.settings;
this.previousIndicesLookup = projectMetadata.indicesLookup;
this.mappingsByHash = new HashMap<>(projectMetadata.mappingsByHash);
this.checkForUnusedMappings = false;
Expand Down Expand Up @@ -1525,6 +1542,11 @@ public Builder removeReservedState(ReservedStateMetadata metadata) {
return this;
}

public Builder settings(Settings settings) {
this.settings = settings;
return this;
}

public Builder indexGraveyard(final IndexGraveyard indexGraveyard) {
return putCustom(IndexGraveyard.TYPE, indexGraveyard);
}
Expand Down Expand Up @@ -1684,6 +1706,7 @@ public ProjectMetadata build(boolean skipNameCollisionChecks) {
visibleClosedIndicesArray,
indicesLookup,
Collections.unmodifiableMap(mappingsByHash),
settings,
IndexVersion.fromId(oldestIndexVersionId)
);
}
Expand Down Expand Up @@ -2110,6 +2133,9 @@ public static ProjectMetadata fromXContent(XContentParser parser) throws IOExcep
projectBuilder.put(IndexTemplateMetadata.Builder.fromXContent(parser, parser.currentName()));
}
}
case "settings" -> {
projectBuilder.settings(Settings.fromXContent(parser));
}
default -> Metadata.Builder.parseCustomObject(
parser,
currentFieldName,
Expand Down Expand Up @@ -2155,6 +2181,11 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p) {
),
indices,
customs,
multiProject ? Iterators.single((builder, params) -> {
builder.startObject("settings");
settings.toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("flat_settings", "true")));
return builder.endObject();
}) : Collections.emptyIterator(),
multiProject
? ChunkedToXContentHelper.object("reserved_state", reservedStateMetadata().values().iterator())
: Collections.emptyIterator()
Expand Down Expand Up @@ -2189,6 +2220,10 @@ public static ProjectMetadata readFrom(StreamInput in) throws IOException {
builder.put(ReservedStateMetadata.readFrom(in));
}

if (in.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) {
builder.settings(Settings.readSettingsFromStream(in));
}

return builder.build();
}

Expand Down Expand Up @@ -2229,6 +2264,10 @@ public void writeTo(StreamOutput out) throws IOException {
}
VersionedNamedWriteable.writeVersionedWriteables(out, filteredCustoms);
out.writeCollection(reservedStateMetadata.values());

if (out.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) {
settings.writeTo(out);
}
}

// this needs to be package accessible for bwc serialization in Metadata.java
Expand All @@ -2248,13 +2287,15 @@ static class ProjectMetadataDiff implements Diff<ProjectMetadata> {
String,
ReservedStateMetadata,
ImmutableOpenMap<String, ReservedStateMetadata>> reservedStateMetadata;
private final Diff<Settings> settingsDiff;

private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) {
if (before == after) {
indices = DiffableUtils.emptyDiff();
templates = DiffableUtils.emptyDiff();
customs = DiffableUtils.emptyDiff();
reservedStateMetadata = DiffableUtils.emptyDiff();
settingsDiff = Settings.EMPTY_DIFF;
} else {
indices = DiffableUtils.diff(before.indices, after.indices, DiffableUtils.getStringKeySerializer());
templates = DiffableUtils.diff(before.templates, after.templates, DiffableUtils.getStringKeySerializer());
Expand All @@ -2269,19 +2310,22 @@ private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) {
after.reservedStateMetadata,
DiffableUtils.getStringKeySerializer()
);
settingsDiff = after.settings.diff(before.settings);
}
}

ProjectMetadataDiff(
DiffableUtils.MapDiff<String, IndexMetadata, ImmutableOpenMap<String, IndexMetadata>> indices,
DiffableUtils.MapDiff<String, IndexTemplateMetadata, ImmutableOpenMap<String, IndexTemplateMetadata>> templates,
DiffableUtils.MapDiff<String, Metadata.ProjectCustom, ImmutableOpenMap<String, Metadata.ProjectCustom>> customs,
DiffableUtils.MapDiff<String, ReservedStateMetadata, ImmutableOpenMap<String, ReservedStateMetadata>> reservedStateMetadata
DiffableUtils.MapDiff<String, ReservedStateMetadata, ImmutableOpenMap<String, ReservedStateMetadata>> reservedStateMetadata,
Diff<Settings> settingsDiff
) {
this.indices = indices;
this.templates = templates;
this.customs = customs;
this.reservedStateMetadata = reservedStateMetadata;
this.settingsDiff = settingsDiff;
}

ProjectMetadataDiff(StreamInput in) throws IOException {
Expand All @@ -2293,6 +2337,11 @@ private ProjectMetadataDiff(ProjectMetadata before, ProjectMetadata after) {
DiffableUtils.getStringKeySerializer(),
RESERVED_DIFF_VALUE_READER
);
if (in.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) {
settingsDiff = Settings.readSettingsDiffFromStream(in);
} else {
settingsDiff = Settings.EMPTY_DIFF;
}
}

Diff<ImmutableOpenMap<String, IndexMetadata>> indices() {
Expand All @@ -2317,11 +2366,18 @@ public void writeTo(StreamOutput out) throws IOException {
templates.writeTo(out);
customs.writeTo(out);
reservedStateMetadata.writeTo(out);
if (out.getTransportVersion().onOrAfter(TransportVersions.PROJECT_METADATA_SETTINGS)) {
settingsDiff.writeTo(out);
}
}

@Override
public ProjectMetadata apply(ProjectMetadata part) {
if (indices.isEmpty() && templates.isEmpty() && customs.isEmpty() && reservedStateMetadata.isEmpty()) {
if (indices.isEmpty()
&& templates.isEmpty()
&& customs.isEmpty()
&& reservedStateMetadata.isEmpty()
&& settingsDiff == Settings.EMPTY_DIFF) {
// nothing to do
return part;
}
Expand All @@ -2336,13 +2392,14 @@ public ProjectMetadata apply(ProjectMetadata part) {
&& builder.dataStreamMetadata() == part.custom(DataStreamMetadata.TYPE, DataStreamMetadata.EMPTY)) {
builder.previousIndicesLookup = part.indicesLookup;
}
builder.settings = settingsDiff.apply(part.settings);
return builder.build(true);
}

ProjectMetadataDiff withCustoms(
DiffableUtils.MapDiff<String, Metadata.ProjectCustom, ImmutableOpenMap<String, Metadata.ProjectCustom>> customs
) {
return new ProjectMetadataDiff(indices, templates, customs, reservedStateMetadata);
return new ProjectMetadataDiff(indices, templates, customs, reservedStateMetadata, settingsDiff);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.ProjectScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -31,6 +32,8 @@
import org.elasticsearch.tasks.TaskManager;
import org.elasticsearch.threadpool.ThreadPool;

import java.util.Collections;

public class ClusterService extends AbstractLifecycleComponent {
private final MasterService masterService;

Expand All @@ -52,12 +55,31 @@ public class ClusterService extends AbstractLifecycleComponent {

private final ClusterSettings clusterSettings;

private final ProjectScopedSettings projectScopedSettings;

private final String nodeName;

public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, TaskManager taskManager) {
this(
settings,
clusterSettings,
new ProjectScopedSettings(settings, Collections.emptySet()),
new MasterService(settings, clusterSettings, threadPool, taskManager),
new ClusterApplierService(Node.NODE_NAME_SETTING.get(settings), settings, clusterSettings, threadPool)
);
}

public ClusterService(
Settings settings,
ClusterSettings clusterSettings,
ProjectScopedSettings projectScopedSettings,
ThreadPool threadPool,
TaskManager taskManager
) {
this(
settings,
clusterSettings,
projectScopedSettings,
new MasterService(settings, clusterSettings, threadPool, taskManager),
new ClusterApplierService(Node.NODE_NAME_SETTING.get(settings), settings, clusterSettings, threadPool)
);
Expand All @@ -68,10 +90,21 @@ public ClusterService(
ClusterSettings clusterSettings,
MasterService masterService,
ClusterApplierService clusterApplierService
) {
this(settings, clusterSettings, new ProjectScopedSettings(settings, Collections.emptySet()), masterService, clusterApplierService);
}

public ClusterService(
Settings settings,
ClusterSettings clusterSettings,
ProjectScopedSettings projectScopedSettings,
MasterService masterService,
ClusterApplierService clusterApplierService
) {
this.settings = settings;
this.nodeName = Node.NODE_NAME_SETTING.get(settings);
this.masterService = masterService;
this.projectScopedSettings = projectScopedSettings;
this.operationRouting = new OperationRouting(settings, clusterSettings);
this.clusterSettings = clusterSettings;
this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
Expand Down Expand Up @@ -201,6 +234,10 @@ public ClusterSettings getClusterSettings() {
return clusterSettings;
}

public ProjectScopedSettings getProjectScopedSettings() {
return projectScopedSettings;
}

/**
* The node's settings.
*/
Expand Down
Loading