etna 0.1.36 → 0.1.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6d9abd6b64884e701b1055215018b85939ee0bf6cc19275eccae0ebffe92856
4
- data.tar.gz: a382140c854224855b317923551d467baa3b29202ec6ebccc2fb8d7782115d06
3
+ metadata.gz: 484c950fffbafcf5132df923bc0ef88a79faa6c285ccde653805aac526e4a97e
4
+ data.tar.gz: f513b75b048e816acc494c09cb0eccbc2c38cda02c2723266fe7bd98c8595f3a
5
5
  SHA512:
6
- metadata.gz: e150a0e7dac99e3c637151033d4105617910188f9c61c8e2812b2fa75c3d3967e95bb2fa43babb98802b14640658e02167c81b825fa0e1be41cef6340a74d4fa
7
- data.tar.gz: 6f7365324ceed077161b4507397380837cc0d355f6cbd4dfff22b2abb527eaeafc2455e3cb3138d7b9a8085d3b4a2b3cf05b86417f2458a9bc80da859c77ed24
6
+ metadata.gz: 6ad0e99925dc6110c8f80f4a1e1417d610b28838497f09afe8be1c69a65fec95a7d549af987aaccde2b42480347bf336838be5398ef580d3024476206b4d611d
7
+ data.tar.gz: 44eb05596c635e7ab96df7971fed6b24bfee7bd545238e173e3d1b57bdcfe7b30db5deea355d2711b192d026d8fb72afc32cbcbcf4a83ef92848184433b7a813
data/lib/etna.rb CHANGED
@@ -21,6 +21,7 @@ require_relative './etna/environment_scoped'
21
21
  require_relative './etna/filesystem'
22
22
  require_relative './etna/formatting'
23
23
  require_relative './etna/cwl'
24
+ require_relative './etna/metrics'
24
25
 
25
26
  class EtnaApp
26
27
  include Etna::Application
@@ -8,6 +8,7 @@ require_relative './command'
8
8
  require_relative './generate_autocompletion_script'
9
9
  require 'singleton'
10
10
  require 'rollbar'
11
+ require 'fileutils'
11
12
 
12
13
  module Etna::Application
13
14
  def self.included(other)
@@ -59,6 +60,23 @@ module Etna::Application
59
60
  end
60
61
  end
61
62
 
63
+ def setup_yabeda
64
+ Yabeda.configure!
65
+ end
66
+
67
+ def write_job_metrics(name)
68
+ node_metrics_dir = config(:node_metrics_dir) || "/tmp/metrics.prom"
69
+ ::FileUtils.mkdir_p(node_metrics_dir)
70
+
71
+ tmp_file = ::File.join(node_metrics_dir, "#{name}.prom.$$")
72
+ ::File.open(tmp_file, "w") do |f|
73
+ f.write(Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry))
74
+ end
75
+
76
+ require 'fileutils'
77
+ ::FileUtils.mv(tmp_file, ::File.join(node_metrics_dir, "#{name}.prom"))
78
+ end
79
+
62
80
  def setup_logger
63
81
  @logger = Etna::Logger.new(
64
82
  # The name of the log_file, required.
@@ -52,7 +52,12 @@ class DirectedGraph
52
52
  result[grandparent] << child_node if result.include?(grandparent)
53
53
  end
54
54
 
55
- result[child_node] = []
55
+ # Depending on the graph shape, diamonds could lead to
56
+ # resetting of previously calculated dependencies.
57
+ # Here we avoid resetting existing entries in `result`
58
+ # and instead concatenate them if they already exist.
59
+ result[child_node] = [] unless result.include?(child_node)
60
+ result[n].concat(result[child_node]) if result.include?(child_node) && result.include?(n)
56
61
  end
57
62
  end
58
63
 
@@ -0,0 +1,26 @@
1
+
2
+ module Etna
3
+ class MetricsExporter
4
+ def initialize(app, path: '/metrics')
5
+ @app = app
6
+ @path = path
7
+ end
8
+
9
+ def exporter
10
+ @exporter ||= begin
11
+ exporter = Yabeda::Prometheus::Exporter.new(@app, path: @path)
12
+ Rack::Auth::Basic.new(exporter) do |user, pw|
13
+ user == 'prometheus' && pw == ENV['METRICS_PW']
14
+ end
15
+ end
16
+ end
17
+
18
+ def call(env)
19
+ if env['PATH_INFO'] == @path
20
+ exporter.call(env)
21
+ else
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/etna/route.rb CHANGED
@@ -148,7 +148,10 @@ module Etna
148
148
  params = request.env['rack.request.params']
149
149
 
150
150
  @auth[:user].all? do |constraint, param_name|
151
- user.respond_to?(constraint) && user.send(constraint, params[param_name])
151
+ user.respond_to?(constraint) && (
152
+ param_name.is_a?(Symbol) ?
153
+ user.send(constraint, params[param_name]) :
154
+ user.send(constraint, param_name))
152
155
  end
153
156
  end
154
157
 
data/lib/etna/server.rb CHANGED
@@ -74,6 +74,11 @@ module Etna
74
74
  def initialize
75
75
  # Setup logging.
76
76
  application.setup_logger
77
+
78
+ # This needs to be required before yabeda invocation, but cannot belong at the top of any module since clients
79
+ # do not install yabeda.
80
+ require 'yabeda'
81
+ application.setup_yabeda
77
82
  end
78
83
 
79
84
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saurabh Asthana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-10 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -168,6 +168,7 @@ files:
168
168
  - lib/etna/hmac.rb
169
169
  - lib/etna/json_serializable_struct.rb
170
170
  - lib/etna/logger.rb
171
+ - lib/etna/metrics.rb
171
172
  - lib/etna/multipart_serializable_nested_hash.rb
172
173
  - lib/etna/parse_body.rb
173
174
  - lib/etna/route.rb