use of org.graylog.plugins.views.search.errors.QueryError in project graylog2-server by Graylog2.
the class QueryBackend method run.
// TODO we can probably push job and query into the GeneratedQueryContext to simplify the signature
default QueryResult run(SearchJob job, Query query, GeneratedQueryContext generatedQueryContext) {
try {
final Stopwatch stopwatch = Stopwatch.createStarted();
final QueryExecutionStats.Builder statsBuilder = QueryExecutionStats.builderWithCurrentTime();
// https://www.ibm.com/developerworks/java/library/j-jtp04298/index.html#3.0
// noinspection unchecked
final QueryResult result = doRun(job, query, (T) generatedQueryContext);
stopwatch.stop();
return result.toBuilder().executionStats(statsBuilder.duration(stopwatch.elapsed(TimeUnit.MILLISECONDS)).effectiveTimeRange(effectiveTimeRangeForResult(query, result)).build()).build();
} catch (Exception e) {
// the backend has very likely created a more specific error and added it to the context, but we fall
// back to a generic error so we never throw exceptions into the engine.
final QueryError queryError = new QueryError(query, e);
generatedQueryContext.addError(queryError);
return QueryResult.failedQueryWithError(query, queryError);
}
}
use of org.graylog.plugins.views.search.errors.QueryError in project graylog2-server by Graylog2.
the class QueryEngine method execute.
public SearchJob execute(SearchJob searchJob) {
searchJob.getSearch().queries().forEach(query -> searchJob.addQueryResultFuture(query.id(), // if need be we default to an empty result with a failed state and the wrapped exception
CompletableFuture.supplyAsync(() -> prepareAndRun(searchJob, query), queryPool).handle((queryResult, throwable) -> {
if (throwable != null) {
final Throwable cause = throwable.getCause();
final SearchError error;
if (cause instanceof SearchException) {
error = ((SearchException) cause).error();
} else {
error = new QueryError(query, cause);
}
LOG.debug("Running query {} failed: {}", query.id(), cause);
searchJob.addError(error);
return QueryResult.failedQueryWithError(query, error);
}
return queryResult;
})));
searchJob.getSearch().queries().forEach(query -> {
final CompletableFuture<QueryResult> queryResultFuture = searchJob.getQueryResultFuture(query.id());
if (!queryResultFuture.isDone()) {
// this is not going to throw an exception, because we will always replace it with a placeholder "FAILED" result above
final QueryResult result = queryResultFuture.join();
} else {
LOG.debug("[{}] Not generating query for query {}", defaultIfEmpty(query.id(), "root"), query);
}
});
LOG.debug("Search job {} executing", searchJob.getId());
return searchJob.seal();
}
use of org.graylog.plugins.views.search.errors.QueryError in project graylog2-server by Graylog2.
the class PivotAggregationSearch method doSearch.
@Override
public AggregationResult doSearch() throws EventProcessorException {
final SearchJob searchJob = getSearchJob(parameters, searchOwner, config.searchWithinMs(), config.executeEveryMs());
final QueryResult queryResult = searchJob.results().get(QUERY_ID);
final QueryResult streamQueryResult = searchJob.results().get(STREAMS_QUERY_ID);
final Set<SearchError> aggregationErrors = firstNonNull(queryResult.errors(), Collections.emptySet());
final Set<SearchError> streamErrors = firstNonNull(streamQueryResult.errors(), Collections.emptySet());
if (!aggregationErrors.isEmpty() || !streamErrors.isEmpty()) {
final Set<SearchError> errors = aggregationErrors.isEmpty() ? streamErrors : aggregationErrors;
errors.forEach(error -> {
if (error instanceof QueryError) {
final QueryError queryError = (QueryError) error;
final String backtrace = queryError.backtrace() != null ? queryError.backtrace() : "";
if (error instanceof EmptyParameterError) {
LOG.debug("Aggregation search query <{}> with empty Parameter: {}\n{}", queryError.queryId(), queryError.description(), backtrace);
} else {
LOG.error("Aggregation search query <{}> returned an error: {}\n{}", queryError.queryId(), queryError.description(), backtrace);
}
} else {
LOG.error("Aggregation search returned an error: {}", error);
}
});
// If we have only EmptyParameterErrors, just return an empty Result
if (!(errors.stream().filter(e -> !(e instanceof EmptyParameterError)).count() > 1)) {
return AggregationResult.empty();
}
if (errors.size() > 1) {
throw new EventProcessorException("Pivot search failed with multiple errors.", false, eventDefinition);
} else {
throw new EventProcessorException(errors.iterator().next().description(), false, eventDefinition);
}
}
final PivotResult pivotResult = (PivotResult) queryResult.searchTypes().get(PIVOT_ID);
final PivotResult streamsResult = (PivotResult) streamQueryResult.searchTypes().get(STREAMS_PIVOT_ID);
return AggregationResult.builder().keyResults(extractValues(pivotResult)).effectiveTimerange(pivotResult.effectiveTimerange()).totalAggregatedMessages(pivotResult.total()).sourceStreams(extractSourceStreams(streamsResult)).build();
}
Aggregations