use of org.graylog2.indexer.IndexSetStatsCreator in project graylog2-server by Graylog2.
the class IndicesIT method retrievingIndexStatsForWildcard.
@ContainerMatrixTest
public void retrievingIndexStatsForWildcard() {
final IndexSetStatsCreator indexSetStatsCreator = new IndexSetStatsCreator(indices);
final String indexPrefix = "indices_wildcard_";
final String wildcard = indexPrefix + "*";
final IndexSet indexSet = mock(IndexSet.class);
when(indexSet.getIndexWildcard()).thenReturn(wildcard);
createRandomIndex(indexPrefix);
createRandomIndex(indexPrefix);
final IndexSetStats indexSetStats = indexSetStatsCreator.getForIndexSet(indexSet);
assertThat(indexSetStats.indices()).isEqualTo(2L);
assertThat(indexSetStats.size()).isNotZero();
}
use of org.graylog2.indexer.IndexSetStatsCreator in project graylog2-server by Graylog2.
the class IndexSetsResource method list.
@GET
@Timed
@ApiOperation(value = "Get a list of all index sets")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetResponse list(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("0") int limit, @ApiParam(name = "stats", value = "Include index set stats.") @QueryParam("stats") @DefaultValue("false") boolean computeStats) {
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
List<IndexSetSummary> indexSets;
int count;
if (limit > 0) {
// First collect all index set ids the user is allowed to see.
final Set<String> allowedIds = indexSetService.findAll().stream().filter(indexSet -> isPermitted(RestPermissions.INDEXSETS_READ, indexSet.id())).map(IndexSetConfig::id).collect(Collectors.toSet());
indexSets = indexSetService.findPaginated(allowedIds, limit, skip).stream().map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = allowedIds.size();
} else {
indexSets = indexSetService.findAll().stream().filter(indexSetConfig -> isPermitted(RestPermissions.INDEXSETS_READ, indexSetConfig.id())).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = indexSets.size();
}
final Map<String, IndexSetStats> stats;
if (computeStats) {
stats = indexSetRegistry.getAll().stream().collect(Collectors.toMap(indexSet -> indexSet.getConfig().id(), indexSetStatsCreator::getForIndexSet));
} else {
stats = Collections.emptyMap();
}
return IndexSetResponse.create(count, indexSets, stats);
}
Aggregations