Skip to content

Commit 5e8276c

Browse files
authored
Add workspaceId/computeEnvId to nf-seqera auto labels (#7059)
* Add workspaceId and computeEnvId auto labels for Seqera executor Register `workspaceId` and `computeEnvId` as new `autoLabels` short names in the Seqera executor so Scheduler-backed runs can be aggregated by Platform workspace and compute environment for cost reporting. When included in `seqera.executor.autoLabels` (either via `true` or via an explicit list), `createRun` emits: - `seqera.io/platform/workspaceId` - `seqera.io/platform/computeEnvId` Values are sourced from the tower config / environment via PlatformHelper (same resolution as the existing CreateRunRequest fields) with a fallback to `seqera.executor.computeEnvId` for the compute environment ID. Signed-off-by: Jonathan Marti <jonathan.marti@seqera.io> Signed-off-by: Jon Marti <jonathan.marti@seqera.io> * Address review: fold platform IDs into withWorkflowMetadata - Drop the separate Labels.withPlatformContext method; handle workspaceId / computeEnvId inside withWorkflowMetadata alongside the existing workflowId, reading from workflow.platform.workspace.id and workflow.platform.computeEnv.id (populated by TowerClient). - Revert the extra call site in SeqeraExecutor.createRun. - Simplify the unit tests down to one focused case each. - Revert the VERSION bump and changelog entry (those belong to the release commit). Signed-off-by: Jonathan Marti <jonathan.marti@seqera.io> Signed-off-by: Jon Marti <jonathan.marti@seqera.io> --------- Signed-off-by: Jonathan Marti <jonathan.marti@seqera.io> Signed-off-by: Jon Marti <jonathan.marti@seqera.io>
1 parent e2c77c6 commit 5e8276c

5 files changed

Lines changed: 48 additions & 4 deletions

File tree

plugins/nf-seqera/src/main/io/seqera/config/ExecutorOpts.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ExecutorOpts implements ConfigScope {
3636
static final Set<String> VALID_AUTO_LABELS = Collections.unmodifiableSet(new LinkedHashSet<>([
3737
'projectName', 'userName', 'runName', 'sessionId', 'resume',
3838
'revision', 'commitId', 'repository', 'manifestName',
39-
'runtimeVersion', 'workflowId'
39+
'runtimeVersion', 'workflowId', 'workspaceId', 'computeEnvId'
4040
]))
4141

4242
final RetryOpts retryPolicy
@@ -87,7 +87,7 @@ class ExecutorOpts implements ConfigScope {
8787
`['runName', 'projectName']` or `'runName,projectName'`
8888
Valid names: `projectName`, `userName`, `runName`, `sessionId`, `resume`,
8989
`revision`, `commitId`, `repository`, `manifestName`, `runtimeVersion`,
90-
`workflowId`.
90+
`workflowId`, `workspaceId`, `computeEnvId`.
9191
""")
9292
final Set<String> autoLabels
9393

plugins/nf-seqera/src/main/io/seqera/executor/Labels.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Labels {
3636
static final Set<String> ALL_AUTO_LABELS = Collections.unmodifiableSet(new LinkedHashSet<>([
3737
'projectName', 'userName', 'runName', 'sessionId', 'resume',
3838
'revision', 'commitId', 'repository', 'manifestName',
39-
'runtimeVersion', 'workflowId'
39+
'runtimeVersion', 'workflowId', 'workspaceId', 'computeEnvId'
4040
]))
4141

4242
private final Map<String,String> entries = new LinkedHashMap<>(20)
@@ -78,6 +78,10 @@ class Labels {
7878
entries.put('nextflow.io/runtimeVersion', NextflowMeta.instance.version.toString())
7979
if( include.contains('workflowId') && workflow.platform?.workflowId )
8080
entries.put('seqera.io/platform/workflowId', workflow.platform.workflowId)
81+
if( include.contains('workspaceId') && workflow.platform?.workspace?.id )
82+
entries.put('seqera.io/platform/workspaceId', workflow.platform.workspace.id)
83+
if( include.contains('computeEnvId') && workflow.platform?.computeEnv?.id )
84+
entries.put('seqera.io/platform/computeEnvId', workflow.platform.computeEnv.id)
8185
return this
8286
}
8387

plugins/nf-seqera/src/test/io/seqera/config/ExecutorOptsTest.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ class ExecutorOptsTest extends Specification {
161161
config.autoLabels == ['runName', 'projectName'] as Set
162162
}
163163

164+
def 'should accept workspaceId and computeEnvId in auto labels' () {
165+
when:
166+
def config = new ExecutorOpts([
167+
endpoint: 'https://sched.example.com',
168+
autoLabels: ['workspaceId', 'computeEnvId']
169+
])
170+
171+
then:
172+
config.autoLabels == ['workspaceId', 'computeEnvId'] as Set
173+
}
174+
164175
def 'should trim whitespace in auto labels list entries' () {
165176
when:
166177
def config = new ExecutorOpts([

plugins/nf-seqera/src/test/io/seqera/executor/LabelsTest.groovy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ class LabelsTest extends Specification {
124124
!labels.entries.containsKey('seqera:sched:clusterId')
125125
}
126126

127+
def 'should include platform workspaceId and computeEnvId when available'() {
128+
given:
129+
def platform = new PlatformMetadata('wf-abc123')
130+
platform.workspace = new PlatformMetadata.Workspace(workspaceId: '1234')
131+
platform.computeEnv = new PlatformMetadata.ComputeEnv(id: 'ce-abc')
132+
def workflow = Mock(WorkflowMetadata) {
133+
getRunName() >> 'happy_turing'
134+
getSessionId() >> UUID.randomUUID()
135+
isResume() >> false
136+
getManifest() >> new Manifest([:])
137+
getPlatform() >> platform
138+
}
139+
140+
when:
141+
def labels = new Labels()
142+
.withWorkflowMetadata(workflow, ['workspaceId', 'computeEnvId'] as Set)
143+
144+
then:
145+
labels.entries.keySet() == ['seqera.io/platform/workspaceId', 'seqera.io/platform/computeEnvId'] as Set
146+
labels.entries['seqera.io/platform/workspaceId'] == '1234'
147+
labels.entries['seqera.io/platform/computeEnvId'] == 'ce-abc'
148+
}
149+
127150
def 'should include platform workflowId when available'() {
128151
given:
129152
def workflow = Mock(WorkflowMetadata) {

plugins/nf-seqera/src/test/io/seqera/executor/SeqeraExecutorTest.groovy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ class SeqeraExecutorTest extends Specification {
185185
new CreateRunResponse().runId('run-1')
186186
}
187187
}
188+
def platform = new nextflow.script.PlatformMetadata('wf-abc123')
189+
platform.workspace = new nextflow.script.PlatformMetadata.Workspace(workspaceId: '1234')
190+
platform.computeEnv = new nextflow.script.PlatformMetadata.ComputeEnv(id: 'ce-abc')
188191
def workflowMeta = Mock(WorkflowMetadata) {
189192
getProjectName() >> 'my-project'
190193
getUserName() >> 'alice'
@@ -195,7 +198,7 @@ class SeqeraExecutorTest extends Specification {
195198
getCommitId() >> null
196199
getRepository() >> null
197200
getManifest() >> null
198-
getPlatform() >> null
201+
getPlatform() >> platform
199202
}
200203
def sessionConfig = [
201204
process: [resourceLabels: [team: 'platform', priority: 3]],
@@ -223,11 +226,14 @@ class SeqeraExecutorTest extends Specification {
223226
captured.getLabels()['priority'] == '3'
224227
captured.getLabels()['nextflow.io/projectName'] == 'my-project'
225228
captured.getLabels()['nextflow.io/runName'] == 'test-run'
229+
captured.getLabels()['seqera.io/platform/workspaceId'] == '1234'
230+
captured.getLabels()['seqera.io/platform/computeEnvId'] == 'ce-abc'
226231

227232
cleanup:
228233
executor.batchSubmitter?.shutdown()
229234
}
230235

236+
231237
/**
232238
* Builds a SchedClientConfig using the same logic as {@link SeqeraExecutor#createClient()}
233239
*/

0 commit comments

Comments
 (0)