Skip to content

Commit f018381

Browse files
authored
Fix geoip databases index access after system feature migration (take 3) (#124604) (#124681)
1 parent 87bd618 commit f018381

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;
@@ -34,7 +35,6 @@
3435

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

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

220219
assertThat(new HashSet<>(indices), is(new HashSet<>(indexNames)));
@@ -240,9 +239,8 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
240239
);
241240
Response response = assertOK(client().performRequest(getStar));
242241

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

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

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

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

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

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)