Search in sources :

Example 31 with TimeRange

use of org.graylog2.plugin.indexer.searches.timeranges.TimeRange in project graylog2-server by Graylog2.

the class SearchesTest method determineAffectedIndicesIncludesDeflectorTarget.

@Test
public void determineAffectedIndicesIncludesDeflectorTarget() throws Exception {
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final MongoIndexRange indexRange0 = MongoIndexRange.create("graylog_0", now, now.plusDays(1), now, 0);
    final MongoIndexRange indexRange1 = MongoIndexRange.create("graylog_1", now.plusDays(1), now.plusDays(2), now, 0);
    final MongoIndexRange indexRangeLatest = MongoIndexRange.create("graylog_2", new DateTime(0L, DateTimeZone.UTC), new DateTime(0L, DateTimeZone.UTC), now, 0);
    final SortedSet<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(indexRange0).add(indexRange1).add(indexRangeLatest).build();
    when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indices);
    final TimeRange absoluteRange = AbsoluteRange.create(now.minusDays(1), now.plusDays(1));
    final TimeRange keywordRange = KeywordRange.create("1 day ago");
    final TimeRange relativeRange = RelativeRange.create(3600);
    assertThat(searches.determineAffectedIndices(absoluteRange, null)).containsExactlyInAnyOrder(indexRangeLatest.indexName(), indexRange0.indexName(), indexRange1.indexName());
    assertThat(searches.determineAffectedIndices(keywordRange, null)).containsExactlyInAnyOrder(indexRangeLatest.indexName(), indexRange0.indexName(), indexRange1.indexName());
    assertThat(searches.determineAffectedIndices(relativeRange, null)).containsExactlyInAnyOrder(indexRangeLatest.indexName(), indexRange0.indexName(), indexRange1.indexName());
}
Also used : MongoIndexRange(org.graylog2.indexer.ranges.MongoIndexRange) IndexRange(org.graylog2.indexer.ranges.IndexRange) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) MongoIndexRange(org.graylog2.indexer.ranges.MongoIndexRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 32 with TimeRange

use of org.graylog2.plugin.indexer.searches.timeranges.TimeRange in project graylog2-server by Graylog2.

the class BundleImporter method createDashboardWidget.

@SuppressWarnings("unchecked")
private org.graylog2.dashboards.widgets.DashboardWidget createDashboardWidget(final DashboardWidget dashboardWidget, final String userName) throws InvalidRangeParametersException, org.graylog2.dashboards.widgets.DashboardWidget.NoSuchWidgetTypeException, InvalidWidgetConfigurationException {
    final String type = dashboardWidget.getType();
    final Map<String, Object> config = dashboardWidget.getConfiguration();
    // Replace "stream_id" in config if it's set
    final String streamReference = (String) config.get("stream_id");
    if (!isNullOrEmpty(streamReference)) {
        final org.graylog2.plugin.streams.Stream stream = streamsByReferenceId.get(streamReference);
        if (null != stream) {
            config.put("stream_id", stream.getId());
        } else {
            LOG.warn("Couldn't find referenced stream {}", streamReference);
        }
    }
    // Build timerange.
    final Map<String, Object> timerangeConfig = (Map<String, Object>) config.get("timerange");
    final TimeRange timeRange = timeRangeFactory.create(timerangeConfig);
    final String widgetId = UUID.randomUUID().toString();
    return dashboardWidgetCreator.buildDashboardWidget(type, widgetId, dashboardWidget.getDescription(), dashboardWidget.getCacheTime(), config, timeRange, userName);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 33 with TimeRange

use of org.graylog2.plugin.indexer.searches.timeranges.TimeRange in project graylog2-server by Graylog2.

the class DashboardWidgetCreator method fromRequest.

public DashboardWidget fromRequest(String widgetId, AddWidgetRequest awr, String userId) throws DashboardWidget.NoSuchWidgetTypeException, InvalidRangeParametersException, InvalidWidgetConfigurationException {
    final String id = isNullOrEmpty(widgetId) ? UUID.randomUUID().toString() : widgetId;
    // Build timerange.
    final Map<String, Object> timerangeConfig = (Map<String, Object>) awr.config().get("timerange");
    final TimeRange timeRange = timeRangeFactory.create(timerangeConfig);
    return buildDashboardWidget(awr.type(), id, awr.description(), 0, awr.config(), timeRange, userId);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) BasicDBObject(com.mongodb.BasicDBObject) Map(java.util.Map)

Example 34 with TimeRange

use of org.graylog2.plugin.indexer.searches.timeranges.TimeRange in project graylog2-server by Graylog2.

the class SearchResourceTest method restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet.

@Test
public void restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet() {
    when(clusterConfigService.get(SearchesClusterConfig.class)).thenReturn(SearchesClusterConfig.createDefault().toBuilder().queryTimeRangeLimit(Period.ZERO).build());
    final SearchResource resource = new SearchResource(searches, clusterConfigService, decoratorProcessor) {
    };
    final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC);
    final DateTime to = from.plusYears(1);
    final TimeRange timeRange = AbsoluteRange.create(from, to);
    final TimeRange restrictedTimeRange = resource.restrictTimeRange(timeRange);
    assertThat(restrictedTimeRange).isNotNull();
    assertThat(restrictedTimeRange.getFrom()).isEqualTo(from);
    assertThat(restrictedTimeRange.getTo()).isEqualTo(to);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 35 with TimeRange

use of org.graylog2.plugin.indexer.searches.timeranges.TimeRange in project graylog2-server by Graylog2.

the class SearchResourceTest method restrictTimeRangeReturnsGivenTimeRangeWithinLimit.

@Test
public void restrictTimeRangeReturnsGivenTimeRangeWithinLimit() {
    when(clusterConfigService.get(SearchesClusterConfig.class)).thenReturn(SearchesClusterConfig.createDefault().toBuilder().queryTimeRangeLimit(queryLimitPeriod).build());
    final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC);
    final DateTime to = from.plusHours(1);
    final TimeRange timeRange = AbsoluteRange.create(from, to);
    final TimeRange restrictedTimeRange = searchResource.restrictTimeRange(timeRange);
    assertThat(restrictedTimeRange).isNotNull();
    assertThat(restrictedTimeRange.getFrom()).isEqualTo(from);
    assertThat(restrictedTimeRange.getTo()).isEqualTo(to);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)21 DateTime (org.joda.time.DateTime)14 Test (org.junit.Test)10 Timed (com.codahale.metrics.annotation.Timed)8 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Produces (javax.ws.rs.Produces)8 ZonedDateTime (java.time.ZonedDateTime)6 GET (javax.ws.rs.GET)6 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)6 SearchRequest (org.elasticsearch.action.search.SearchRequest)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 IndexRange (org.graylog2.indexer.ranges.IndexRange)6 InvalidRangeParametersException (org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException)6 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)5 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)5 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)5 MongoIndexRange (org.graylog2.indexer.ranges.MongoIndexRange)5 Sorting (org.graylog2.indexer.searches.Sorting)5 ScrollResult (org.graylog2.indexer.results.ScrollResult)4