Search in sources :

Example 1 with ESPivot

use of org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot in project graylog2-server by Graylog2.

the class ESPivotTest method setUp.

@Before
public void setUp() throws Exception {
    bucketHandlers = new HashMap<>();
    seriesHandlers = new HashMap<>();
    this.esPivot = new ESPivot(bucketHandlers, seriesHandlers);
    when(pivot.id()).thenReturn("dummypivot");
}
Also used : ESPivot(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot) Before(org.junit.Before)

Example 2 with ESPivot

use of org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot in project graylog2-server by Graylog2.

the class ESPivotTest method includesCustomNameinResultIfPresent.

@Test
public void includesCustomNameinResultIfPresent() throws InvalidRangeParametersException {
    final ESPivot esPivot = new ESPivot(Collections.emptyMap(), Collections.emptyMap());
    final Pivot pivot = Pivot.builder().id("somePivotId").name("customPivot").series(Collections.emptyList()).rollup(false).build();
    final long documentCount = 424242;
    when(queryResult.getTotal()).thenReturn(documentCount);
    final MetricAggregation mockMetricAggregation = createTimestampRangeAggregations((double) new Date().getTime(), (double) new Date().getTime());
    when(queryResult.getAggregations()).thenReturn(mockMetricAggregation);
    when(query.effectiveTimeRange(pivot)).thenReturn(RelativeRange.create(300));
    final SearchType.Result result = esPivot.doExtractResult(null, query, pivot, queryResult, null, null);
    assertThat(result.name()).contains("customPivot");
}
Also used : MetricAggregation(io.searchbox.core.search.aggregation.MetricAggregation) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) ESPivot(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot) SearchType(org.graylog.plugins.views.search.SearchType) ESPivot(org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot) Date(java.util.Date) Test(org.junit.Test)

Example 3 with ESPivot

use of org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot 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 4 with ESPivot

use of org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot 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 ESPivot

use of org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot in project graylog2-server by Graylog2.

the class ESPivotTest method includesCustomNameinResultIfPresent.

@Test
public void includesCustomNameinResultIfPresent() throws InvalidRangeParametersException {
    final ESPivot esPivot = new ESPivot(Collections.emptyMap(), Collections.emptyMap());
    final Pivot pivot = Pivot.builder().id("somePivotId").name("customPivot").series(Collections.emptyList()).rollup(false).build();
    final long documentCount = 424242;
    returnDocumentCount(queryResult, documentCount);
    final Aggregations mockMetricAggregation = createTimestampRangeAggregations((double) new Date().getTime(), (double) new Date().getTime());
    when(queryResult.getAggregations()).thenReturn(mockMetricAggregation);
    when(query.effectiveTimeRange(pivot)).thenReturn(RelativeRange.create(300));
    final SearchType.Result result = esPivot.doExtractResult(null, query, pivot, queryResult, null, null);
    assertThat(result.name()).contains("customPivot");
}
Also used : Aggregations(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) SearchType(org.graylog.plugins.views.search.SearchType) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SearchType (org.graylog.plugins.views.search.SearchType)4 Pivot (org.graylog.plugins.views.search.searchtypes.pivot.Pivot)4 Before (org.junit.Before)4 ESPivot (org.graylog.storage.elasticsearch6.views.searchtypes.pivot.ESPivot)3 ESPivot (org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Collections (java.util.Collections)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Provider (javax.inject.Provider)2 Query (org.graylog.plugins.views.search.Query)2 QueryResult (org.graylog.plugins.views.search.QueryResult)2 Search (org.graylog.plugins.views.search.Search)2 SearchJob (org.graylog.plugins.views.search.SearchJob)2 FieldTypesLookup (org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup)2 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)2 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)2 BucketSpec (org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec)2