Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.calcite.rel.metadata.RelMetadataQueryBase;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.ExceptionsHelper;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.action.support.TimeoutTaskCancellationUtility;
Expand Down Expand Up @@ -50,6 +51,7 @@
import org.opensearch.common.inject.Inject;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.tasks.TaskId;
import org.opensearch.search.SearchService;
import org.opensearch.tasks.Task;
Expand Down Expand Up @@ -409,7 +411,21 @@ protected void doExecute(Task task, AnalyticsQueryRequest request, ActionListene
// immediately. The listener is wrapped to convert backend-specific exceptions.
ActionListener<AnalyticsQueryResponse> convertingListener = ActionListener.wrap(listener::onResponse, e -> {
Exception converted = e instanceof Exception ex ? contextProvider.convertException(ex) : new RuntimeException(e);
listener.onFailure(converted);
// If convertException returned unrecognized 500 — redact internal details and log the original.
if (converted == e && isInternalError(converted)) {
AnalyticsQueryTask queryTask = (AnalyticsQueryTask) task;
String queryId = queryTask.getQueryId();
String identifier = "unassigned".equals(queryId)
? "task_id=" + task.getId()
: "task_id=" + task.getId() + ", query_id=" + queryId;
logger.error(
new org.apache.logging.log4j.message.ParameterizedMessage("[analytics-engine] internal error [{}]", identifier),
converted
);
listener.onFailure(new RuntimeException("Internal error [" + identifier + "]"));
} else {
listener.onFailure(converted);
}
});
ContextAwareExecutor.wrap(searchExecutor, threadPool).execute(() -> {
try {
Expand Down Expand Up @@ -443,6 +459,13 @@ protected void doExecute(Task task, AnalyticsQueryRequest request, ActionListene
});
}

/**
* Returns true if the exception would produce a 500 response and should be redacted.
*/
private static boolean isInternalError(Exception e) {
return ExceptionsHelper.status(e) == RestStatus.INTERNAL_SERVER_ERROR;
}

/**
* Materializes Arrow batches into row-oriented {@code Object[]}s for the
* external query API. The scheduler yields batches (the native wire format);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static IndexResolution resolveAlias(String aliasName, List<IndexMetadata
for (IndexMetadata index : open) {
AliasMetadata aliasMd = index.getAliases().get(aliasName);
if (aliasMd != null && aliasMd.filteringRequired()) {
throw new IllegalStateException(
throw new IllegalArgumentException(
"Alias ["
+ aliasName
+ "] declares a filter on index ["
Expand Down Expand Up @@ -252,7 +252,7 @@ record Decl(String type, String sourceIndex) {
OpenSearchSchemaBuilder.mapFieldType(previous.type),
OpenSearchSchemaBuilder.mapFieldType(type)
)) {
throw new IllegalStateException(
throw new IllegalArgumentException(
"Alias ["
+ aliasName
+ "] resolves to indices with incompatible field types: ["
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testAliasRejectsWhenFieldTypesDiffer() {
IndexMetadata.Builder b = indexBuilder("bank_b", keywordField("age")).putAlias(AliasMetadata.builder("bank_all").build());
ClusterState state = clusterStateOf(a, b);

IllegalStateException ex = expectThrows(IllegalStateException.class, () -> IndexResolution.resolve("bank_all", state));
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> IndexResolution.resolve("bank_all", state));
assertTrue("error must mention the conflicting field: " + ex.getMessage(), ex.getMessage().contains("age"));
assertTrue(
"error must mention both indices: " + ex.getMessage(),
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testAliasRejectsFilterAlias() {
IndexMetadata.Builder a = indexBuilder("bank_a", longField("age")).putAlias(filterAlias);
ClusterState state = clusterStateOf(a);

IllegalStateException ex = expectThrows(IllegalStateException.class, () -> IndexResolution.resolve("active_only", state));
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> IndexResolution.resolve("active_only", state));
assertTrue("error must mention the alias name: " + ex.getMessage(), ex.getMessage().contains("active_only"));
assertTrue("error must mention 'filter': " + ex.getMessage(), ex.getMessage().toLowerCase(Locale.ROOT).contains("filter"));
}
Expand Down Expand Up @@ -142,7 +142,7 @@ public void testCommaSeparatedExpressionResolvesToUnion() {
public void testWildcardRejectsIncompatibleSchemasAcrossMatches() {
ClusterState state = clusterStateOf(indexBuilder("test", longField("age")), indexBuilder("test1", keywordField("age")));

IllegalStateException ex = expectThrows(IllegalStateException.class, () -> IndexResolution.resolve("test*", state, RESOLVER));
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> IndexResolution.resolve("test*", state, RESOLVER));
assertTrue("error must mention the conflicting field: " + ex.getMessage(), ex.getMessage().contains("age"));
}

Expand Down Expand Up @@ -268,7 +268,7 @@ public void testDataStreamRejectsConflictingBackingMappings() {
)
.build();

IllegalStateException ex = expectThrows(IllegalStateException.class, () -> IndexResolution.resolve("logs", state, RESOLVER));
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> IndexResolution.resolve("logs", state, RESOLVER));
assertTrue("error must mention the conflicting field: " + ex.getMessage(), ex.getMessage().contains("age"));
}

Expand Down
Loading