Search in sources :

Example 1 with CloudStorageTraffic

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;
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) TimeSeriesPoint(org.pmiops.workbench.model.TimeSeriesPoint) CloudStorageTraffic(org.pmiops.workbench.model.CloudStorageTraffic) Point(com.google.monitoring.v3.Point) TimeSeriesPoint(org.pmiops.workbench.model.TimeSeriesPoint)

Example 2 with CloudStorageTraffic

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);
}
Also used : TimeSeries(com.google.monitoring.v3.TimeSeries) Duration(java.time.Duration) CloudStorageTraffic(org.pmiops.workbench.model.CloudStorageTraffic) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.jupiter.api.Test)

Aggregations

TimeSeries (com.google.monitoring.v3.TimeSeries)2 CloudStorageTraffic (org.pmiops.workbench.model.CloudStorageTraffic)2 Point (com.google.monitoring.v3.Point)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1 TimeSeriesPoint (org.pmiops.workbench.model.TimeSeriesPoint)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1