Search in sources :

Example 6 with IndexRange

use of org.graylog2.indexer.ranges.IndexRange in project graylog2-server by Graylog2.

the class MongoIndexRangeService method calculateRange.

@Override
public IndexRange calculateRange(String index) {
    indices.waitForRecovery(index);
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final Stopwatch sw = Stopwatch.createStarted();
    final IndexRangeStats stats = indices.indexRangeStatsOfIndex(index);
    final int duration = Ints.saturatedCast(sw.stop().elapsed(TimeUnit.MILLISECONDS));
    LOG.info("Calculated range of [{}] in [{}ms].", index, duration);
    return MongoIndexRange.create(index, stats.min(), stats.max(), now, duration, stats.streamIds());
}
Also used : Stopwatch(com.google.common.base.Stopwatch) IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) DateTime(org.joda.time.DateTime)

Example 7 with IndexRange

use of org.graylog2.indexer.ranges.IndexRange in project graylog2-server by Graylog2.

the class MongoIndexRangeTest method testJsonMapping.

@Test
public void testJsonMapping() throws Exception {
    String indexName = "test";
    DateTime begin = new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC);
    DateTime end = new DateTime(2015, 2, 1, 0, 0, DateTimeZone.UTC);
    DateTime calculatedAt = new DateTime(2015, 2, 1, 0, 0, DateTimeZone.UTC);
    int calculationDuration = 42;
    MongoIndexRange indexRange = MongoIndexRange.create(indexName, begin, end, calculatedAt, calculationDuration);
    ObjectMapper objectMapper = new ObjectMapperProvider().get();
    String json = objectMapper.writeValueAsString(indexRange);
    Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);
    assertThat((String) JsonPath.read(document, "$." + MongoIndexRange.FIELD_INDEX_NAME)).isEqualTo(indexName);
    assertThat((long) JsonPath.read(document, "$." + MongoIndexRange.FIELD_BEGIN)).isEqualTo(begin.getMillis());
    assertThat((long) JsonPath.read(document, "$." + MongoIndexRange.FIELD_END)).isEqualTo(end.getMillis());
    assertThat((long) JsonPath.read(document, "$." + MongoIndexRange.FIELD_CALCULATED_AT)).isEqualTo(calculatedAt.getMillis());
    assertThat((int) JsonPath.read(document, "$." + MongoIndexRange.FIELD_TOOK_MS)).isEqualTo(calculationDuration);
}
Also used : DateTime(org.joda.time.DateTime) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test)

Example 8 with IndexRange

use of org.graylog2.indexer.ranges.IndexRange in project graylog2-server by Graylog2.

the class IndexRangesResource method show.

@GET
@Path("/{index: [a-z_0-9]+}")
@Timed
@ApiOperation(value = "Show single index range")
@Produces(MediaType.APPLICATION_JSON)
public IndexRangeSummary show(@ApiParam(name = "index", value = "The name of the Graylog-managed Elasticsearch index", required = true) @PathParam("index") @NotEmpty String index) throws NotFoundException {
    if (!indexSetRegistry.isManagedIndex(index)) {
        throw new BadRequestException(index + " is not a Graylog-managed Elasticsearch index.");
    }
    checkPermission(RestPermissions.INDEXRANGES_READ, index);
    final IndexRange indexRange = indexRangeService.get(index);
    return IndexRangeSummary.create(indexRange.indexName(), indexRange.begin(), indexRange.end(), indexRange.calculatedAt(), indexRange.calculationDuration());
}
Also used : IndexRange(org.graylog2.indexer.ranges.IndexRange) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with IndexRange

use of org.graylog2.indexer.ranges.IndexRange in project graylog2-server by Graylog2.

the class Searches method search.

public SearchResult search(SearchesConfig config) {
    Set<IndexRange> indices = determineAffectedIndicesWithRanges(config.range(), config.filter());
    Set<String> indexNames = Sets.newHashSet();
    for (IndexRange index : indices) {
        indexNames.add(index.indexName());
    }
    SearchRequest request = searchRequest(config, indexNames).request();
    SearchResponse r = c.search(request).actionGet();
    recordEsMetrics(r, config.range());
    return new SearchResult(r.getHits(), indices, config.query(), request.source(), r.getTook());
}
Also used : IndexRange(org.graylog2.indexer.ranges.IndexRange) SearchRequest(org.elasticsearch.action.search.SearchRequest) SearchResult(org.graylog2.indexer.results.SearchResult) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 10 with IndexRange

use of org.graylog2.indexer.ranges.IndexRange in project graylog2-server by Graylog2.

the class LegacyMongoIndexRangeService method findAll.

@Override
public SortedSet<IndexRange> findAll() {
    final BasicDBList subQueries = new BasicDBList();
    subQueries.add(new BasicDBObject(FIELD_INDEX, new BasicDBObject("$exists", true)));
    subQueries.add(new BasicDBObject(FIELD_START, new BasicDBObject("$exists", true)));
    final DBObject query = new BasicDBObject("$and", subQueries);
    final List<DBObject> result = query(query, COLLECTION_NAME);
    final ImmutableSortedSet.Builder<IndexRange> indexRanges = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR);
    for (DBObject dbo : result) {
        try {
            indexRanges.add(buildIndexRange(dbo));
        } catch (Exception e) {
            LOG.debug("Couldn't add index range to result set: " + dbo, e);
        }
    }
    return indexRanges.build();
}
Also used : BasicDBList(com.mongodb.BasicDBList) BasicDBObject(com.mongodb.BasicDBObject) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) NotFoundException(org.graylog2.database.NotFoundException)

Aggregations

IndexRange (org.graylog2.indexer.ranges.IndexRange)17 DateTime (org.joda.time.DateTime)11 Test (org.junit.Test)10 MongoIndexRange (org.graylog2.indexer.ranges.MongoIndexRange)9 ZonedDateTime (java.time.ZonedDateTime)8 IndexSet (org.graylog2.indexer.IndexSet)5 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)5 NotFoundException (org.graylog2.database.NotFoundException)3 SearchResult (org.graylog2.indexer.results.SearchResult)3 Timed (com.codahale.metrics.annotation.Timed)2 Stopwatch (com.google.common.base.Stopwatch)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)2 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 ApiOperation (io.swagger.annotations.ApiOperation)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 TimeValue (org.elasticsearch.common.unit.TimeValue)2 SearchHits (org.elasticsearch.search.SearchHits)2 AbstractAlertCondition (org.graylog2.alerts.AbstractAlertCondition)2 AlertConditionTest (org.graylog2.alerts.AlertConditionTest)2