-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Reprocess operator file settings on service start #114295
Merged
elasticsearchmachine
merged 53 commits into
elastic:main
from
n1v0lg:reprocess-file-settings-on-start
Oct 21, 2024
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
0c193cd
Reprocess file settings on start
n1v0lg 1cc6175
Clean up and fixes
n1v0lg 4e243c4
Merge branch 'main' into reprocess-file-settings-on-start
n1v0lg 4fab8f6
Merge branch 'main' into reprocess-file-settings-on-start
elasticmachine 80036ee
Clean up
n1v0lg 7242520
IT
n1v0lg 2fd6eef
Smaller diff
n1v0lg 4319bb6
Nit
n1v0lg 574ba67
More clean up
n1v0lg fd4d20c
Missed a file
n1v0lg 75a255d
More clean and tests
n1v0lg 55f5399
WIP better conditions
n1v0lg d790a5e
Test fixes
n1v0lg 5f41735
More unit tests
n1v0lg 28938d5
WIP error handling
n1v0lg d6d9c43
Fix concurrency in tests
n1v0lg fa65684
More
n1v0lg 77421c7
New error
n1v0lg 16db4ed
Merge branch 'main' into reprocess-file-settings-on-start
elasticmachine 1fae6be
Version fix
n1v0lg 8d3539b
Merge branch 'reprocess-file-settings-on-start' of github.com:n1v0lg/…
n1v0lg 7a02f9b
Update docs/changelog/114295.yaml
n1v0lg ff796cf
Changelog
n1v0lg e478134
Merge branch 'main' into reprocess-file-settings-on-start
n1v0lg 74ab91a
Merge branch 'main' into reprocess-file-settings-on-start
n1v0lg 9a44ebf
Upgrade test
n1v0lg 89b0957
Spacing
n1v0lg dda0723
WIP review feedback
n1v0lg 8dc3709
Fix test
n1v0lg 496ab5c
Merge branch 'main' into reprocess-file-settings-on-start
n1v0lg ae00eaa
Fold reprocessSameVersion into version metadata
n1v0lg 99e2b0e
Refactor
n1v0lg b7608cb
Parens
n1v0lg 6ba1336
Merge branch 'main' into reprocess-file-settings-on-start
n1v0lg 035e8c0
Fix compilation
n1v0lg 7e2720d
Error version checks
n1v0lg 051f3c6
Tweak
n1v0lg 7af83cb
More clean up
n1v0lg e1a1de2
More
n1v0lg c0540bf
Inject version check
n1v0lg cf8002a
Smaller diff
n1v0lg a5d1bc8
More
n1v0lg d20b1d3
Rename
n1v0lg 1409c89
Merge branch 'main' into reprocess-file-settings-on-start
n1v0lg fbf0691
Fix
n1v0lg afef613
Javadoc clean up
n1v0lg cb84cfb
Naming is hard
n1v0lg 997ac7a
Log message
n1v0lg a09b505
Match description with actual thing
n1v0lg 8548c93
Still more fixes
n1v0lg 4205feb
Urgh imports
n1v0lg 65d05b4
Fix test
n1v0lg dbbf948
Merge branch 'main' into reprocess-file-settings-on-start
n1v0lg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 114295 | ||
summary: "Reprocess operator file settings when settings service starts, due to node restart or master node change" | ||
area: Infra/Settings | ||
type: enhancement | ||
issues: [ ] |
111 changes: 111 additions & 0 deletions
111
...de/src/javaRestTest/java/org/elasticsearch/upgrades/FileSettingsRoleMappingUpgradeIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.upgrades; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.Name; | ||
|
||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.core.SuppressForbidden; | ||
import org.elasticsearch.test.XContentTestUtils; | ||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
import org.elasticsearch.test.cluster.local.distribution.DistributionType; | ||
import org.elasticsearch.test.cluster.util.resource.Resource; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.rules.RuleChain; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.junit.rules.TestRule; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
public class FileSettingsRoleMappingUpgradeIT extends ParameterizedRollingUpgradeTestCase { | ||
|
||
private static final String settingsJSON = """ | ||
{ | ||
"metadata": { | ||
"version": "1", | ||
"compatibility": "8.4.0" | ||
}, | ||
"state": { | ||
"role_mappings": { | ||
"everyone_kibana": { | ||
"enabled": true, | ||
"roles": [ "kibana_user" ], | ||
"rules": { "field": { "username": "*" } } | ||
} | ||
} | ||
} | ||
}"""; | ||
|
||
private static final TemporaryFolder repoDirectory = new TemporaryFolder(); | ||
|
||
private static final ElasticsearchCluster cluster = ElasticsearchCluster.local() | ||
.distribution(DistributionType.DEFAULT) | ||
.version(getOldClusterTestVersion()) | ||
.nodes(NODE_NUM) | ||
.setting("path.repo", new Supplier<>() { | ||
@Override | ||
@SuppressForbidden(reason = "TemporaryFolder only has io.File methods, not nio.File") | ||
public String get() { | ||
return repoDirectory.getRoot().getPath(); | ||
} | ||
}) | ||
.setting("xpack.security.enabled", "true") | ||
// workaround to avoid having to set up clients and authorization headers | ||
.setting("xpack.security.authc.anonymous.roles", "superuser") | ||
.configFile("operator/settings.json", Resource.fromString(settingsJSON)) | ||
.build(); | ||
|
||
@ClassRule | ||
public static TestRule ruleChain = RuleChain.outerRule(repoDirectory).around(cluster); | ||
|
||
public FileSettingsRoleMappingUpgradeIT(@Name("upgradedNodes") int upgradedNodes) { | ||
super(upgradedNodes); | ||
} | ||
|
||
@Override | ||
protected ElasticsearchCluster getUpgradeCluster() { | ||
return cluster; | ||
} | ||
|
||
@Before | ||
public void checkVersions() { | ||
assumeTrue( | ||
"Only relevant when upgrading from a version before role mappings were stored in cluster state", | ||
oldClusterHasFeature("gte_v8.4.0") && oldClusterHasFeature("gte_v8.15.0") == false | ||
); | ||
} | ||
|
||
public void testRoleMappingsAppliedOnUpgrade() throws IOException { | ||
if (isOldCluster()) { | ||
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata"); | ||
List<Object> roleMappings = new XContentTestUtils.JsonMapView(entityAsMap(client().performRequest(clusterStateRequest))).get( | ||
"metadata.role_mappings.role_mappings" | ||
); | ||
assertThat(roleMappings, is(nullValue())); | ||
} else if (isUpgradedCluster()) { | ||
// the nodes have all been upgraded. Check they re-processed the role mappings in the settings file on | ||
// upgrade | ||
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata"); | ||
List<Object> roleMappings = new XContentTestUtils.JsonMapView(entityAsMap(client().performRequest(clusterStateRequest))).get( | ||
"metadata.role_mappings.role_mappings" | ||
); | ||
assertThat(roleMappings, is(not(nullValue()))); | ||
assertThat(roleMappings.size(), equalTo(1)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 won't actually run on 9.0, only once these changes are backported to 8.x -- I have a PR open to give this some CI time (also checked that it passes locally).