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());
}
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);
}
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());
}
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());
}
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();
}
Aggregations