Search in sources :

Example 1 with IndexLookup

use of org.graylog.plugins.views.search.elasticsearch.IndexLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendErrorHandlingTest method setUp.

@Before
public void setUp() throws Exception {
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(ImmutableMap.of("dummy", () -> mock(DummyHandler.class)), jestClient, indexLookup, new QueryStringDecorators(Collections.emptySet()), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false, objectMapper);
    when(indexLookup.indexNamesForStreamsInTimeRange(any(), any())).thenReturn(Collections.emptySet());
    final SearchType searchType1 = mock(SearchType.class);
    when(searchType1.id()).thenReturn("deadbeef");
    when(searchType1.type()).thenReturn("dummy");
    final SearchType searchType2 = mock(SearchType.class);
    when(searchType2.id()).thenReturn("cafeaffe");
    when(searchType2.type()).thenReturn("dummy");
    final Set<SearchType> searchTypes = ImmutableSet.of(searchType1, searchType2);
    this.query = Query.builder().id("query1").timerange(RelativeRange.create(300)).query(ElasticsearchQueryString.of("*")).searchTypes(searchTypes).build();
    final Search search = Search.builder().id("search1").queries(ImmutableSet.of(query)).build();
    this.searchJob = new SearchJob("job1", search, "admin");
    this.queryContext = new ESGeneratedQueryContext(this.backend, new SearchSourceBuilder(), searchJob, query, mock(FieldTypesLookup.class));
    searchTypes.forEach(queryContext::searchSourceBuilder);
    when(jestClient.execute(any())).thenReturn(result);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch6.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Query(org.graylog.plugins.views.search.Query) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiSearchResult(io.searchbox.core.MultiSearchResult) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) JestClient(io.searchbox.client.JestClient) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) SearchType(org.graylog.plugins.views.search.SearchType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) MockitoJUnit(org.mockito.junit.MockitoJUnit) JsonNode(com.fasterxml.jackson.databind.JsonNode) Search(org.graylog.plugins.views.search.Search) QueryResult(org.graylog.plugins.views.search.QueryResult) Before(org.junit.Before) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) SearchError(org.graylog.plugins.views.search.errors.SearchError) MockitoRule(org.mockito.junit.MockitoRule) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Mockito.mock(org.mockito.Mockito.mock) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Search(org.graylog.plugins.views.search.Search) SearchJob(org.graylog.plugins.views.search.SearchJob) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) SearchType(org.graylog.plugins.views.search.SearchType) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Before(org.junit.Before)

Example 2 with IndexLookup

use of org.graylog.plugins.views.search.elasticsearch.IndexLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendGeneratedRequestTestBase method setUpSUT.

@Before
public void setUpSUT() {
    this.elasticSearchTypeHandlers = new HashMap<>();
    final Map<String, ESPivotBucketSpecHandler<? extends BucketSpec, ? extends Aggregation>> bucketHandlers = Collections.emptyMap();
    final Map<String, ESPivotSeriesSpecHandler<? extends SeriesSpec, ? extends Aggregation>> seriesHandlers = new HashMap<>();
    seriesHandlers.put(Average.NAME, new ESAverageHandler());
    seriesHandlers.put(Max.NAME, new ESMaxHandler());
    elasticSearchTypeHandlers.put(Pivot.NAME, () -> new ESPivot(bucketHandlers, seriesHandlers));
    this.elasticsearchBackend = new ElasticsearchBackend(elasticSearchTypeHandlers, jestClient, indexLookup, new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false, objectMapper);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch6.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Provider(javax.inject.Provider) Query(org.graylog.plugins.views.search.Query) Mock(org.mockito.Mock) JestHttpClient(io.searchbox.client.http.JestHttpClient) ESMaxHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.series.ESMaxHandler) HashMap(java.util.HashMap) Captor(org.mockito.Captor) Max(org.graylog.plugins.views.search.searchtypes.pivot.series.Max) ArgumentCaptor(org.mockito.ArgumentCaptor) SearchType(org.graylog.plugins.views.search.SearchType) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) Map(java.util.Map) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) MockitoJUnit(org.mockito.junit.MockitoJUnit) Search(org.graylog.plugins.views.search.Search) QueryResult(org.graylog.plugins.views.search.QueryResult) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) ESPivot(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot) Before(org.junit.Before) MultiSearch(io.searchbox.core.MultiSearch) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) ESPivotSeriesSpecHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivotSeriesSpecHandler) ESPivotBucketSpecHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivotBucketSpecHandler) Set(java.util.Set) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Aggregation(io.searchbox.core.search.aggregation.Aggregation) Mockito.verify(org.mockito.Mockito.verify) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) ESAverageHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.series.ESAverageHandler) MockitoRule(org.mockito.junit.MockitoRule) Average(org.graylog.plugins.views.search.searchtypes.pivot.series.Average) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) ESPivotSeriesSpecHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivotSeriesSpecHandler) HashMap(java.util.HashMap) ESMaxHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.series.ESMaxHandler) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) Aggregation(io.searchbox.core.search.aggregation.Aggregation) ESAverageHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.series.ESAverageHandler) ESPivotBucketSpecHandler(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivotBucketSpecHandler) ESPivot(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot) Before(org.junit.Before)

Example 3 with IndexLookup

use of org.graylog.plugins.views.search.elasticsearch.IndexLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendUsingCorrectIndicesTest method setupSUT.

