use of org.pmiops.workbench.model.CloudStorageTraffic in project workbench by all-of-us.
the class WorkspaceAdminServiceImpl method getCloudStorageTraffic.
@Override
public CloudStorageTraffic getCloudStorageTraffic(String workspaceNamespace) {
CloudStorageTraffic response = new CloudStorageTraffic().receivedBytes(new ArrayList<>());
String googleProject = getWorkspaceByNamespaceOrThrow(workspaceNamespace).getGoogleProject();
for (TimeSeries timeSeries : cloudMonitoringService.getCloudStorageReceivedBytes(googleProject, TRAILING_TIME_TO_QUERY)) {
for (Point point : timeSeries.getPointsList()) {
response.addReceivedBytesItem(new TimeSeriesPoint().timestamp(Timestamps.toMillis(point.getInterval().getEndTime())).value(point.getValue().getDoubleValue()));
}
}
response.getReceivedBytes().sort(Comparator.comparing(TimeSeriesPoint::getTimestamp));
return response;
}
use of org.pmiops.workbench.model.CloudStorageTraffic in project workbench by all-of-us.
the class WorkspaceAdminServiceTest method getCloudStorageTraffic_sortsPointsByTimestamp.
@Test
public void getCloudStorageTraffic_sortsPointsByTimestamp() {
TimeSeries timeSeries = TimeSeries.newBuilder().addPoints(Point.newBuilder().setInterval(TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(2000))).setValue(TypedValue.newBuilder().setDoubleValue(1234))).addPoints(Point.newBuilder().setInterval(TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(1000))).setValue(TypedValue.newBuilder().setDoubleValue(1234))).build();
when(mockCloudMonitoringService.getCloudStorageReceivedBytes(anyString(), any(Duration.class))).thenReturn(Collections.singletonList(timeSeries));
final CloudStorageTraffic cloudStorageTraffic = workspaceAdminService.getCloudStorageTraffic(WORKSPACE_NAMESPACE);
assertThat(cloudStorageTraffic.getReceivedBytes().stream().map(TimeSeriesPoint::getTimestamp).collect(Collectors.toList())).containsExactly(1000L, 2000L);
}
Aggregations