Skip to content

Commit

Permalink
Merge pull request #2 from ElucidataInc/PRD-138/productionize_nf_polly
Browse files Browse the repository at this point in the history
Add safety checks for reporting metrics
  • Loading branch information
saif-el committed Apr 15, 2024
2 parents cabae54 + 05bf8ff commit 9b1eda7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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

0 comments on commit 9b1eda7

Please sign in to comment.