dogapi 1.30 → 1.31.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebee611bd7522efe9456a959522706572585e27cd7a7c702749584318bfc291b
4
- data.tar.gz: 8d3fedc656c9443618b164fdcb0a9dd601f88dee81d000fc210f7338aacb3a34
3
+ metadata.gz: e9f77255b968b9091ed12bc8f849c06176ed6ff0b53a78b061c76432af14ad5f
4
+ data.tar.gz: d49bb8d4241f7b1232d13887908ddc211782931258bddaa4648d9ab2eafa1615
5
5
  SHA512:
6
- metadata.gz: c4be6b9543da77c590ba0e155f2b92bb9c52befa16825d835d81721a3792cc7fd58e4a1a888a46a0856d7f099c124fd49eafa2674133660b3bda2ce0e6ab5bbf
7
- data.tar.gz: 32e79e62b507f2c2d514bcd28449f1eb5d1c4856c8a8ebcb6b7a2204299f552b4e83fe0ff0b90be30fd21882ffdebed775a4806015681986d52866b0dd45038e
6
+ metadata.gz: 9e66a2caae73756e7882ed5b7bc7aa4830d3045c14bf2bb272f3c77e8cef6c3a7879e0daf725c52b2d6279f993d4ae8deb994f67e6ee39484a9cae281490d8bc
7
+ data.tar.gz: 63ea3b3ba9e1fd0d8d53ef9e714b96afc907977f2d98fc3044fd03aa25ff3346a3859557f1b8544a456e767a5d3fdf47611449230bc0434d47620c5df5106fe2
@@ -1,18 +1,11 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-03-23 17:40:12 -0400 using RuboCop version 0.49.1.
3
+ # on 2018-10-01 12:52:09 +0200 using RuboCop version 0.49.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
10
- # Configuration parameters: Include.
11
- # Include: **/Gemfile, **/gems.rb
12
- Bundler/DuplicatedGem:
13
- Exclude:
14
- - 'Gemfile'
15
-
16
9
  # Offense count: 1
17
10
  # Cop supports --auto-correct.
18
11
  # Configuration parameters: Include, TreatCommentsAsGroupSeparators.
@@ -58,7 +51,7 @@ Layout/EmptyLines:
58
51
  - 'lib/capistrano/datadog/v2.rb'
59
52
  - 'lib/dogapi/facade.rb'
60
53
 
61
- # Offense count: 60
54
+ # Offense count: 63
62
55
  # Cop supports --auto-correct.
63
56
  # Configuration parameters: EnforcedStyle, SupportedStyles.
64
57
  # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
@@ -210,21 +203,21 @@ Lint/UselessAssignment:
210
203
 
211
204
  # Offense count: 11
212
205
  Metrics/AbcSize:
213
- Max: 50
206
+ Max: 51
214
207
 
215
- # Offense count: 15
208
+ # Offense count: 18
216
209
  # Configuration parameters: CountComments, ExcludedMethods.
217
210
  Metrics/BlockLength:
218
211
  Max: 96
219
212
 
220
- # Offense count: 1
213
+ # Offense count: 2
221
214
  Metrics/CyclomaticComplexity:
222
- Max: 7
215
+ Max: 8
223
216
 
224
217
  # Offense count: 15
225
218
  # Configuration parameters: CountComments.
226
219
  Metrics/MethodLength:
227
- Max: 33
220
+ Max: 34
228
221
 
229
222
  # Offense count: 2
230
223
  # Configuration parameters: CountKeywordArgs.
@@ -233,7 +226,7 @@ Metrics/ParameterLists:
233
226
 
234
227
  # Offense count: 1
235
228
  Metrics/PerceivedComplexity:
236
- Max: 8
229
+ Max: 9
237
230
 
238
231
  # Offense count: 11
239
232
  Style/AccessorMethodName:
@@ -316,7 +309,7 @@ Style/ConditionalAssignment:
316
309
  Exclude:
317
310
  - 'lib/capistrano/datadog.rb'
318
311
 
319
- # Offense count: 19
312
+ # Offense count: 20
320
313
  # Cop supports --auto-correct.
321
314
  Style/DefWithParentheses:
