-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply settings filter to get cluster settings API (#33247)
Some settings have filters applied to them and we use this in logs and the get nodes info API. For consistency, we should apply this in the get cluster settings API too.
- Loading branch information
1 parent
4afbc30
commit cfe3d9f
Showing
2 changed files
with
140 additions
and
13 deletions.
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
74 changes: 74 additions & 0 deletions
74
...t/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsActionTests.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,74 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.rest.action.admin.cluster; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.settings.SettingsFilter; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class RestClusterGetSettingsActionTests extends ESTestCase { | ||
|
||
public void testFilterPersistentSettings() { | ||
runTestFilterSettingsTest( | ||
MetaData.Builder::persistentSettings, | ||
RestClusterGetSettingsAction.ClusterGetSettingsResponse::persistentSettings); | ||
} | ||
|
||
public void testFilterTransientSettings() { | ||
runTestFilterSettingsTest( | ||
MetaData.Builder::transientSettings, | ||
RestClusterGetSettingsAction.ClusterGetSettingsResponse::transientSettings); | ||
} | ||
|
||
private void runTestFilterSettingsTest( | ||
final BiConsumer<MetaData.Builder, Settings> md, | ||
final Function<RestClusterGetSettingsAction.ClusterGetSettingsResponse, Settings> s) { | ||
final MetaData.Builder mdBuilder = new MetaData.Builder(); | ||
final Settings settings = Settings.builder().put("foo.filtered", "bar").put("foo.non_filtered", "baz").build(); | ||
md.accept(mdBuilder, settings); | ||
final ClusterState.Builder builder = new ClusterState.Builder(ClusterState.EMPTY_STATE).metaData(mdBuilder); | ||
final SettingsFilter filter = new SettingsFilter(Settings.EMPTY, Collections.singleton("foo.filtered")); | ||
final Setting.Property[] properties = {Setting.Property.Dynamic, Setting.Property.Filtered, Setting.Property.NodeScope}; | ||
final Set<Setting<?>> settingsSet = Stream.concat( | ||
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), | ||
Stream.concat( | ||
Stream.of(Setting.simpleString("foo.filtered", properties)), | ||
Stream.of(Setting.simpleString("foo.non_filtered", properties)))) | ||
.collect(Collectors.toSet()); | ||
final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet); | ||
final RestClusterGetSettingsAction.ClusterGetSettingsResponse response = | ||
new RestClusterGetSettingsAction.ClusterGetSettingsResponse( | ||
builder.build(), randomBoolean(), filter, clusterSettings, Settings.EMPTY); | ||
assertFalse(s.apply(response).hasValue("foo.filtered")); | ||
assertTrue(s.apply(response).hasValue("foo.non_filtered")); | ||
} | ||
|
||
} |