Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add safety checks for reporting metrics #2

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PollyConfig {

PollyConfig(Map map) {
def config = map ?: Collections.emptyMap()
metricsStreamName = config.metricsStreamName ?: 'pravaah-dev-user-defined-metrics-events-stream-v1'
metricsStreamName = config.metricsStreamName ?: "NA"
}

String getMetricsStreamName() { metricsStreamName }
Expand Down
19 changes: 18 additions & 1 deletion plugins/nf-polly/src/main/nextflow/polly/PollyExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class PollyExtension extends PluginExtensionPoint {
*/
private PollyConfig config

/**
* A map of 'env' variables set in the Nextflow config file
*/
private Map env

/*
* nf-core initializes the plugin once loaded and session is ready
* @param session
Expand All @@ -53,6 +58,7 @@ class PollyExtension extends PluginExtensionPoint {
protected void init(Session session) {
this.session = session
this.config = new PollyConfig(session.config.navigate('polly') as Map)
this.env = session.config.navigate('env') as Map
}

/**
Expand All @@ -65,8 +71,19 @@ class PollyExtension extends PluginExtensionPoint {
@Function
void reportMetric(var key, var value) {
logger.info(String.format("Putting record with key='%s' & value='%s'", key, value))

String streamName = this.config.getMetricsStreamName()
String jobId = System.getenv("job_id") ?: "NA"
if (streamName == "NA") {
logger.error("No stream set for process to send metrics to. Unable to report metric.")
return
}

String jobId = this.env.get("JOB_ID") ?: "NA"
if (jobId == "NA") {
logger.error("No JOB_ID set for process. Unable to report metric.")
return
}

String partitionKey = key.toString()
try {
Map map = [job_id: jobId, key: key, value: value, type: getValueType(value)]
Expand Down
Loading