322
315
  Exclude:
@@ -380,12 +373,11 @@ Style/HashSyntax:
380
373
  - 'lib/dogapi/v1/snapshot.rb'
381
374
  - 'lib/dogapi/v1/tag.rb'
382
375
 
383
- # Offense count: 16
376
+ # Offense count: 15
384
377
  # Cop supports --auto-correct.
385
378
  # Configuration parameters: MaxLineLength.
386
379
  Style/IfUnlessModifier:
387
380
  Exclude:
388
- - 'Gemfile'
389
381
  - 'lib/capistrano/datadog.rb'
390
382
  - 'lib/capistrano/datadog/v2.rb'
391
383
  - 'lib/capistrano/datadog/v3.rb'
@@ -401,7 +393,7 @@ Style/LineEndConcatenation:
401
393
  Exclude:
402
394
  - 'dogapi.gemspec'
403
395
 
404
- # Offense count: 14
396
+ # Offense count: 15
405
397
  # Cop supports --auto-correct.
406
398
  Style/MethodCallWithoutArgsParentheses:
407
399
  Exclude:
@@ -410,13 +402,13 @@ Style/MethodCallWithoutArgsParentheses:
410
402
  - 'lib/dogapi/facade.rb'
411
403
  - 'lib/dogapi/v1/event.rb'
412
404
 
413
- # Offense count: 5
405
+ # Offense count: 4
414
406
  # Cop supports --auto-correct.
415
407
  Style/MultilineIfThen:
416
408
  Exclude:
417
409
  - 'lib/capistrano/datadog.rb'
418
410
 
419
- # Offense count: 20
411
+ # Offense count: 21
420
412
  # Cop supports --auto-correct.
421
413
  Style/MutableConstant:
422
414
  Enabled: false
@@ -478,6 +470,12 @@ Style/RedundantSelf:
478
470
  - 'lib/dogapi/facade.rb'
479
471
  - 'lib/dogapi/v1/metric.rb'
480
472
 
473
+ # Offense count: 1
474
+ # Cop supports --auto-correct.
475
+ Style/RescueModifier:
476
+ Exclude:
477
+ - 'lib/capistrano/datadog.rb'
478
+
481
479
  # Offense count: 2
482
480
  # Cop supports --auto-correct.
483
481
  Style/SelfAssignment:
@@ -493,7 +491,7 @@ Style/SpecialGlobalVars:
493
491
  Exclude:
494
492
  - 'dogapi.gemspec'
495
493
 
496
- # Offense count: 23
494
+ # Offense count: 22
497
495
  # Cop supports --auto-correct.
498
496
  # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
499
497
  # SupportedStyles: single_quotes, double_quotes
@@ -520,13 +518,12 @@ Style/TrailingCommaInLiteral:
520
518
  - 'lib/dogapi/v1/snapshot.rb'
521
519
  - 'lib/dogapi/v1/user.rb'
522
520
 
523
- # Offense count: 3
521
+ # Offense count: 2
524
522
  # Cop supports --auto-correct.
525
523
  # Configuration parameters: EnforcedStyle, SupportedStyles, MinSize, WordRegex.
526
524
  # SupportedStyles: percent, brackets
527
525
  Style/WordArray:
528
526
  Exclude:
529
- - 'Rakefile'
530
527
  - 'examples/custom_event.rb'
531
528
 
