use of org.graylog.plugins.views.search.errors.SearchException in project graylog2-server by Graylog2.
the class QueryValidationServiceImpl method toExplanation.
private List<ValidationMessage> toExplanation(String query, SearchException searchException) {
if (searchException.error() instanceof UnboundParameterError) {
final UnboundParameterError error = (UnboundParameterError) searchException.error();
final List<SubstringMultilinePosition> positions = SubstringMultilinePosition.compute(query, "$" + error.parameterName() + "$");
if (!positions.isEmpty()) {
return positions.stream().map(p -> ValidationMessage.builder().errorType("Parameter error").errorMessage(error.description()).beginLine(p.getLine()).endLine(p.getLine()).beginColumn(p.getBeginColumn()).endColumn(p.getEndColumn()).build()).collect(Collectors.toList());
}
}
return Collections.singletonList(ValidationMessage.fromException(searchException));
}
use of org.graylog.plugins.views.search.errors.SearchException 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.SearchException in project graylog2-server by Graylog2.
the class AggregationEventProcessor method createEvents.
@Override
public void createEvents(EventFactory eventFactory, EventProcessorParameters processorParameters, EventConsumer<List<EventWithContext>> eventsConsumer) throws EventProcessorException {
final AggregationEventProcessorParameters parameters = (AggregationEventProcessorParameters) processorParameters;
// TODO: We have to take the Elasticsearch index.refresh_interval into account here!
if (!dependencyCheck.hasMessagesIndexedUpTo(parameters.timerange().getTo())) {
final String msg = String.format(Locale.ROOT, "Couldn't run aggregation <%s/%s> for timerange <%s to %s> because required messages haven't been indexed, yet.", eventDefinition.title(), eventDefinition.id(), parameters.timerange().getFrom(), parameters.timerange().getTo());
throw new EventProcessorPreconditionException(msg, eventDefinition);
}
LOG.debug("Creating events for config={} parameters={}", config, parameters);
// a simple search query. (one message -> one event)
try {
if (config.series().isEmpty()) {
filterSearch(eventFactory, parameters, eventsConsumer);
} else {
aggregatedSearch(eventFactory, parameters, eventsConsumer);
}
} catch (SearchException e) {
if (e.error() instanceof ParameterExpansionError) {
final String msg = String.format(Locale.ROOT, "Couldn't run aggregation <%s/%s> because parameters failed to expand: %s", eventDefinition.title(), eventDefinition.id(), e.error().description());
LOG.error(msg);
throw new EventProcessorPreconditionException(msg, eventDefinition, e);
}
}
// Update the state for this processor! This state will be used for dependency checks between event processors.
stateService.setState(eventDefinition.id(), parameters.timerange().getFrom(), parameters.timerange().getTo());
}
use of org.graylog.plugins.views.search.errors.SearchException in project graylog2-server by Graylog2.
the class MoreSearch method scrollQuery.
/**
* This scrolls results for the given query, streams and time range from Elasticsearch. The result is passed to
* the given callback in batches. (using the given batch size)
* <p>
* The search will continue until it is done, an error occurs or the search is stopped by setting the
* {@code continueScrolling} boolean to {@code false} from the {@link ScrollCallback}.
* <p></p>
* TODO: Elasticsearch has a default limit of 500 concurrent scrolls. Every caller of this method should check
* if there is capacity to create a new scroll request. This can be done by using the ES nodes stats API.
* See: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#scroll-search-context
*
* @param queryString the search query string
* @param streams the set of streams to search in
* @param timeRange the time range for the search
* @param batchSize the number of documents to retrieve at once
* @param resultCallback the callback that gets executed for each batch
*/
public void scrollQuery(String queryString, Set<String> streams, Set<Parameter> queryParameters, TimeRange timeRange, int batchSize, ScrollCallback resultCallback) throws EventProcessorException {
// TODO: Does scroll time need to be configurable?
final String scrollTime = "1m";
final Set<String> affectedIndices = getAffectedIndices(streams, timeRange);
try {
queryString = decorateQuery(queryParameters, timeRange, queryString);
} catch (SearchException e) {
if (e.error() instanceof EmptyParameterError) {
LOG.debug("Empty parameter from lookup table. Assuming non-matching query. Error: {}", e.getMessage());
return;
}
throw e;
}
moreSearchAdapter.scrollEvents(queryString, timeRange, affectedIndices, streams, scrollTime, batchSize, resultCallback::call);
}
Aggregations