Skip to content

Commit

Permalink
Improve the error messages for _stats with closed indices
Browse files Browse the repository at this point in the history
Signed-off-by: srikanth padakanti <srikanth29.9@gmail.com>
  • Loading branch information
srikanthpadakanti committed Apr 17, 2024
1 parent 84679de commit 2462bdd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Enabled mockTelemetryPlugin for IT and fixed OOM issues ([#13054](https://github.com/opensearch-project/OpenSearch/pull/13054))
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))
- Fix snapshot _status API to return correct status for partial snapshots ([#12812](https://github.com/opensearch-project/OpenSearch/pull/12812))
- Improve error messages for _stats with closed indices ([#13012](https://github.com/opensearch-project/OpenSearch/pull/13012))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,13 @@ private void checkSystemIndexAccess(Context context, Metadata metadata, Set<Inde
private static boolean shouldTrackConcreteIndex(Context context, IndicesOptions options, IndexMetadata index) {
if (index.getState() == IndexMetadata.State.CLOSE) {
if (options.forbidClosedIndices() && options.ignoreUnavailable() == false) {
throw new IndexClosedException(index.getIndex());
if (options.expandWildcardsClosed() == true) {
throw new IllegalArgumentException(
"To expand [" + index.getState() + "] wildcard, please set forbid_closed_indices to `false`"
);
} else {
throw new IndexClosedException(index.getIndex());
}
} else {
return options.forbidClosedIndices() == false && addIndex(index, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,25 @@ public void testIndexOptionsWildcardExpansion() {
assertEquals(1, results.length);
assertThat(results, arrayContainingInAnyOrder(".hidden-closed"));

options = IndicesOptions.fromOptions(false, true, false, true, false, false, false, false);
context = new IndexNameExpressionResolver.Context(state, options, false);

results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);

try {
options = IndicesOptions.fromOptions(false, true, false, true, false, true, false, false);
context = new IndexNameExpressionResolver.Context(state, options, false);

results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
assertEquals(1, results.length);
assertEquals("foo", results[0]);
} catch (IllegalArgumentException iae) {
String expectedMessage = "To expand [CLOSE] wildcard, please set forbid_closed_indices to `false`";
assertEquals(expectedMessage, iae.getMessage());
}

// Only open
options = IndicesOptions.fromOptions(false, true, true, false, false);
context = new IndexNameExpressionResolver.Context(state, options, false);
Expand Down

0 comments on commit 2462bdd

Please sign in to comment.