532
529
  # Offense count: 1
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 1.31.0 / 2018-10-01
4
+
5
+ * [FIX] Handle nil values from benchmarks in Capistrano. See [#159][].
6
+ * [IMPROVEMENT] Add getter/setter for datadog_host. See [#160][].
7
+
3
8
  ## 1.30 / 2018-06-05
4
9
 
5
10
  * [FIX] Change API endpoint. See [#147][].
@@ -204,6 +209,8 @@ This is the last release compatible with Ruby 1.8. ([EOL 2013-06-30](https://www
204
209
  [#147]: https://github.com/DataDog/dogapi-rb/issues/147
205
210
  [#151]: https://github.com/DataDog/dogapi-rb/issues/151
206
211
  [#152]: https://github.com/DataDog/dogapi-rb/issues/152
212
+ [#159]: https://github.com/DataDog/dogapi-rb/issues/159
213
+ [#160]: https://github.com/DataDog/dogapi-rb/issues/160
207
214
  [@ArjenSchwarz]: https://github.com/ArjenSchwarz
208
215
  [@Kaixiang]: https://github.com/Kaixiang
209
216
  [@acroos]: https://github.com/acroos
@@ -49,6 +49,34 @@ to take advantage of automatic tagging with the host's tags.
49
49
  If you want to attach events and points to a specific device
50
50
  on a host, simply specify the device when calling emit functions.
51
51
 
52
+ == Configure the Datadog API Url
53
+
54
+
55
+ require 'rubygems'
56
+ require 'dogapi'
57
+
58
+ api_key = "abcdef123456"
59
+ application_key = "fedcba654321"
60
+
61
+ # by default the API Url will be set to https://api.datadoghq.com
62
+ dog = Dogapi::Client.new(api_key, application_key)
63
+ p dog.datadog_host # prints https://api.datadoghq.com
64
+
65
+ # API Url can be passed to the initializer...
66
+ dog = Dogapi::Client.new(api_key, application_key, nil, nil, nil, nil, 'https://myproxy.local')
67
+ p dog.datadog_host # prints https://myproxy.local
68
+
69
+ # ...or set on the client instance directly
70
+ dog = Dogapi::Client.new(api_key, application_key)
71
+ dog.datadog_host = 'https://myproxy.local'
72
+ p dog.datadog_host # prints https://myproxy.local
73
+
74
+ # in any case, contents of the DATADOG_HOST env var take precedence
75
+ ENV['DATADOG_HOST'] = https://myproxy.local
76
+ dog = Dogapi::Client.new(api_key, application_key)
77
+ p dog.datadog_host # prints https://myproxy.local
78
+
79
+
52
80
  == Submit an event to Datadog
53
81
 
54
82
 
data/Rakefile CHANGED
@@ -24,3 +24,7 @@ end
24
24
  task :rubocop do
25
25
  sh "rubocop"
26
26
  end
27
+
28
+ task :rubocop_todo do
29
+ sh "rubocop --auto-gen-config"
30
+ end
@@ -25,13 +25,3 @@ dog.emit_event(Dogapi::Event.new("Now that's better",
25
25
  :alert_type => "success",
26
26
  :tags => ["ruby", "dogapi"]
27
27
  ))
28
-
29
- # You should see something like this in your stream:
30
- # screenshot: https://img.skitch.com/20120705-3s4icgxfc689x1jtrx1yr1m5k.png
31
-
32
- # And if you graph a metric and want to overlay these events on the graphs
33
- # You can use the following query: "tags:dogapi tags:ruby" in the graph editor
34
- # screenshot: https://img.skitch.com/20120705-m4h6f4377cbm2d3rctnd6biej9.png
35
-
36
- # Then you can see the events neatly overlaid on your graph
37
- # screenshot: https://img.skitch.com/20120705-xybhimti31u4s4m42ac854568h.png
@@ -13,7 +13,9 @@ module Capistrano
13
13
 
14
14
  def self.cap_version()
15
15
  if @cap_version.nil? then
16
- if Configuration.respond_to? :instance then
16
+ if !defined? Configuration
17
+ @cap_version = ''
18
+ elsif Configuration.respond_to? :instance
17
19
  @cap_version = :v2
18
20
  else
19
21
  @cap_version = :v3
@@ -108,8 +110,9 @@ module Capistrano
108
110
  if !task[:application].nil? and !task[:application].empty? then
109
111
  application = ' for ' + task[:application]
110
112
  end
113
+ timing = Float(task[:timing]).round(2) rescue 'n/a'
111
114
  title = "#{user}@#{hostname} ran #{name}#{application} on #{roles.join(', ')} "\
112
- "with capistrano in #{task[:timing].round(2)} secs"
115
+ "with capistrano in #{timing} secs"
113
116
  type = 'deploy'
114
117
  alert_type = 'success'
115
118
  source_type = 'capistrano'
@@ -12,6 +12,7 @@ module Dogapi
12
12
  # information about the JSON object structure is available in the HTTP API
13
13
  # documentation, here[https://github.com/DataDog/dogapi/wiki].
14
14
  class Client # rubocop:disable Metrics/ClassLength
15
+ attr_accessor :datadog_host
15
16
 
16
17
  def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil, endpoint=nil)
17
18
 
@@ -1,3 +1,3 @@
1
1
  module Dogapi
2
- VERSION = '1.30'
2
+ VERSION = '1.31.0'
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'capistrano/datadog'
3
+ require 'benchmark'
4
+
5
+ describe 'Capistrano' do
6
+ context 'Reporter' do
7
+ context 'report' do
8
+ before(:each) do
9
+ @task = {
10
+ name: 'ATask',
11
+ roles: [],
12
+ stage: 'AStage',
13
+ application: 'MyApp',
14
+ logs: [],
15
+ hosts: []
16
+ }
17
+ @reporter = Capistrano::Datadog.reporter
18
+ end
19
+
20
+ it 'normally works with float timing' do
21
+ @task[:timing] = 9.99999
22
+ expected = @task[:timing].round(2)
23
+ @reporter.instance_variable_set(:@tasks, [@task])
24
+ event = @reporter.report.first.first
25
+ expect(event.msg_title).to include("with capistrano in #{expected} secs")
26
+ end
27
+
28
+ it 'handles non-numeric timing' do
29
+ @task[:timing] = nil
30
+ @reporter.instance_variable_set(:@tasks, [@task])
31
+ event = @reporter.report.first.first
32
+ expect(event.msg_title).to include('with capistrano in n/a secs')
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,6 +1,17 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe 'Common' do
4
+ describe Dogapi.find_datadog_host do
5
+ it 'gives precedence to DATADOG_HOST env var' do
6
+ allow(ENV).to receive(:[]).with('DATADOG_HOST').and_return('example.com')
7
+ expect(Dogapi.find_datadog_host).to eq 'example.com'
8
+ end
9
+ it 'falls back to default url when DATADOG_HOST env var is not set' do
10
+ allow(ENV).to receive(:[]).with('DATADOG_HOST').and_return(nil)
11
+ expect(Dogapi.find_datadog_host).to eq 'https://api.datadoghq.com'
12
+ end
13
+ end
14
+
4
15
  context 'Scope' do
5
16
  it 'validates the Scope class' do
6
17
  obj = Dogapi::Scope.new('somehost', 'somedevice')
@@ -11,6 +11,19 @@ describe Dogapi::Client do
11
11
  end
12
12
  end
13
13
 
14
+ describe 'Datadog API url' do
15
+ it 'can be set in initializer' do
16
+ client = Dogapi::Client.new(api_key, app_key, nil, nil, nil, nil, 'example.com')
17
+ expect(client.datadog_host).to eq 'example.com'
18
+ end
19
+
20
+ it 'can be set with instance var' do
21
+ client = Dogapi::Client.new(api_key, app_key)
22
+ client.datadog_host = 'example.com'
23
+ expect(client.datadog_host).to eq 'example.com'
24
+ end
25
+ end
26
+
14
27
  describe '#emit_point' do
15
28
  it 'passes data' do
16
29
  @dogmock.emit_point('metric.name', 0, host: 'myhost')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogapi
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.30'
4
+ version: 1.31.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: 2018-06-05 00:00:00.000000000 Z
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -133,6 +133,7 @@ files:
133
133
  - spec/integration/tag_spec.rb
134
134
  - spec/integration/user_spec.rb
135
135
  - spec/spec_helper.rb
136
+ - spec/unit/capistrano_spec.rb
136
137
  - spec/unit/common_spec.rb
137
138
  - spec/unit/facade_spec.rb
138
139
  homepage: http://datadoghq.com/
@@ -183,5 +184,6 @@ test_files:
183
184
  - spec/integration/tag_spec.rb
184
185
  - spec/integration/user_spec.rb
185
186
  - spec/spec_helper.rb
187
+ - spec/unit/capistrano_spec.rb
186
188
  - spec/unit/common_spec.rb
187
189
  - spec/unit/facade_spec.rb