deployangel 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "deployangel/version"
4
+ require_relative "deployangel/configuration"
5
+ require_relative "deployangel/core/histogram"
6
+ require_relative "deployangel/core/fingerprint"
7
+ require_relative "deployangel/core/release"
8
+ require_relative "deployangel/core/instance"
9
+ require_relative "deployangel/core/aggregator"
10
+ require_relative "deployangel/core/protocol"
11
+ require_relative "deployangel/core/buffer"
12
+ require_relative "deployangel/core/transport"
13
+ require_relative "deployangel/agent"
14
+ require_relative "deployangel/fork_hook"
15
+
16
+ module DeployAngel
17
+ # Web servers and job workers report from boot, so idle processes still
18
+ # send heartbeats.
19
+ EAGER_PROGRAMS = /puma|unicorn|passenger|falcon|pitchfork|thrust|rackup|sidekiq|jobs|solid.queue|good_job/
20
+
21
+ class << self
22
+ attr_reader :agent
23
+
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def configure
29
+ yield configuration
30
+ end
31
+
32
+ # Called by the Railtie after the app boots. Web server processes start
33
+ # reporting immediately, so idle processes still send heartbeats; other
34
+ # processes (console, rake) only report after recording a request.
35
+ def start(environment:, root: nil, framework: nil, framework_version: nil, logger: nil)
36
+ configuration.logger = logger if logger
37
+ @agent = Agent.new(config: configuration, environment: environment, root: root,
38
+ framework: framework, framework_version: framework_version, eager: server_process?)
39
+ install_exit_hook
40
+ @agent
41
+ rescue StandardError => e
42
+ configuration.logger&.warn("DeployAngel failed to start: #{e.class}: #{e.message}")
43
+ nil
44
+ end
45
+
46
+ def recording?
47
+ agent&.active? || false
48
+ end
49
+
50
+ def record_request(**attributes)
51
+ agent&.record_request(**attributes)
52
+ end
53
+
54
+ def record_job(**attributes)
55
+ agent&.record_job(**attributes)
56
+ end
57
+
58
+ def record_exception(exception, **options)
59
+ agent&.record_exception(exception, **options)
60
+ end
61
+
62
+ CHECKPOINT_NAME = /\A[a-z0-9][a-z0-9_.:-]{0,99}\z/i
63
+
64
+ # Counts a business event, such as DeployAngel.checkpoint("order.fulfilled").
65
+ # DeployAngel learns each checkpoint's normal rate and fails a release
66
+ # after which it drops sharply or stops. Cheap and safe to call anywhere:
67
+ # it never raises and never touches the network.
68
+ def checkpoint(name, count: 1)
69
+ name = name.to_s
70
+ unless name.match?(CHECKPOINT_NAME) && count.is_a?(Integer) && count.positive?
71
+ configuration.logger&.warn("DeployAngel ignored checkpoint #{name.inspect}: use letters, numbers, and . _ : - (max 100)") unless @warned_checkpoint
72
+ @warned_checkpoint = true
73
+ return
74
+ end
75
+
76
+ add_capability("checkpoints")
77
+ agent&.record_checkpoint(name, count: count)
78
+ nil
79
+ rescue StandardError
80
+ nil
81
+ end
82
+
83
+ def capabilities
84
+ @capabilities ||= %w[http exceptions]
85
+ end
86
+
87
+ def add_capability(name)
88
+ capabilities << name unless capabilities.include?(name)
89
+ end
90
+
91
+ def after_fork
92
+ agent&.after_fork!
93
+ end
94
+
95
+ def shutdown
96
+ agent&.shutdown
97
+ end
98
+
99
+ private
100
+ def server_process?
101
+ defined?(::Rails::Server) || File.basename($PROGRAM_NAME.to_s).match?(EAGER_PROGRAMS)
102
+ end
103
+
104
+ def install_exit_hook
105
+ return if @exit_hook_installed
106
+
107
+ @exit_hook_installed = true
108
+ at_exit { DeployAngel.shutdown }
109
+ end
110
+ end
111
+ end
112
+
113
+ require_relative "deployangel/rails/http"
114
+ require_relative "deployangel/rails/active_job"
115
+ require_relative "deployangel/rails/error_subscriber"
116
+ require_relative "deployangel/rails/metadata"
117
+ require_relative "deployangel/sidekiq"
118
+ require_relative "deployangel/rails/railtie" if defined?(::Rails::Railtie)
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deployangel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Owens
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Aggregates HTTP request behavior in-process and reports one small payload
13
+ per process per minute to DeployAngel, which verifies each deployment and tells
14
+ you when it is safe to stop watching it.
15
+ email:
16
+ - jordan@deployangel.com
17
+ executables:
18
+ - deployangel
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - CHANGELOG.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - exe/deployangel
26
+ - lib/deployangel.rb
27
+ - lib/deployangel/agent.rb
28
+ - lib/deployangel/capistrano.rb
29
+ - lib/deployangel/capistrano/steps.rb
30
+ - lib/deployangel/capistrano/tasks.rake
31
+ - lib/deployangel/ci_environment.rb
32
+ - lib/deployangel/cli.rb
33
+ - lib/deployangel/cli/formatter.rb
34
+ - lib/deployangel/client.rb
35
+ - lib/deployangel/configuration.rb
36
+ - lib/deployangel/core/aggregator.rb
37
+ - lib/deployangel/core/buffer.rb
38
+ - lib/deployangel/core/fingerprint.rb
39
+ - lib/deployangel/core/histogram.rb
40
+ - lib/deployangel/core/instance.rb
41
+ - lib/deployangel/core/protocol.rb
42
+ - lib/deployangel/core/release.rb
43
+ - lib/deployangel/core/transport.rb
44
+ - lib/deployangel/fork_hook.rb
45
+ - lib/deployangel/mcp.rb
46
+ - lib/deployangel/rails/active_job.rb
47
+ - lib/deployangel/rails/error_subscriber.rb
48
+ - lib/deployangel/rails/http.rb
49
+ - lib/deployangel/rails/metadata.rb
50
+ - lib/deployangel/rails/railtie.rb
51
+ - lib/deployangel/sidekiq.rb
52
+ - lib/deployangel/verification_waiter.rb
53
+ - lib/deployangel/version.rb
54
+ homepage: https://www.deployangel.com
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ homepage_uri: https://www.deployangel.com
59
+ documentation_uri: https://www.deployangel.com/docs
60
+ source_code_uri: https://github.com/DeployAngel/deployangel-ruby
61
+ changelog_uri: https://github.com/DeployAngel/deployangel-ruby/blob/main/CHANGELOG.md
62
+ bug_tracker_uri: https://github.com/DeployAngel/deployangel-ruby/issues
63
+ rubygems_mfa_required: 'true'
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '3.1'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 4.0.0
79
+ specification_version: 4
80
+ summary: 'DeployAngel agent for Rails: production verification for every deployment.'
81
+ test_files: []