Skip to content

Commit

Permalink
Fix cwl-metrics extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan committed May 6, 2021
1 parent 2bf9dc1 commit 43c0a8c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
53 changes: 53 additions & 0 deletions lib/ep3/extensions/cwl-metrics/bin/sendMetricsFailureLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby
require 'json'
require 'optparse'

if $0 == __FILE__
opt = OptionParser.new
opt.banner = "#{$0} [options] <response> <err> <tag> <interrupted>"

opt.parse!(ARGV)
unless ARGV.length == 4
puts opt.help
exit
end

resfile, errfile, tag, interrupted = *ARGV

unless File.exist? resfile
raise "File not found: #{resfile}"
end
res_str = open(resfile).read
begin
response = JSON.load(res_str)
message = 'Failed to send metrics'
rescue JSON::ParserError
response = res_str
message = 'Invalid response from metrics server'
end

unless File.exist? errfile
raise "File not found: #{errfile}"
end
err = open(errfile).read

level = if interrupted == 'true'
'warning'
else
'error'
end

ret = {
'log-level' => level,
'interrupted' => interrupted == 'true',
'tag' => tag,
'message' => message,
'response' => response,
'stderr' => err,
'metrics_server' => ENV['ES_HOST'],
'metrics_port' => ENV['ES_PORT'],
}

puts JSON.dump(ret)
end

10 changes: 8 additions & 2 deletions lib/ep3/extensions/cwl-metrics/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ hooks:
out:
- place: uuid
pattern: ~(newfile)
- place: es_response
pattern: ~(newfile)
command: |
uuid=$(uuidgen)
echo $uuid > ~(out.uuid)
Expand All @@ -47,7 +49,11 @@ hooks:
-H "Content-Type: application/json" \
-X POST \
"${ES_HOST}:${ES_PORT}/workflow/_doc/${uuid}?pretty" \
--data-binary @"~(in.cwl.metrics.json)" > /dev/null
--data-binary @"~(in.cwl.metrics.json)" > ~(out.es_response)
result=$(jq -r .result ~(out.es_response))
test "$result" = 'created'
log:
failure: sendMetricsFailureLog ~(tr.newfile.es_response) ~(tr.stderr) ~(tag) ~(interrupted)
transitions:
- name: prepare-metrics-directory
type: shell
Expand Down Expand Up @@ -246,7 +252,7 @@ hooks:
- place: cid
pattern: ~(in.cid)
command: |
mem=$(docker info 2> /dev/null | grep "Total Memory" | awk '{ print $3 }')
mem=$(docker info | grep "Total Memory" | awk '{ print $3 }')
docker info --format '{{json .}}' | jq "{ running_containers: .ContainersRunning, server_version: .ServerVersion, storage_driver: .Driver, number_of_cpu: .NCPU, total_memory: \"$mem\" }" > ~(out.metrics.runtime.json)
cid=$(cat ~(in.cid))
docker inspect $cid | jq "{ id: \"$cid\", image: .[0].Config.Image, cmd: .[0].Config.Cmd | join(\" \"), status: .[0].State.Status, start_time: .[0].State.StartedAt, end_time: .[0].State.FinishedAt, exit_code: .[0].State.ExitCode }" > ~(out.metrics.process.json)
Expand Down

0 comments on commit 43c0a8c

Please sign in to comment.