Skip to content

Commit

Permalink
Add Fusion logs and tags config
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Feb 26, 2023
1 parent 828583d commit 0919207
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package nextflow.fusion

import groovy.transform.CompileStatic

/**
* Model Fusion config options
*
Expand All @@ -29,17 +28,30 @@ class FusionConfig {

final static public String DEFAULT_FUSION_AMD64_URL = 'https://fusionfs.seqera.io/releases/v2.1-amd64.json'
final static public String DEFAULT_FUSION_ARM64_URL = 'https://fusionfs.seqera.io/releases/v2.1-arm64.json'
final static public String DEFAULT_TAGS = "[.command.*|.exitcode|.fusion.*](nextflow.io/metadata=true),[*](nextflow.io/temporary=true)"

final static public String FUSION_PATH = '/usr/bin/fusion'

final private Boolean enabled
final private String containerConfigUrl
final private Boolean exportAwsAccessKeys
final private String logOutput
final private String logLevel
final private boolean tagsEnabled
final private String tagsPattern

boolean enabled() { enabled }

boolean exportAwsAccessKeys() { exportAwsAccessKeys }

String logLevel() { logLevel }

String logOutput() { logOutput }

boolean tagsEnabled() { tagsEnabled }

String tagsPattern() { tagsPattern }

URL containerConfigUrl() {
this.containerConfigUrl ? new URL(this.containerConfigUrl) : null
}
Expand All @@ -48,6 +60,10 @@ class FusionConfig {
this.enabled = opts.enabled
this.exportAwsAccessKeys = opts.exportAwsAccessKeys
this.containerConfigUrl = opts.containerConfigUrl?.toString() ?: env.get('FUSION_CONTAINER_CONFIG_URL')
this.logLevel = opts.logLevel
this.logOutput = opts.logOutput
this.tagsEnabled = opts.tags==null || opts.tags.toString()!='false'
this.tagsPattern = (opts.tags==null || (opts.tags instanceof Boolean && opts.tags)) ? DEFAULT_TAGS : ( opts.tags !instanceof Boolean ? opts.tags as String : null )
if( containerConfigUrl && !validProtocol(containerConfigUrl))
throw new IllegalArgumentException("Fusion container config URL should start with 'http:' or 'https:' protocol prefix - offending value: $containerConfigUrl")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package nextflow.fusion


import nextflow.Global
import nextflow.SysEnv
import nextflow.plugin.Plugins
Expand All @@ -35,6 +36,14 @@ class FusionEnvProvider {
final env = it.getEnvironment(scheme,config)
if( env ) result.putAll(env)
}
// tags setting
if( config.tagsEnabled() )
result.FUSION_TAGS = config.tagsPattern()
// logs setting
if( config.logOutput() )
result.FUSION_LOG_OUTPUT = config.logOutput()
if( config.logLevel() )
result.FUSION_LOG_LEVEL = config.logLevel()
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class FusionScriptLauncher extends BashWrapperBuilder {
final work = toContainerMount(remoteWorkDir).toString()
final result = new LinkedHashMap(10)
result.FUSION_WORK = work
result.FUSION_TAGS="[.command.*|.exitcode|.fusion.*](nextflow.io/metadata=true),[*](nextflow.io/temporary=true)"
// foreign env
final provider = new FusionEnvProvider()
result.putAll(provider.getEnvironment(scheme))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,37 @@ class FusionScriptLauncherTest extends Specification {
]
}

def 'should get fusion logs env' () {
given:
Global.config = [fusion: [logLevel:'debug', logOutput:'stdout', tags: false]]
and:
def fusion = new FusionScriptLauncher(
scheme: 'http',
remoteWorkDir: XPath.get('http://foo/work'))

expect:
fusion.fusionEnv() == [
FUSION_WORK: '/fusion/http/foo/work',
FUSION_LOG_LEVEL: 'debug',
FUSION_LOG_OUTPUT: 'stdout'
]
}

def 'should get fusion with custom tags' () {
given:
Global.config = [fusion: [tags: 'custom-tags-pattern-here']]
and:
def fusion = new FusionScriptLauncher(
scheme: 'http',
remoteWorkDir: XPath.get('http://foo/work'))

expect:
fusion.fusionEnv() == [
FUSION_WORK: '/fusion/http/foo/work',
FUSION_TAGS: 'custom-tags-pattern-here'
]
}

def 'should get header script' () {
given:
def fusion = new FusionScriptLauncher(scheme: 's3')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,35 @@ class FusionConfigTest extends Specification {
[exportAwsAccessKeys: true] | true
}

@Unroll
def 'should configure log level and output' () {
given:
def opts = new FusionConfig(OPTS)
expect:
opts.logLevel() == LEVEL
opts.logOutput() == OUTPUT

where:
OPTS | LEVEL | OUTPUT
[:] | null | null
[logLevel: 'trace'] | 'trace' | null
[logOutput: 'stdout'] | null | 'stdout'
}

@Unroll
def 'should configure tags' () {
given:
def opts = new FusionConfig(OPTS)
expect:
opts.tagsEnabled() == ENABLED
opts.tagsPattern() == PATTERN

where:
OPTS | ENABLED | PATTERN
[:] | true | FusionConfig.DEFAULT_TAGS
[tags:true] | true | FusionConfig.DEFAULT_TAGS
[tags:false] | false | null
[tags:'[*.txt](x=1)'] | true | '[*.txt](x=1)'

}
}

0 comments on commit 0919207

Please sign in to comment.