@Before
public void setupSUT() throws Exception {
    when(jestClient.execute(any(), any())).thenReturn(resultFor(resourceFile("successfulResponseWithSingleQuery.json")));
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(handlers, jestClient, indexLookup, new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false, objectMapper);
}
Also used : ESMessageList(org.graylog.storage.elasticsearch6.views.searchtypes.ESMessageList) ESSearchTypeHandler(org.graylog.storage.elasticsearch6.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AndFilter(org.graylog.plugins.views.search.filter.AndFilter) Provider(javax.inject.Provider) Query(org.graylog.plugins.views.search.Query) DateTimeUtils(org.joda.time.DateTimeUtils) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JestHttpClient(io.searchbox.client.http.JestHttpClient) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) Captor(org.mockito.Captor) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) ArgumentCaptor(org.mockito.ArgumentCaptor) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) SearchType(org.graylog.plugins.views.search.SearchType) After(org.junit.After) Map(java.util.Map) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) MockitoJUnit(org.mockito.junit.MockitoJUnit) Search(org.graylog.plugins.views.search.Search) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Before(org.junit.Before) Period(org.joda.time.Period) MultiSearch(io.searchbox.core.MultiSearch) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) MockitoRule(org.mockito.junit.MockitoRule) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Mockito.mock(org.mockito.Mockito.mock) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Before(org.junit.Before)

Example 4 with IndexLookup

use of org.graylog.plugins.views.search.elasticsearch.IndexLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendGeneratedRequestTestBase method setUpSUT.

@Before
public void setUpSUT() {
    this.elasticSearchTypeHandlers = new HashMap<>();
    final Map<String, ESPivotBucketSpecHandler<? extends BucketSpec, ? extends Aggregation>> bucketHandlers = Collections.emptyMap();
    final Map<String, ESPivotSeriesSpecHandler<? extends SeriesSpec, ? extends Aggregation>> seriesHandlers = new HashMap<>();
    seriesHandlers.put(Average.NAME, new ESAverageHandler());
    seriesHandlers.put(Max.NAME, new ESMaxHandler());
    elasticSearchTypeHandlers.put(Pivot.NAME, () -> new ESPivot(bucketHandlers, seriesHandlers));
    this.elasticsearchBackend = new ElasticsearchBackend(elasticSearchTypeHandlers, client, indexLookup, new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch7.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Provider(javax.inject.Provider) Query(org.graylog.plugins.views.search.Query) Mock(org.mockito.Mock) HashMap(java.util.HashMap) Captor(org.mockito.Captor) Max(org.graylog.plugins.views.search.searchtypes.pivot.series.Max) ESPivotSeriesSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotSeriesSpecHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) SearchType(org.graylog.plugins.views.search.SearchType) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) Map(java.util.Map) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) MockitoJUnit(org.mockito.junit.MockitoJUnit) Search(org.graylog.plugins.views.search.Search) Aggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation) QueryResult(org.graylog.plugins.views.search.QueryResult) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Before(org.junit.Before) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) ESMaxHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESMaxHandler) ESPivotBucketSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotBucketSpecHandler) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) ESAverageHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESAverageHandler) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) MockitoRule(org.mockito.junit.MockitoRule) Average(org.graylog.plugins.views.search.searchtypes.pivot.series.Average) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) ESPivotSeriesSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotSeriesSpecHandler) HashMap(java.util.HashMap) ESMaxHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESMaxHandler) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) Aggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation) ESAverageHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESAverageHandler) ESPivotBucketSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotBucketSpecHandler) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) Before(org.junit.Before)

Example 5 with IndexLookup

use of org.graylog.plugins.views.search.elasticsearch.IndexLookup in project graylog2-server by Graylog2.

the class ElasticsearchBackendUsingCorrectIndicesTest method setupSUT.

@Before
public void setupSUT() throws Exception {
    final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulResponseWithSingleQuery.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(handlers, client, indexLookup, new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch7.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AndFilter(org.graylog.plugins.views.search.filter.AndFilter) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Arrays(java.util.Arrays) Provider(javax.inject.Provider) Query(org.graylog.plugins.views.search.Query) DateTimeUtils(org.joda.time.DateTimeUtils) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) Captor(org.mockito.Captor) ViewsUtils.indicesOf(org.graylog.storage.elasticsearch7.views.ViewsUtils.indicesOf) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) ArgumentCaptor(org.mockito.ArgumentCaptor) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) SearchType(org.graylog.plugins.views.search.SearchType) After(org.junit.After) Map(java.util.Map) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) MockitoJUnit(org.mockito.junit.MockitoJUnit) Search(org.graylog.plugins.views.search.Search) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Before(org.junit.Before) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) TestMultisearchResponse(org.graylog.storage.elasticsearch7.testing.TestMultisearchResponse) ImmutableMap(com.google.common.collect.ImmutableMap) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) ESMessageList(org.graylog.storage.elasticsearch7.views.searchtypes.ESMessageList) MockitoRule(org.mockito.junit.MockitoRule) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Mockito.mock(org.mockito.Mockito.mock) MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Before(org.junit.Before)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)6 Query (org.graylog.plugins.views.search.Query)6 Search (org.graylog.plugins.views.search.Search)6 SearchJob (org.graylog.plugins.views.search.SearchJob)6 SearchType (org.graylog.plugins.views.search.SearchType)6 FieldTypesLookup (org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup)6 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)6 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)6 Before (org.junit.Before)6 Rule (org.junit.Rule)6 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)6 Mock (org.mockito.Mock)6 MockitoJUnit (org.mockito.junit.MockitoJUnit)6 MockitoRule (org.mockito.junit.MockitoRule)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 Collections (java.util.Collections)4 Map (java.util.Map)4 Set (java.util.Set)4 Provider (javax.inject.Provider)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4