Skip to content

Commit

Permalink
Add /system/indices/index_sets/{id}/stats to fetch individual index s…
Browse files Browse the repository at this point in the history
…et stats (Graylog2#4129)

Closes Graylog2#4088
  • Loading branch information
joschi authored and bernd committed Sep 11, 2017
1 parent 73e87d1 commit bd65376
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ public IndexSetSummary get(@ApiParam(name = "id", required = true)
.orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}

@GET
@Path("{id}/stats")
@Timed
@ApiOperation(value = "Get index set statistics")
@ApiResponses(value = {
@ApiResponse(code = 403, message = "Unauthorized"),
@ApiResponse(code = 404, message = "Index set not found"),
})
public IndexSetStats indexSetStatistics(@ApiParam(name = "id", required = true)
@PathParam("id") String id) {
checkPermission(RestPermissions.INDEXSETS_READ, id);
return indexSetRegistry.get(id)
.map(indexSetStatsCreator::getForIndexSet)
.orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}

@POST
@Timed
@ApiOperation(value = "Create index set")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.graylog2.plugin.cluster.ClusterConfigService;
import org.graylog2.rest.resources.system.indexer.requests.IndexSetUpdateRequest;
import org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse;
import org.graylog2.rest.resources.system.indexer.responses.IndexSetStats;
import org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary;
import org.graylog2.shared.bindings.GuiceInjectorHolder;
import org.graylog2.system.jobs.SystemJobManager;
Expand Down Expand Up @@ -245,6 +246,46 @@ public void getDenied() {
}
}

@Test
public void indexSetStatistics() {
final IndexSet indexSet = mock(IndexSet.class);
final IndexSetStats indexSetStats = IndexSetStats.create(5L, 23L, 42L);

when(indexSetRegistry.get("id")).thenReturn(Optional.of(indexSet));
when(indexSetStatsCreator.getForIndexSet(indexSet)).thenReturn(indexSetStats);

assertThat(indexSetsResource.indexSetStatistics("id")).isEqualTo(indexSetStats);
}

@Test
public void indexSetStatistics0() {
when(indexSetRegistry.get("id")).thenReturn(Optional.empty());

expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Couldn't load index set with ID <id>");

try {
indexSetsResource.indexSetStatistics("id");
} finally {
verify(indexSetRegistry, times(1)).get("id");
verifyNoMoreInteractions(indexSetRegistry);
}
}

@Test
public void indexSetStatisticsDenied() {
notPermitted();

expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Not authorized to access resource id <id>");

try {
indexSetsResource.indexSetStatistics("id");
} finally {
verifyZeroInteractions(indexSetRegistry);
}
}

@Test
public void save() {
final IndexSetConfig indexSetConfig = IndexSetConfig.create(
Expand Down

0 comments on commit bd65376

Please sign in to comment.