neetodeploy-autoscale 0.4.0 → 0.6.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0b25708e10d77c473b33ff4f46b1537b0977bb18c990f54bdf33afc4b3a6947
|
4
|
+
data.tar.gz: d2faea5f93812588a2850b5cf5e2bb84e5efbf3295331e7340f2153d43ec2841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a732fd7615496308c4e10da3b73dfbdf82e0713d906719e618e9a07fc1611a279b12186ff232b467ae2c42663dc4314b592c848810acc3882af006806bce3220
|
7
|
+
data.tar.gz: b9b4ee9cbb20796597ca64dfd4c0d621c2f88b66655544c3e0f376c3e0defd71b261f489f3ccd90ddbdd087e3059bed8147d96ee84e3a0edf6e5f539b039efdf
|
@@ -12,7 +12,7 @@ module Neetodeploy
|
|
12
12
|
def call(env)
|
13
13
|
url = URI.parse("https://nd-queue-time-exporter.neetodeployapp.com/metrics")
|
14
14
|
|
15
|
-
query_params = URI.encode_www_form(app_name: ENV.to_h["NEETODEPLOY_APP_NAME"], queue_time: queue_time(env))
|
15
|
+
query_params = URI.encode_www_form(app_name: ENV.to_h["NEETODEPLOY_APP_NAME"], process_type: "web", queue_time: queue_time(env))
|
16
16
|
|
17
17
|
url.query = query_params
|
18
18
|
|
@@ -31,17 +31,17 @@ module Neetodeploy
|
|
31
31
|
def started_at(env)
|
32
32
|
return nil unless env["HTTP_X_REQUEST_START"].present?
|
33
33
|
|
34
|
-
|
34
|
+
env["HTTP_X_REQUEST_START"].to_i
|
35
35
|
end
|
36
36
|
|
37
37
|
def network_time(env)
|
38
38
|
env["puma.request_body_wait"].to_i
|
39
39
|
end
|
40
40
|
|
41
|
-
def queue_time(now = Time.now, env)
|
41
|
+
def queue_time(now = Time.now.to_f * 1000, env)
|
42
42
|
return if started_at(env).nil?
|
43
43
|
|
44
|
-
queue_time = (
|
44
|
+
queue_time = (now - started_at(env)).round
|
45
45
|
queue_time -= network_time(env)
|
46
46
|
|
47
47
|
queue_time.positive? ? queue_time : 0
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "time"
|
5
|
+
|
6
|
+
module Neetodeploy
|
7
|
+
class SidekiqMiddleware
|
8
|
+
def call(worker, job, queue)
|
9
|
+
url = URI.parse("https://nd-queue-time-exporter.neetodeployapp.com/metrics")
|
10
|
+
|
11
|
+
query_params = URI.encode_www_form(app_name: ENV.to_h["NEETODEPLOY_APP_NAME"], process_type: "worker", queue_time: queue_time(worker, job, queue))
|
12
|
+
|
13
|
+
url.query = query_params
|
14
|
+
|
15
|
+
post = Net::HTTP::Post.new(url)
|
16
|
+
post["AuthToken"] = "K0An3O3MSyEEMTCnRd1IHgGjdGQkzy"
|
17
|
+
|
18
|
+
Net::HTTP.start(url.host, url.port, use_ssl: false) do |http|
|
19
|
+
http.request(post)
|
20
|
+
end
|
21
|
+
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def queue_time(worker, job, queue)
|
28
|
+
(Time.now - Time.at(job["created_at"])) * 1000
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -5,10 +5,29 @@ require_relative "neetodeploy/autoscale/version"
|
|
5
5
|
module Neetodeploy
|
6
6
|
module Autoscale
|
7
7
|
class Error < StandardError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def setup_middleware
|
11
|
+
require "neetodeploy/autoscale/middleware"
|
12
|
+
Neetodeploy::Autoscale.setup_rails if defined? Rails
|
13
|
+
Neetodeploy::Autoscale.setup_sidekiq if defined?(Sidekiq)
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup_rails
|
17
|
+
require "neetodeploy/autoscale/railtie"
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup_sidekiq
|
21
|
+
require "neetodeploy/autoscale/sidekiq_middleware"
|
22
|
+
|
23
|
+
Sidekiq.configure_server do |config|
|
24
|
+
config.server_middleware do |chain|
|
25
|
+
chain.add Neetodeploy::SidekiqMiddleware
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
8
30
|
end
|
9
31
|
end
|
10
32
|
|
11
|
-
|
12
|
-
require "neetodeploy/autoscale/middleware"
|
13
|
-
require "neetodeploy/autoscale/railtie" if defined? Rails
|
14
|
-
end
|
33
|
+
ENV.to_h["NEETODEPLOY_APP_NAME"].present? && Neetodeploy::Autoscale.setup_middleware
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neetodeploy-autoscale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sreeram Venkitesh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: For automatically scaling your Rails application based on network metrics
|
14
14
|
email:
|
@@ -25,6 +25,7 @@ files:
|
|
25
25
|
- lib/neetodeploy-autoscale.rb
|
26
26
|
- lib/neetodeploy/autoscale/middleware.rb
|
27
27
|
- lib/neetodeploy/autoscale/railtie.rb
|
28
|
+
- lib/neetodeploy/autoscale/sidekiq_middleware.rb
|
28
29
|
- lib/neetodeploy/autoscale/version.rb
|
29
30
|
homepage: https://neetodeploy.com
|
30
31
|
licenses: []
|
@@ -47,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
48
|
- !ruby/object:Gem::Version
|
48
49
|
version: '0'
|
49
50
|
requirements: []
|
50
|
-
rubygems_version: 3.3.
|
51
|
+
rubygems_version: 3.3.26
|
51
52
|
signing_key:
|
52
53
|
specification_version: 4
|
53
54
|
summary: neetoDeploy autoscaler gem
|