dogapi 1.23.0 → 1.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/Gemfile +11 -2
- data/lib/capistrano/README.md +11 -0
- data/lib/capistrano/datadog.rb +39 -16
- data/lib/capistrano/datadog/v2.rb +6 -14
- data/lib/capistrano/datadog/v3.rb +24 -13
- data/lib/dogapi/common.rb +1 -1
- data/lib/dogapi/version.rb +1 -1
- metadata +22 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8af26835da807d734048331e326f41734ad0d43
|
4
|
+
data.tar.gz: f7adbdd5a2a4afa6ae81d39a8250ad74692656ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c679456882e5e7babf2cee567f0cdd1f4bf67c477b07a7e3195c0103b704fd9131569564df1c43583832635ffcb794c8ebe91952d2ecee5353f58f28f062f8f
|
7
|
+
data.tar.gz: 54df8543e2c6b0fb4d771b323d01c3190ac1204fb7cf138c83f16b3579dea6003712f46723f7b481399053ea807ada33ef23a6717edfe789afee309af16b7b9b
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
Changes
|
2
2
|
=======
|
3
3
|
|
4
|
-
# 1.
|
4
|
+
# 1.24.0 / 2017-01-12
|
5
|
+
|
6
|
+
* [FEATURE] Add the ability to record events per host and to filter events. See [#115][] (thanks [@hnovikov][])
|
7
|
+
* [BUGFIX] Encode extra\_params to handle spaces. See [#113][] (thanks [@miknight][])
|
8
|
+
* [BUGFIX] Fix CaptureIO delegation and output with Capistrano >= 3.5. See [#114][] (thanks [@casperisfine][])
|
9
|
+
|
10
|
+
# 1.23.0 / 2016-08-24
|
5
11
|
|
6
12
|
* [FEATURE] Add Datadog endpoint to configuration. See [#108][]
|
7
13
|
* [FEATURE] Add delete method for events. See [#99][], [#109][]
|
@@ -159,12 +165,18 @@ This is the last release compatible with Ruby 1.8. ([EOL 2013-06-30](https://www
|
|
159
165
|
[#106]: https://github.com/DataDog/dogapi-rb/issues/106
|
160
166
|
[#108]: https://github.com/DataDog/dogapi-rb/issues/108
|
161
167
|
[#109]: https://github.com/DataDog/dogapi-rb/issues/109
|
168
|
+
[#113]: https://github.com/DataDog/dogapi-rb/issues/113
|
169
|
+
[#114]: https://github.com/DataDog/dogapi-rb/issues/114
|
170
|
+
[#115]: https://github.com/DataDog/dogapi-rb/issues/115
|
162
171
|
[@ArjenSchwarz]: https://github.com/ArjenSchwarz
|
163
172
|
[@Kaixiang]: https://github.com/Kaixiang
|
164
173
|
[@ansel1]: https://github.com/ansel1
|
165
174
|
[@arielo]: https://github.com/arielo
|
166
175
|
[@blakehilscher]: https://github.com/blakehilscher
|
167
176
|
[@byroot]: https://github.com/byroot
|
177
|
+
[@casperisfine]: https://github.com/casperisfine
|
178
|
+
[@hnovikov]: https://github.com/hnovikov
|
179
|
+
[@miknight]: https://github.com/miknight
|
168
180
|
[@nots]: https://github.com/nots
|
169
181
|
[@rmoriz]: https://github.com/rmoriz
|
170
182
|
[@treeder]: https://github.com/treeder
|
data/Gemfile
CHANGED
@@ -7,9 +7,18 @@ group :test do
|
|
7
7
|
gem 'rspec'
|
8
8
|
gem 'rubocop', '~> 0.41.2'
|
9
9
|
gem 'simplecov'
|
10
|
-
gem 'webmock'
|
11
10
|
if RbConfig::CONFIG['ruby_version'].start_with?("1.9")
|
12
|
-
|
11
|
+
gem 'json', '< 2'
|
12
|
+
gem 'public_suffix', '< 1.5'
|
13
|
+
gem 'rdoc', '< 5'
|
14
|
+
gem 'term-ansicolor', '< 1.4'
|
15
|
+
gem 'webmock', '< 2.3'
|
16
|
+
gem 'nokogiri', '< 1.7'
|
17
|
+
elsif RbConfig::CONFIG['ruby_version'].start_with?("2.0")
|
18
|
+
gem 'nokogiri', '< 1.7'
|
19
|
+
gem 'webmock'
|
20
|
+
else
|
21
|
+
gem 'webmock'
|
13
22
|
end
|
14
23
|
end
|
15
24
|
|
data/lib/capistrano/README.md
CHANGED
@@ -7,6 +7,17 @@ To set up your Capfile:
|
|
7
7
|
require "capistrano/datadog"
|
8
8
|
set :datadog_api_key, "my_api_key"
|
9
9
|
|
10
|
+
# (optional) create an event for every host
|
11
|
+
# default: create a global event
|
12
|
+
# Warning: as this feature can create a lot of events,
|
13
|
+
# please use it in conjonction with datadog_event_filter
|
14
|
+
# set :datadog_record_hosts, false
|
15
|
+
|
16
|
+
# (optional) filter the events sent to Datadog
|
17
|
+
# default: no filter
|
18
|
+
# for instance, only push the production event
|
19
|
+
# set :datadog_event_filter, proc { |event, hosts| event.msg_title.include?('ran production') ? [event, hosts] : nil }
|
20
|
+
|
10
21
|
You can find your Datadog API key [here](https://app.datadoghq.com/account/settings#api). If you don't have a Datadog account, you can sign up for one [here](http://www.datadoghq.com/).
|
11
22
|
|
12
23
|
`capistrano/datadog` will capture each Capistrano task that that Capfile runs, including the roles that the task applies to and any logging output that it emits and submits them as events to Datadog at the end of the execution of all the tasks. If sending to Datadog fails for any reason, your scripts will still succeed.
|
data/lib/capistrano/datadog.rb
CHANGED
@@ -26,8 +26,14 @@ module Capistrano
|
|
26
26
|
begin
|
27
27
|
if api_key
|
28
28
|
dog = Dogapi::Client.new(api_key)
|
29
|
-
reporter.report.each do |event|
|
30
|
-
|
29
|
+
reporter.report.each do |event, hosts|
|
30
|
+
if hosts.size > 0
|
31
|
+
hosts.each do |host|
|
32
|
+
dog.emit_event event, host: host
|
33
|
+
end
|
34
|
+
else
|
35
|
+
dog.emit_event event
|
36
|
+
end
|
31
37
|
end
|
32
38
|
else
|
33
39
|
puts 'No api key set, not submitting to Datadog'
|
@@ -41,29 +47,44 @@ module Capistrano
|
|
41
47
|
|
42
48
|
# Collects info about the tasks that ran in order to submit to Datadog
|
43
49
|
class Reporter
|
44
|
-
attr_accessor :
|
50
|
+
attr_accessor :event_filter
|
45
51
|
|
46
52
|
def initialize()
|
47
53
|
@tasks = []
|
48
|
-
@
|
49
|
-
@logging_output = {}
|
54
|
+
@task_stack = []
|
50
55
|
end
|
51
56
|
|
52
|
-
def record_task(task_name,
|
53
|
-
|
57
|
+
def record_task(task_name, roles, stage=nil, application_name=nil)
|
58
|
+
task = {
|
54
59
|
:name => task_name,
|
55
|
-
:timing => timing,
|
56
60
|
:roles => roles,
|
57
61
|
:stage => stage,
|
58
|
-
:application => application_name
|
62
|
+
:application => application_name,
|
63
|
+
:logs => [],
|
64
|
+
:hosts => []
|
59
65
|
}
|
66
|
+
@tasks << task
|
67
|
+
@task_stack << task
|
68
|
+
result = nil
|
69
|
+
timing = Benchmark.measure(task_name) do
|
70
|
+
result = yield
|
71
|
+
end
|
72
|
+
task[:timing] = timing.real
|
73
|
+
@task_stack.pop
|
74
|
+
result
|
60
75
|
end
|
61
76
|
|
62
77
|
def record_log(message)
|
63
|
-
|
64
|
-
|
78
|
+
current_task = @task_stack.last
|
79
|
+
if current_task
|
80
|
+
current_task[:logs] << message
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def record_hostname(hostname)
|
85
|
+
@task_stack.each do |task|
|
86
|
+
task[:hosts] << hostname
|
65
87
|
end
|
66
|
-
@logging_output[@current_task] << message
|
67
88
|
end
|
68
89
|
|
69
90
|
def report()
|
@@ -73,6 +94,8 @@ module Capistrano
|
|
73
94
|
# Lazy randomness
|
74
95
|
aggregation_key = Digest::MD5.hexdigest "#{Time.new}|#{rand}"
|
75
96
|
|
97
|
+
filter = event_filter || proc { |x| x }
|
98
|
+
|
76
99
|
# Convert the tasks into Datadog events
|
77
100
|
@tasks.map do |task|
|
78
101
|
name = task[:name]
|
@@ -89,21 +112,21 @@ module Capistrano
|
|
89
112
|
type = 'deploy'
|
90
113
|
alert_type = 'success'
|
91
114
|
source_type = 'capistrano'
|
92
|
-
message_content =
|
115
|
+
message_content = task[:logs].join('')
|
93
116
|
message = if !message_content.empty? then
|
94
117
|
# Strip out color control characters
|
95
118
|
message_content = sanitize_encoding(message_content).gsub(/\e\[(\d+)m/, '')
|
96
119
|
"@@@\n#{message_content}@@@" else '' end
|
97
120
|
|
98
|
-
Dogapi::Event.new(message,
|
121
|
+
[Dogapi::Event.new(message,
|
99
122
|
:msg_title => title,
|
100
123
|
:event_type => type,
|
101
124
|
:event_object => aggregation_key,
|
102
125
|
:alert_type => alert_type,
|
103
126
|
:source_type_name => source_type,
|
104
127
|
:tags => tags
|
105
|
-
)
|
106
|
-
end
|
128
|
+
), task[:hosts]]
|
129
|
+
end.map(&event_filter).reject(&:nil?)
|
107
130
|
end
|
108
131
|
|
109
132
|
def sanitize_encoding(string)
|
@@ -14,28 +14,20 @@ module Capistrano
|
|
14
14
|
# outputted for submission to Datadog
|
15
15
|
def find_and_execute_task(path, hooks= {})
|
16
16
|
task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
|
17
|
-
result = nil
|
18
17
|
reporter = Capistrano::Datadog.reporter
|
19
18
|
task_name = task.fully_qualified_name
|
20
|
-
timing = Benchmark.measure(task_name) do
|
21
|
-
# Set the current task so that the logger knows which task to
|
22
|
-
# associate the logs with
|
23
|
-
reporter.current_task = task_name
|
24
|
-
trigger(hooks[:before], task) if hooks[:before]
|
25
|
-
result = execute_task(task)
|
26
|
-
trigger(hooks[:after], task) if hooks[:after]
|
27
|
-
reporter.current_task = nil
|
28
|
-
end
|
29
19
|
|
30
|
-
# Record the task name, its timing and roles
|
31
20
|
roles = task.options[:roles]
|
32
21
|
if roles.is_a? Proc
|
33
22
|
roles = roles.call
|
34
23
|
end
|
35
|
-
reporter.record_task(task_name, timing.real, roles, task.namespace.variables[:stage], fetch(:application))
|
36
24
|
|
37
|
-
|
38
|
-
|
25
|
+
reporter.record_task(task_name, roles, task.namespace.variables[:stage], fetch(:application)) do
|
26
|
+
trigger(hooks[:before], task) if hooks[:before]
|
27
|
+
result = execute_task(task)
|
28
|
+
trigger(hooks[:after], task) if hooks[:after]
|
29
|
+
result
|
30
|
+
end
|
39
31
|
end
|
40
32
|
end
|
41
33
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'benchmark'
|
2
|
+
require 'delegate'
|
2
3
|
require 'sshkit/formatters/pretty'
|
3
4
|
require 'sshkit/formatters/simple_text'
|
4
5
|
|
@@ -8,41 +9,51 @@ module Rake
|
|
8
9
|
class Task
|
9
10
|
alias old_invoke invoke
|
10
11
|
def invoke(*args)
|
11
|
-
result = nil
|
12
12
|
reporter = Capistrano::Datadog.reporter
|
13
|
+
event_filter = Capistrano::Configuration.env.fetch(:datadog_event_filter)
|
14
|
+
if event_filter
|
15
|
+
reporter.event_filter = event_filter
|
16
|
+
end
|
13
17
|
task_name = name
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
stage = Capistrano::Configuration.env.fetch(:stage)
|
19
|
+
application = Capistrano::Configuration.env.fetch(:application)
|
20
|
+
reporter.record_task(task_name, roles, stage, application) do
|
21
|
+
old_invoke(*args)
|
17
22
|
end
|
18
|
-
reporter.record_task(task_name, timing.real, roles,
|
19
|
-
Capistrano::Configuration.env.fetch(:stage), Capistrano::Configuration.env.fetch(:application))
|
20
|
-
result
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
module Capistrano
|
28
|
+
module DSL
|
29
|
+
alias old_on on
|
30
|
+
def on(hosts, *args, &block)
|
31
|
+
old_on(hosts, *args) do |host|
|
32
|
+
if Capistrano::Configuration.env.fetch(:datadog_record_hosts)
|
33
|
+
Capistrano::Datadog.reporter.record_hostname(host)
|
34
|
+
end
|
35
|
+
self.instance_exec(host, &block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
26
40
|
module Datadog
|
27
|
-
class CaptureIO
|
41
|
+
class CaptureIO < SimpleDelegator
|
28
42
|
def initialize(wrapped)
|
43
|
+
super
|
29
44
|
@wrapped = wrapped
|
30
45
|
end
|
31
46
|
|
32
47
|
def write(*args)
|
33
48
|
# Check if Capistrano version >= 3.5.0
|
34
49
|
if Gem::Version.new(VERSION) >= Gem::Version.new('3.5.0')
|
35
|
-
@wrapped << args
|
50
|
+
@wrapped << args.join
|
36
51
|
else
|
37
52
|
@wrapped.write(*args)
|
38
53
|
end
|
39
54
|
args.each { |arg| Capistrano::Datadog.reporter.record_log(arg) }
|
40
55
|
end
|
41
56
|
alias :<< :write
|
42
|
-
|
43
|
-
def close
|
44
|
-
@wrapped.close
|
45
|
-
end
|
46
57
|
end
|
47
58
|
end
|
48
59
|
end
|
data/lib/dogapi/common.rb
CHANGED
@@ -136,7 +136,7 @@ module Dogapi
|
|
136
136
|
params = { api_key: @api_key }
|
137
137
|
params[:application_key] = @application_key if with_app_key
|
138
138
|
params = extra_params.merge params unless extra_params.nil?
|
139
|
-
qs_params = params.map { |k, v| k.to_s + '=' + v.to_s }
|
139
|
+
qs_params = params.map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }
|
140
140
|
qs = '?' + qs_params.join('&')
|
141
141
|
qs
|
142
142
|
end
|
data/lib/dogapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Datadog, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rdoc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Ruby bindings for Datadog's API
|
@@ -74,11 +74,11 @@ extensions: []
|
|
74
74
|
extra_rdoc_files:
|
75
75
|
- README.rdoc
|
76
76
|
files:
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .rubocop.yml
|
80
|
+
- .tailor
|
81
|
+
- .travis.yml
|
82
82
|
- CHANGELOG.md
|
83
83
|
- Gemfile
|
84
84
|
- LICENSE
|
@@ -135,27 +135,27 @@ licenses:
|
|
135
135
|
metadata: {}
|
136
136
|
post_install_message:
|
137
137
|
rdoc_options:
|
138
|
-
-
|
138
|
+
- --title
|
139
139
|
- DogAPI -- Datadog Client
|
140
|
-
-
|
140
|
+
- --main
|
141
141
|
- README.rdoc
|
142
|
-
-
|
143
|
-
-
|
142
|
+
- --line-numbers
|
143
|
+
- --inline-source
|
144
144
|
require_paths:
|
145
145
|
- lib
|
146
146
|
required_ruby_version: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
|
-
- -
|
148
|
+
- - '>='
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '0'
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
|
-
- -
|
153
|
+
- - '>='
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.0.14.1
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Ruby bindings for Datadog's API
|
@@ -177,4 +177,3 @@ test_files:
|
|
177
177
|
- spec/spec_helper.rb
|
178
178
|
- spec/unit/common_spec.rb
|
179
179
|
- spec/unit/facade_spec.rb
|
180
|
-
has_rdoc: true
|