From 6c7d586d6bfd2825f4226551243287a1b683bec4 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Thu, 17 Aug 2023 09:23:27 -0500 Subject: [PATCH] Add resource labels support for Azure Batch (#4178) Signed-off-by: Ben Sherman Signed-off-by: Paolo Di Tommaso Co-authored-by: Paolo Di Tommaso --- docs/executor.md | 6 +++++- docs/process.md | 14 ++++++++++++-- .../cloud/azure/batch/AzBatchService.groovy | 16 ++++++++++++++-- .../cloud/azure/batch/AzVmPoolSpec.groovy | 1 + .../cloud/azure/batch/AzBatchServiceTest.groovy | 4 +++- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/docs/executor.md b/docs/executor.md index 1cce5ecd1d..a14d867146 100644 --- a/docs/executor.md +++ b/docs/executor.md @@ -28,6 +28,7 @@ Resource requests and other job characteristics can be controlled via the follow - {ref}`process-cpus` - {ref}`process-memory` - {ref}`process-queue` +- {ref}`process-resourcelabels` - {ref}`process-time` See the {ref}`AWS Batch` page for further configuration details. @@ -55,6 +56,7 @@ Resource requests and other job characteristics can be controlled via the follow - {ref}`process-machineType` - {ref}`process-memory` - {ref}`process-queue` +- {ref}`process-resourcelabels` - {ref}`process-time` See the {ref}`Azure Batch ` page for further configuration details. @@ -191,8 +193,8 @@ Resource requests and other job characteristics can be controlled via the follow - {ref}`process-disk` - {ref}`process-machineType` - {ref}`process-memory` -- {ref}`process-time` - {ref}`process-resourcelabels` +- {ref}`process-time` See the {ref}`Google Cloud Batch ` page for further configuration details. @@ -218,6 +220,7 @@ Resource requests and other job characteristics can be controlled via the follow - {ref}`process-disk` - {ref}`process-machineType` - {ref}`process-memory` +- {ref}`process-resourcelabels` - {ref}`process-time` See the {ref}`Google Life Sciences ` page for further configuration details. @@ -312,6 +315,7 @@ Resource requests and other job characteristics can be controlled via the follow - {ref}`process-disk` - {ref}`process-memory` - {ref}`process-pod` +- {ref}`process-resourcelabels` - {ref}`process-time` See the {ref}`Kubernetes ` page to learn how to set up a Kubernetes cluster to run Nextflow pipelines. diff --git a/docs/process.md b/docs/process.md index db7a594aca..7c4eb7fce0 100644 --- a/docs/process.md +++ b/docs/process.md @@ -2121,8 +2121,18 @@ process my_task { The limits and the syntax of the corresponding cloud provider should be taken into consideration when using resource labels. -:::{note} -Resource labels are currently only supported by the {ref}`awsbatch-executor`, {ref}`google-lifesciences-executor`, Google Cloud Batch and {ref}`k8s-executor` executors. +Resource labels are currently supported by the following executors: + +- {ref}`awsbatch-executor` +- {ref}`azurebatch-executor` +- {ref}`google-batch-executor` +- {ref}`google-lifesciences-executor` +- {ref}`k8s-executor` + +:::{versionadded} 23.09.0-edge +Resource labels are supported for Azure Batch when using automatic pool creation. + +Resource labels in Azure are added to pools, rather than jobs, in order to facilitate cost analysis. A new pool will be created for each new set of resource labels, therefore it is recommended to also set `azure.batch.deletePoolsOnCompletion = true` when using process-specific resource labels. ::: See also: [label](#label) diff --git a/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzBatchService.groovy b/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzBatchService.groovy index ddd858991f..a16506e4ad 100644 --- a/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzBatchService.groovy +++ b/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzBatchService.groovy @@ -39,6 +39,7 @@ import com.microsoft.azure.batch.protocol.models.ContainerRegistry import com.microsoft.azure.batch.protocol.models.ElevationLevel import com.microsoft.azure.batch.protocol.models.ImageInformation import com.microsoft.azure.batch.protocol.models.JobUpdateParameter +import com.microsoft.azure.batch.protocol.models.MetadataItem import com.microsoft.azure.batch.protocol.models.MountConfiguration import com.microsoft.azure.batch.protocol.models.NetworkConfiguration import com.microsoft.azure.batch.protocol.models.OnAllTasksComplete @@ -563,9 +564,10 @@ class AzBatchService implements Closeable { throw new IllegalArgumentException(msg) } - final key = CacheHelper.hasher([vmType.name, opts]).hash().toString() + final metadata = task.config.getResourceLabels() + final key = CacheHelper.hasher([vmType.name, opts, metadata]).hash().toString() final poolId = "nf-pool-$key-$vmType.name" - return new AzVmPoolSpec(poolId: poolId, vmType: vmType, opts: opts) + return new AzVmPoolSpec(poolId: poolId, vmType: vmType, opts: opts, metadata: metadata) } protected void checkPool(CloudPool pool, AzVmPoolSpec spec) { @@ -698,6 +700,16 @@ class AzBatchService implements Closeable { .withTaskSlotsPerNode(spec.vmType.numberOfCores) .withStartTask(poolStartTask) + // resource labels + if( spec.metadata ) { + final metadata = spec.metadata.collect { name, value -> + new MetadataItem() + .withName(name) + .withValue(value) + } + poolParams.withMetadata(metadata) + } + // virtual network if( spec.opts.virtualNetwork ) poolParams.withNetworkConfiguration( new NetworkConfiguration().withSubnetId(spec.opts.virtualNetwork) ) diff --git a/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzVmPoolSpec.groovy b/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzVmPoolSpec.groovy index d9ac092c85..257edb6cfb 100644 --- a/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzVmPoolSpec.groovy +++ b/plugins/nf-azure/src/main/nextflow/cloud/azure/batch/AzVmPoolSpec.groovy @@ -36,4 +36,5 @@ class AzVmPoolSpec { String poolId AzVmType vmType AzPoolOpts opts + Map metadata } diff --git a/plugins/nf-azure/src/test/nextflow/cloud/azure/batch/AzBatchServiceTest.groovy b/plugins/nf-azure/src/test/nextflow/cloud/azure/batch/AzBatchServiceTest.groovy index 055a795b27..0b00cc9a38 100644 --- a/plugins/nf-azure/src/test/nextflow/cloud/azure/batch/AzBatchServiceTest.groovy +++ b/plugins/nf-azure/src/test/nextflow/cloud/azure/batch/AzBatchServiceTest.groovy @@ -338,6 +338,7 @@ class AzBatchServiceTest extends Specification { getMemory() >> MEM getCpus() >> CPUS getMachineType() >> TYPE + getResourceLabels() >> [foo: 'bar'] } } @@ -346,7 +347,8 @@ class AzBatchServiceTest extends Specification { then: 1 * svc.guessBestVm(LOC, CPUS, MEM, TYPE) >> VM and: - spec.poolId == 'nf-pool-ddb1223ab79edfe07c0af2be7fceeb13-Standard_X1' + spec.poolId == 'nf-pool-9022a3fbfb5f93028d78fefaea5e21ab-Standard_X1' + spec.metadata == [foo: 'bar'] }