diff --git a/plugins/nf-seqera/src/main/io/seqera/config/ExecutorOpts.groovy b/plugins/nf-seqera/src/main/io/seqera/config/ExecutorOpts.groovy index a0294dc29f..d32cf681ad 100644 --- a/plugins/nf-seqera/src/main/io/seqera/config/ExecutorOpts.groovy +++ b/plugins/nf-seqera/src/main/io/seqera/config/ExecutorOpts.groovy @@ -36,7 +36,7 @@ class ExecutorOpts implements ConfigScope { static final Set VALID_AUTO_LABELS = Collections.unmodifiableSet(new LinkedHashSet<>([ 'projectName', 'userName', 'runName', 'sessionId', 'resume', 'revision', 'commitId', 'repository', 'manifestName', - 'runtimeVersion', 'workflowId' + 'runtimeVersion', 'workflowId', 'workspaceId', 'computeEnvId' ])) final RetryOpts retryPolicy @@ -87,7 +87,7 @@ class ExecutorOpts implements ConfigScope { `['runName', 'projectName']` or `'runName,projectName'` Valid names: `projectName`, `userName`, `runName`, `sessionId`, `resume`, `revision`, `commitId`, `repository`, `manifestName`, `runtimeVersion`, - `workflowId`. + `workflowId`, `workspaceId`, `computeEnvId`. """) final Set autoLabels diff --git a/plugins/nf-seqera/src/main/io/seqera/executor/Labels.groovy b/plugins/nf-seqera/src/main/io/seqera/executor/Labels.groovy index 762d7ecfa8..8f78b97f27 100644 --- a/plugins/nf-seqera/src/main/io/seqera/executor/Labels.groovy +++ b/plugins/nf-seqera/src/main/io/seqera/executor/Labels.groovy @@ -36,7 +36,7 @@ class Labels { static final Set ALL_AUTO_LABELS = Collections.unmodifiableSet(new LinkedHashSet<>([ 'projectName', 'userName', 'runName', 'sessionId', 'resume', 'revision', 'commitId', 'repository', 'manifestName', - 'runtimeVersion', 'workflowId' + 'runtimeVersion', 'workflowId', 'workspaceId', 'computeEnvId' ])) private final Map entries = new LinkedHashMap<>(20) @@ -78,6 +78,10 @@ class Labels { entries.put('nextflow.io/runtimeVersion', NextflowMeta.instance.version.toString()) if( include.contains('workflowId') && workflow.platform?.workflowId ) entries.put('seqera.io/platform/workflowId', workflow.platform.workflowId) + if( include.contains('workspaceId') && workflow.platform?.workspace?.id ) + entries.put('seqera.io/platform/workspaceId', workflow.platform.workspace.id) + if( include.contains('computeEnvId') && workflow.platform?.computeEnv?.id ) + entries.put('seqera.io/platform/computeEnvId', workflow.platform.computeEnv.id) return this } diff --git a/plugins/nf-seqera/src/test/io/seqera/config/ExecutorOptsTest.groovy b/plugins/nf-seqera/src/test/io/seqera/config/ExecutorOptsTest.groovy index 46afd4d532..6f078dba03 100644 --- a/plugins/nf-seqera/src/test/io/seqera/config/ExecutorOptsTest.groovy +++ b/plugins/nf-seqera/src/test/io/seqera/config/ExecutorOptsTest.groovy @@ -161,6 +161,17 @@ class ExecutorOptsTest extends Specification { config.autoLabels == ['runName', 'projectName'] as Set } + def 'should accept workspaceId and computeEnvId in auto labels' () { + when: + def config = new ExecutorOpts([ + endpoint: 'https://sched.example.com', + autoLabels: ['workspaceId', 'computeEnvId'] + ]) + + then: + config.autoLabels == ['workspaceId', 'computeEnvId'] as Set + } + def 'should trim whitespace in auto labels list entries' () { when: def config = new ExecutorOpts([ diff --git a/plugins/nf-seqera/src/test/io/seqera/executor/LabelsTest.groovy b/plugins/nf-seqera/src/test/io/seqera/executor/LabelsTest.groovy index a618f02a3e..c361b55177 100644 --- a/plugins/nf-seqera/src/test/io/seqera/executor/LabelsTest.groovy +++ b/plugins/nf-seqera/src/test/io/seqera/executor/LabelsTest.groovy @@ -124,6 +124,29 @@ class LabelsTest extends Specification { !labels.entries.containsKey('seqera:sched:clusterId') } + def 'should include platform workspaceId and computeEnvId when available'() { + given: + def platform = new PlatformMetadata('wf-abc123') + platform.workspace = new PlatformMetadata.Workspace(workspaceId: '1234') + platform.computeEnv = new PlatformMetadata.ComputeEnv(id: 'ce-abc') + def workflow = Mock(WorkflowMetadata) { + getRunName() >> 'happy_turing' + getSessionId() >> UUID.randomUUID() + isResume() >> false + getManifest() >> new Manifest([:]) + getPlatform() >> platform + } + + when: + def labels = new Labels() + .withWorkflowMetadata(workflow, ['workspaceId', 'computeEnvId'] as Set) + + then: + labels.entries.keySet() == ['seqera.io/platform/workspaceId', 'seqera.io/platform/computeEnvId'] as Set + labels.entries['seqera.io/platform/workspaceId'] == '1234' + labels.entries['seqera.io/platform/computeEnvId'] == 'ce-abc' + } + def 'should include platform workflowId when available'() { given: def workflow = Mock(WorkflowMetadata) { diff --git a/plugins/nf-seqera/src/test/io/seqera/executor/SeqeraExecutorTest.groovy b/plugins/nf-seqera/src/test/io/seqera/executor/SeqeraExecutorTest.groovy index 78a8b338d2..8c66d7030f 100644 --- a/plugins/nf-seqera/src/test/io/seqera/executor/SeqeraExecutorTest.groovy +++ b/plugins/nf-seqera/src/test/io/seqera/executor/SeqeraExecutorTest.groovy @@ -185,6 +185,9 @@ class SeqeraExecutorTest extends Specification { new CreateRunResponse().runId('run-1') } } + def platform = new nextflow.script.PlatformMetadata('wf-abc123') + platform.workspace = new nextflow.script.PlatformMetadata.Workspace(workspaceId: '1234') + platform.computeEnv = new nextflow.script.PlatformMetadata.ComputeEnv(id: 'ce-abc') def workflowMeta = Mock(WorkflowMetadata) { getProjectName() >> 'my-project' getUserName() >> 'alice' @@ -195,7 +198,7 @@ class SeqeraExecutorTest extends Specification { getCommitId() >> null getRepository() >> null getManifest() >> null - getPlatform() >> null + getPlatform() >> platform } def sessionConfig = [ process: [resourceLabels: [team: 'platform', priority: 3]], @@ -223,11 +226,14 @@ class SeqeraExecutorTest extends Specification { captured.getLabels()['priority'] == '3' captured.getLabels()['nextflow.io/projectName'] == 'my-project' captured.getLabels()['nextflow.io/runName'] == 'test-run' + captured.getLabels()['seqera.io/platform/workspaceId'] == '1234' + captured.getLabels()['seqera.io/platform/computeEnvId'] == 'ce-abc' cleanup: executor.batchSubmitter?.shutdown() } + /** * Builds a SchedClientConfig using the same logic as {@link SeqeraExecutor#createClient()} */