Skip to content

Commit

Permalink
Split workflow executions in half if request body size is too big
Browse files Browse the repository at this point in the history
  • Loading branch information
kathy-t committed Jan 19, 2024
1 parent 38b05b4 commit 311671f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
5 changes: 5 additions & 0 deletions metricsaggregator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -292,6 +296,7 @@
<usedDependency>org.javamoney.moneta:moneta-core</usedDependency>
<usedDependency>ch.qos.logback:logback-classic</usedDependency>
<usedDependency>ch.qos.logback:logback-core</usedDependency>
<usedDependency>com.google.guava:guava</usedDependency>
</usedDependencies>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.dockstore.utils.ExceptionHandler.exceptionMessage;
import static java.util.stream.Collectors.groupingBy;

import com.google.common.collect.Lists;
import io.dockstore.common.Partner;
import io.dockstore.metricsaggregator.MetricsAggregatorConfig;
import io.dockstore.metricsaggregator.client.cli.CommandLineArgs.SubmitTerraMetrics;
Expand Down Expand Up @@ -44,6 +45,7 @@
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -167,21 +169,46 @@ private void submitWorkflowExecutions(String sourceUrl, List<CSVRecord> workflow
}

final SourceUrlTrsInfo sourceUrlTrsInfo = sourceUrlToSourceUrlTrsInfo.get(sourceUrl);
final List<RunExecution> workflowExecutionsToSubmit = workflowMetricRecords.stream()
List<RunExecution> workflowExecutionsToSubmit = workflowMetricRecords.stream()
.map(workflowExecution -> getTerraWorkflowExecutionFromCsvRecord(workflowExecution, sourceUrlTrsInfo.sourceUrl(), skippedExecutionsCsvPrinter))
.filter(Optional::isPresent)
.map(Optional::get)
.toList();
final ExecutionsRequestBody executionsRequestBody = new ExecutionsRequestBody().runExecutions(workflowExecutionsToSubmit);
String description = "Submitted using the metricsaggregator's submit-terra-metrics command";
if (StringUtils.isNotBlank(submitTerraMetricsCommand.getDescription())) {
description += ". " + submitTerraMetricsCommand.getDescription();

Check warning on line 179 in metricsaggregator/src/main/java/io/dockstore/metricsaggregator/client/cli/TerraMetricsSubmitter.java

View check run for this annotation

Codecov / codecov/patch

metricsaggregator/src/main/java/io/dockstore/metricsaggregator/client/cli/TerraMetricsSubmitter.java#L179

Added line #L179 was not covered by tests
}

executionMetricsPost(workflowExecutionsToSubmit, sourceUrlTrsInfo, description, extendedGa4GhApi, workflowMetricRecords, skippedExecutionsCsvPrinter);
}

/**
* Submit Terra workflow executions to Dockstore.
* If the request fails with a 413 Request Entity Too Large, the function halves the number of workflow executions to submit then re-attempts submission
* until it's successful or a non-413 error occurs.
* @param workflowExecutionsToSubmit
* @param sourceUrlTrsInfo
* @param description
* @param extendedGa4GhApi
* @param workflowMetricRecords
* @param skippedExecutionsCsvPrinter
*/
private void executionMetricsPost(List<RunExecution> workflowExecutionsToSubmit, SourceUrlTrsInfo sourceUrlTrsInfo, String description, ExtendedGa4GhApi extendedGa4GhApi, List<CSVRecord> workflowMetricRecords, CSVPrinter skippedExecutionsCsvPrinter) {
try {
String description = "Submitted using the metricsaggregator's submit-terra-metrics command";
if (StringUtils.isNotBlank(submitTerraMetricsCommand.getDescription())) {
description += ". " + submitTerraMetricsCommand.getDescription();
}
extendedGa4GhApi.executionMetricsPost(executionsRequestBody, Partner.TERRA.toString(), sourceUrlTrsInfo.trsId(), sourceUrlTrsInfo.version(), description);
extendedGa4GhApi.executionMetricsPost(new ExecutionsRequestBody().runExecutions(workflowExecutionsToSubmit), Partner.TERRA.toString(), sourceUrlTrsInfo.trsId(),
sourceUrlTrsInfo.version(), description);
numberOfExecutionsSubmitted.addAndGet(workflowMetricRecords.size());
} catch (ApiException e) {
logSkippedExecutions(sourceUrlTrsInfo.sourceUrl(), workflowMetricRecords, String.format("Could not submit execution metrics to Dockstore for workflow %s: %s", sourceUrlTrsInfo, e.getMessage()), skippedExecutionsCsvPrinter, false);
if (e.getCode() == HttpStatus.SC_REQUEST_TOO_LONG) {
List<List<RunExecution>> workflowExecutionsToSubmitPartitions = Lists.partition(workflowExecutionsToSubmit, 2);

Check warning on line 203 in metricsaggregator/src/main/java/io/dockstore/metricsaggregator/client/cli/TerraMetricsSubmitter.java

View check run for this annotation

Codecov / codecov/patch

metricsaggregator/src/main/java/io/dockstore/metricsaggregator/client/cli/TerraMetricsSubmitter.java#L203

Added line #L203 was not covered by tests
for (List<RunExecution> partition: workflowExecutionsToSubmitPartitions) {
executionMetricsPost(partition, sourceUrlTrsInfo, description, extendedGa4GhApi, workflowMetricRecords, skippedExecutionsCsvPrinter);
}
} else {
logSkippedExecutions(sourceUrlTrsInfo.sourceUrl(), workflowMetricRecords,
String.format("Could not submit execution metrics to Dockstore for workflow %s: %s", sourceUrlTrsInfo,
e.getMessage()), skippedExecutionsCsvPrinter, false);

Check warning on line 210 in metricsaggregator/src/main/java/io/dockstore/metricsaggregator/client/cli/TerraMetricsSubmitter.java

View check run for this annotation

Codecov / codecov/patch

metricsaggregator/src/main/java/io/dockstore/metricsaggregator/client/cli/TerraMetricsSubmitter.java#L205-L210

Added lines #L205 - L210 were not covered by tests
}
}
}

Expand Down

0 comments on commit 311671f

Please sign in to comment.