Skip to content

Commit bb32c7a

Browse files
authored
Fix geoip databases index access after system feature migration (take 3) (#124604) (#124680)
1 parent cec80e8 commit bb32c7a

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

docs/changelog/124604.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 124604
2+
summary: Fix geoip databases index access after system feature migration (take 3)
3+
area: Ingest Node
4+
type: bug
5+
issues: []

modules/ingest-geoip/qa/geoip-reindexed/src/javaRestTest/java/org/elasticsearch/ingest/geoip/GeoIpReindexedIT.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.client.Response;
1919
import org.elasticsearch.client.WarningsHandler;
2020
import org.elasticsearch.common.settings.Settings;
21+
import org.elasticsearch.common.util.CollectionUtils;
2122
import org.elasticsearch.common.util.concurrent.ThreadContext;
2223
import org.elasticsearch.core.Nullable;
2324
import org.elasticsearch.rest.RestStatus;
@@ -33,7 +34,6 @@
3334

3435
import java.io.IOException;
3536
import java.nio.charset.StandardCharsets;
36-
import java.util.ArrayList;
3737
import java.util.Base64;
3838
import java.util.HashSet;
3939
import java.util.List;
@@ -210,9 +210,8 @@ private void testCatIndices(List<String> indexNames, @Nullable List<String> addi
210210
String response = EntityUtils.toString(assertOK(client().performRequest(catIndices)).getEntity());
211211
List<String> indices = List.of(response.trim().split("\\s+"));
212212

213-
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
214-
indexNames = new ArrayList<>(indexNames); // recopy into a mutable list
215-
indexNames.addAll(additionalIndexNames);
213+
if (additionalIndexNames != null) {
214+
indexNames = CollectionUtils.concatLists(indexNames, additionalIndexNames);
216215
}
217216

218217
assertThat(new HashSet<>(indices), is(new HashSet<>(indexNames)));
@@ -238,9 +237,8 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
238237
);
239238
Response response = assertOK(client().performRequest(getStar));
240239

241-
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
242-
indexNames = new ArrayList<>(indexNames); // recopy into a mutable list
243-
indexNames.addAll(additionalIndexNames);
240+
if (additionalIndexNames != null) {
241+
indexNames = CollectionUtils.concatLists(indexNames, additionalIndexNames);
244242
}
245243

246244
Map<String, Object> map = responseAsMap(response);
@@ -256,23 +254,38 @@ private void testGetStarAsKibana(List<String> indexNames, @Nullable List<String>
256254
);
257255
Response response = assertOK(client().performRequest(getStar));
258256

259-
if (additionalIndexNames != null && additionalIndexNames.isEmpty() == false) {
260-
indexNames = new ArrayList<>(indexNames); // recopy into a mutable list
261-
indexNames.addAll(additionalIndexNames);
257+
if (additionalIndexNames != null) {
258+
indexNames = CollectionUtils.concatLists(indexNames, additionalIndexNames);
262259
}
263260

264261
Map<String, Object> map = responseAsMap(response);
265262
assertThat(map.keySet(), is(new HashSet<>(indexNames)));
266263
}
267264

268265
private void testGetDatastreams() throws IOException {
269-
Request getStar = new Request("GET", "_data_stream");
270-
getStar.setOptions(
271-
RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE) // we don't care about warnings, just errors
266+
final List<List<String>> wildcardOptions = List.of(
267+
List.of(), // the default for expand_wildcards (that is, the option is not specified)
268+
List.of("all"),
269+
List.of("none"),
270+
List.of("hidden"),
271+
List.of("open"),
272+
List.of("closed"),
273+
List.of("hidden", "open"),
274+
List.of("hidden", "closed"),
275+
List.of("open", "closed")
272276
);
273-
Response response = client().performRequest(getStar);
274-
assertOK(response);
275-
276-
// note: we don't actually care about the response, just that there was one and that it didn't error out on us
277+
for (List<String> expandWildcards : wildcardOptions) {
278+
final Request getStar = new Request(
279+
"GET",
280+
"_data_stream" + (expandWildcards.isEmpty() ? "" : ("?expand_wildcards=" + String.join(",", expandWildcards)))
281+
);
282+
getStar.setOptions(
283+
RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE) // we only care about errors
284+
);
285+
Response response = client().performRequest(getStar);
286+
assertOK(response);
287+
288+
// note: we don't actually care about the response, just that there was one and that it didn't error out on us
289+
}
277290
}
278291
}

server/src/main/java/org/elasticsearch/action/datastreams/DataStreamsActionUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.action.datastreams;
1111

1212
import org.elasticsearch.action.support.IndicesOptions;
13+
import org.elasticsearch.action.support.IndicesOptions.WildcardOptions;
1314
import org.elasticsearch.cluster.ClusterState;
1415
import org.elasticsearch.cluster.metadata.DataStream;
1516
import org.elasticsearch.cluster.metadata.IndexAbstraction;
@@ -40,9 +41,10 @@ public static List<String> getDataStreamNames(
4041
}
4142

4243
public static IndicesOptions updateIndicesOptions(IndicesOptions indicesOptions) {
44+
// if expandWildcardsOpen=false, then it will be overridden to true
4345
if (indicesOptions.expandWildcardsOpen() == false) {
4446
indicesOptions = IndicesOptions.builder(indicesOptions)
45-
.wildcardOptions(IndicesOptions.WildcardOptions.builder(indicesOptions.wildcardOptions()).matchOpen(true))
47+
.wildcardOptions(WildcardOptions.builder(indicesOptions.wildcardOptions()).matchOpen(true))
4648
.build();
4749
}
4850
return indicesOptions;

server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ public static boolean isIndexVisible(
156156
final boolean isHidden = indexAbstraction.isHidden();
157157
boolean isVisible = isHidden == false || indicesOptions.expandWildcardsHidden() || isVisibleDueToImplicitHidden(expression, index);
158158
if (indexAbstraction.getType() == IndexAbstraction.Type.ALIAS) {
159-
if (indexAbstraction.isSystem()) {
159+
// it's an alias, ignore expandWildcardsOpen and expandWildcardsClosed.
160+
// it's complicated to support those options with aliases pointing to multiple indices...
161+
isVisible = isVisible && indicesOptions.ignoreAliases() == false;
162+
163+
if (isVisible && indexAbstraction.isSystem()) {
160164
// check if it is net new
161165
if (resolver.getNetNewSystemIndexPredicate().test(indexAbstraction.getName())) {
162166
// don't give this code any particular credit for being *correct*. it's just trying to resolve a combination of
@@ -182,9 +186,6 @@ public static boolean isIndexVisible(
182186
}
183187
}
184188

185-
// it's an alias, ignore expandWildcardsOpen and expandWildcardsClosed.
186-
// complicated to support those options with aliases pointing to multiple indices...
187-
isVisible = isVisible && indicesOptions.ignoreAliases() == false;
188189
if (isVisible && selectorString != null) {
189190
// Check if a selector was present, and if it is, check if this alias is applicable to it
190191
IndexComponentSelector selector = IndexComponentSelector.getByKey(selectorString);

0 commit comments

Comments
 (0)