From bf2a80f498890518bb5f7623b24aebdd970ae7d4 Mon Sep 17 00:00:00 2001 From: Amit Galitzky Date: Thu, 14 Nov 2024 08:40:24 -0800 Subject: [PATCH] don't fail on unknown exception Signed-off-by: Amit Galitzky --- .../rest/handler/AbstractTimeSeriesActionHandler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opensearch/timeseries/rest/handler/AbstractTimeSeriesActionHandler.java b/src/main/java/org/opensearch/timeseries/rest/handler/AbstractTimeSeriesActionHandler.java index eca71c555..60c32680c 100644 --- a/src/main/java/org/opensearch/timeseries/rest/handler/AbstractTimeSeriesActionHandler.java +++ b/src/main/java/org/opensearch/timeseries/rest/handler/AbstractTimeSeriesActionHandler.java @@ -890,6 +890,7 @@ protected void validateConfigFeatures(String id, boolean indexingDryRun, ActionL feature.getId() ); ssb.aggregation(internalAgg.getAggregatorFactories().iterator().next()); + ssb.trackTotalHits(false); SearchRequest searchRequest = new SearchRequest().indices(config.getIndices().toArray(new String[0])).source(ssb); ActionListener searchResponseListener = ActionListener.wrap(response -> { Optional aggFeatureResult = searchFeatureDao.parseResponse(response, Arrays.asList(feature.getId()), false); @@ -907,11 +908,17 @@ protected void validateConfigFeatures(String id, boolean indexingDryRun, ActionL String errorMessage; if (isExceptionCausedByInvalidQuery(e)) { errorMessage = CommonMessages.FEATURE_WITH_INVALID_QUERY_MSG + feature.getName(); + logger.error(errorMessage, e); + multiFeatureQueriesResponseListener.onFailure(new OpenSearchStatusException(errorMessage, RestStatus.BAD_REQUEST, e)); } else { errorMessage = CommonMessages.UNKNOWN_SEARCH_QUERY_EXCEPTION_MSG + feature.getName(); + logger.error(errorMessage, e); + // If we see an unexpected error such as timeout or some task cancellation cause of search backpressure + // we don't want to block detector creation as this is unlikely an error due to wrong configs + // but we want to record what error was seen + multiFeatureQueriesResponseListener + .onResponse(new MergeableList<>(new ArrayList<>(List.of(Optional.of(new double[] { 1.0 }))))); } - logger.error(errorMessage, e); - multiFeatureQueriesResponseListener.onFailure(new OpenSearchStatusException(errorMessage, RestStatus.BAD_REQUEST, e)); }); clientUtil.asyncRequestWithInjectedSecurity(searchRequest, client::search, user, client, context, searchResponseListener); }