dogapi 1.35.0 → 1.36.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 +5 -5
- data/.rubocop.yml +2 -0
- data/.rubocop_todo.yml +4 -0
- data/CHANGELOG.md +12 -0
- data/lib/dogapi/common.rb +0 -1
- data/lib/dogapi/facade.rb +96 -0
- data/lib/dogapi/v1.rb +1 -0
- data/lib/dogapi/v1/hosts.rb +1 -1
- data/lib/dogapi/v1/metric.rb +8 -1
- data/lib/dogapi/v1/monitor.rb +11 -1
- data/lib/dogapi/v1/usage.rb +95 -0
- data/lib/dogapi/v2.rb +1 -0
- data/lib/dogapi/v2/dashboard_list.rb +68 -0
- data/lib/dogapi/version.rb +1 -1
- data/spec/integration/dashboard_list_spec.rb +45 -1
- data/spec/integration/metric_spec.rb +7 -0
- data/spec/integration/monitor_spec.rb +7 -0
- data/spec/integration/usage_spec.rb +44 -0
- data/spec/spec_helper.rb +71 -5
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c534abc672555cbdf8ae3e4ad066a06bc6d066b
|
4
|
+
data.tar.gz: 349b0b8721a13b3bbe97d4f3183dc739a259a4d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b23eaa485025ad841b5a74683c85009fc3eca097b2681ae9045af8a146adc1f6b881c49d46919f40fe54ff691d671b162928b07eab83666ccad1f5c23fea593e
|
7
|
+
data.tar.gz: a8d31cf15e3f1d61e6fc0da448994b57fae3d5f6a6846b3713bbb95ced32890da0af5f05a281040cfccc75015adb68921679b7a1769ec8cefb9570b3c2696738
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -209,6 +209,8 @@ Metrics/AbcSize:
|
|
209
209
|
# Configuration parameters: CountComments, ExcludedMethods.
|
210
210
|
Metrics/BlockLength:
|
211
211
|
Max: 96
|
212
|
+
Exclude:
|
213
|
+
- 'spec/integration/monitor_spec.rb'
|
212
214
|
|
213
215
|
# Offense count: 2
|
214
216
|
Metrics/CyclomaticComplexity:
|
@@ -340,6 +342,8 @@ Style/Documentation:
|
|
340
342
|
- 'lib/dogapi/v1/snapshot.rb'
|
341
343
|
- 'lib/dogapi/v1/user.rb'
|
342
344
|
- 'lib/dogapi/v1/integration.rb'
|
345
|
+
- 'lib/dogapi/v1/usage.rb'
|
346
|
+
- 'lib/dogapi/v1/metric.rb'
|
343
347
|
|
344
348
|
# Offense count: 1
|
345
349
|
# Cop supports --auto-correct.
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 1.36.0 / 2019-06-05
|
4
|
+
|
5
|
+
* [BUGFIX] Pass the options as params to request, not body content. See [#157][], thanks [@wonko][]
|
6
|
+
* [FEATURE] Add support for dashboard list API v2. See [#174][]
|
7
|
+
* [IMPROVEMENT] Add `get_active_metrics` and `resolve_monitors` methods for missing api endpoints. See [#172][]
|
8
|
+
* [IMPROVEMENT] Add methods for missing hourly usage api endpoints. See [#173][]
|
9
|
+
|
3
10
|
## 1.35.0 / 2019-03-21
|
4
11
|
|
5
12
|
* [FEATURE] Add get_all_boards and support for 'free' layout. See [#171][].
|
@@ -227,6 +234,7 @@ This is the last release compatible with Ruby 1.8. ([EOL 2013-06-30](https://www
|
|
227
234
|
[#147]: https://github.com/DataDog/dogapi-rb/issues/147
|
228
235
|
[#151]: https://github.com/DataDog/dogapi-rb/issues/151
|
229
236
|
[#152]: https://github.com/DataDog/dogapi-rb/issues/152
|
237
|
+
[#157]: https://github.com/DataDog/dogapi-rb/issues/157
|
230
238
|
[#159]: https://github.com/DataDog/dogapi-rb/issues/159
|
231
239
|
[#160]: https://github.com/DataDog/dogapi-rb/issues/160
|
232
240
|
[#162]: https://github.com/DataDog/dogapi-rb/issues/162
|
@@ -235,6 +243,9 @@ This is the last release compatible with Ruby 1.8. ([EOL 2013-06-30](https://www
|
|
235
243
|
[#167]: https://github.com/DataDog/dogapi-rb/issues/167
|
236
244
|
[#170]: https://github.com/DataDog/dogapi-rb/issues/170
|
237
245
|
[#171]: https://github.com/DataDog/dogapi-rb/issues/171
|
246
|
+
[#172]: https://github.com/DataDog/dogapi-rb/issues/172
|
247
|
+
[#173]: https://github.com/DataDog/dogapi-rb/issues/173
|
248
|
+
[#174]: https://github.com/DataDog/dogapi-rb/issues/174
|
238
249
|
[@ArjenSchwarz]: https://github.com/ArjenSchwarz
|
239
250
|
[@Kaixiang]: https://github.com/Kaixiang
|
240
251
|
[@TaylURRE]: https://github.com/TaylURRE
|
@@ -257,4 +268,5 @@ This is the last release compatible with Ruby 1.8. ([EOL 2013-06-30](https://www
|
|
257
268
|
[@rmoriz]: https://github.com/rmoriz
|
258
269
|
[@treeder]: https://github.com/treeder
|
259
270
|
[@winebarrel]: https://github.com/winebarrel
|
271
|
+
[@wonko]: https://github.com/wonko
|
260
272
|
[@yyuu]: https://github.com/yyuu
|
data/lib/dogapi/common.rb
CHANGED
data/lib/dogapi/facade.rb
CHANGED
@@ -1,8 +1,51 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'dogapi/v1'
|
3
|
+
require 'dogapi/v2'
|
3
4
|
|
4
5
|
module Dogapi
|
5
6
|
|
7
|
+
# A simple DogAPI client supporting the version 2.
|
8
|
+
#
|
9
|
+
# See Dogapi::V2 for the thick underlying clients
|
10
|
+
class ClientV2
|
11
|
+
attr_accessor :datadog_host
|
12
|
+
def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil, endpoint=nil)
|
13
|
+
|
14
|
+
if api_key
|
15
|
+
@api_key = api_key
|
16
|
+
else
|
17
|
+
raise 'Please provide an API key to submit your data'
|
18
|
+
end
|
19
|
+
|
20
|
+
@application_key = application_key
|
21
|
+
@datadog_host = endpoint || Dogapi.find_datadog_host()
|
22
|
+
@host = host || Dogapi.find_localhost()
|
23
|
+
@device = device
|
24
|
+
|
25
|
+
@dashboard_list_service_v2 = Dogapi::V2::DashboardListService.new(
|
26
|
+
@api_key, @application_key, silent, timeout, @datadog_host
|
27
|
+
)
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_items_to_dashboard_list(dashboard_list_id, dashboards)
|
32
|
+
@dashboard_list_service_v2.add_items(dashboard_list_id, dashboards)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_items_of_dashboard_list(dashboard_list_id, dashboards)
|
36
|
+
@dashboard_list_service_v2.update_items(dashboard_list_id, dashboards)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete_items_from_dashboard_list(dashboard_list_id, dashboards)
|
40
|
+
@dashboard_list_service_v2.delete_items(dashboard_list_id, dashboards)
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_items_of_dashboard_list(dashboard_list_id)
|
44
|
+
@dashboard_list_service_v2.get_items(dashboard_list_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
6
49
|
# A simple DogAPI client
|
7
50
|
#
|
8
51
|
# See Dogapi::V1 for the thick underlying clients
|
@@ -13,6 +56,8 @@ module Dogapi
|
|
13
56
|
# documentation, here[https://github.com/DataDog/dogapi/wiki].
|
14
57
|
class Client # rubocop:disable Metrics/ClassLength
|
15
58
|
attr_accessor :datadog_host
|
59
|
+
attr_accessor :v2
|
60
|
+
# Support for API version 2.
|
16
61
|
|
17
62
|
def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, timeout=nil, endpoint=nil)
|
18
63
|
|
@@ -49,6 +94,11 @@ module Dogapi
|
|
49
94
|
@legacy_event_svc = Dogapi::EventService.new(@datadog_host)
|
50
95
|
@hosts_svc = Dogapi::V1::HostsService.new(@api_key, @application_key, silent, timeout, @datadog_host)
|
51
96
|
@integration_svc = Dogapi::V1::IntegrationService.new(@api_key, @application_key, silent, timeout, @datadog_host)
|
97
|
+
@usage_svc = Dogapi::V1::UsageService.new(@api_key, @application_key, silent, timeout, @datadog_host)
|
98
|
+
|
99
|
+
# Support for Dashboard List API v2.
|
100
|
+
@v2 = Dogapi::ClientV2.new(@api_key, @application_key, true, true, @datadog_host)
|
101
|
+
|
52
102
|
end
|
53
103
|
|
54
104
|
#
|
@@ -118,6 +168,13 @@ module Dogapi
|
|
118
168
|
end
|
119
169
|
end
|
120
170
|
|
171
|
+
# Get a list of active metrics since a given time
|
172
|
+
# +from+ The seconds since the unix epoch <tt>[Time, Integer]</tt>
|
173
|
+
#
|
174
|
+
def get_active_metrics(from)
|
175
|
+
@metric_svc.get_active_metrics(from)
|
176
|
+
end
|
177
|
+
|
121
178
|
#
|
122
179
|
# EVENTS
|
123
180
|
|
@@ -507,6 +564,10 @@ module Dogapi
|
|
507
564
|
@monitor_svc.unmute_monitor(monitor_id, options)
|
508
565
|
end
|
509
566
|
|
567
|
+
def resolve_monitors(monitor_groups = [], options = {}, version = nil)
|
568
|
+
@monitor_svc.resolve_monitors(monitor_groups, options, version)
|
569
|
+
end
|
570
|
+
|
510
571
|
def search_monitors(options = {})
|
511
572
|
@monitor_svc.search_monitors(options)
|
512
573
|
end
|
@@ -621,6 +682,41 @@ module Dogapi
|
|
621
682
|
@integration_svc.delete_integration(source_type_name)
|
622
683
|
end
|
623
684
|
|
685
|
+
#
|
686
|
+
# USAGE
|
687
|
+
#
|
688
|
+
|
689
|
+
# Get hourly usage information for different datadog service
|
690
|
+
# Usage data is delayed by up to 72 hours from when it was incurred. It is retained for the past 15 months.#
|
691
|
+
# format of dates is ISO-8601 UTC YYYY-MM-DDThh
|
692
|
+
# ex:
|
693
|
+
# require 'time'
|
694
|
+
# Time.now.utc.strftime('%Y-%m-%dT%H')
|
695
|
+
# => "2019-05-05T13"
|
696
|
+
def get_hosts_usage(start_hr, end_hr = nil)
|
697
|
+
@usage_svc.get_hosts_usage(start_hr, end_hr)
|
698
|
+
end
|
699
|
+
|
700
|
+
def get_logs_usage(start_hr, end_hr = nil)
|
701
|
+
@usage_svc.get_logs_usage(start_hr, end_hr)
|
702
|
+
end
|
703
|
+
|
704
|
+
def get_custom_metrics_usage(start_hr, end_hr = nil)
|
705
|
+
@usage_svc.get_custom_metrics_usage(start_hr, end_hr)
|
706
|
+
end
|
707
|
+
|
708
|
+
def get_traces_usage(start_hr, end_hr = nil)
|
709
|
+
@usage_svc.get_traces_usage(start_hr, end_hr)
|
710
|
+
end
|
711
|
+
|
712
|
+
def get_synthetics_usage(start_hr, end_hr = nil)
|
713
|
+
@usage_svc.get_synthetics_usage(start_hr, end_hr)
|
714
|
+
end
|
715
|
+
|
716
|
+
def get_fargate_usage(start_hr, end_hr = nil)
|
717
|
+
@usage_svc.get_fargate_usage(start_hr, end_hr)
|
718
|
+
end
|
719
|
+
|
624
720
|
private
|
625
721
|
|
626
722
|
def override_scope(options= {})
|
data/lib/dogapi/v1.rb
CHANGED
data/lib/dogapi/v1/hosts.rb
CHANGED
data/lib/dogapi/v1/metric.rb
CHANGED
@@ -83,7 +83,14 @@ module Dogapi
|
|
83
83
|
suppress_error_if_silent e
|
84
84
|
end
|
85
85
|
end
|
86
|
-
end
|
87
86
|
|
87
|
+
def get_active_metrics(from)
|
88
|
+
params = {
|
89
|
+
from: from.to_i
|
90
|
+
}
|
91
|
+
|
92
|
+
request(Net::HTTP::Get, '/api/' + API_VERSION + '/metrics', params, nil, false)
|
93
|
+
end
|
94
|
+
end
|
88
95
|
end
|
89
96
|
end
|
data/lib/dogapi/v1/monitor.rb
CHANGED
@@ -83,6 +83,17 @@ module Dogapi
|
|
83
83
|
request(Net::HTTP::Post, "/api/#{API_VERSION}/monitor/#{monitor_id}/unmute", nil, options, true)
|
84
84
|
end
|
85
85
|
|
86
|
+
def resolve_monitors(monitor_groups = [], options = {}, version = nil)
|
87
|
+
body = {
|
88
|
+
'resolve' => monitor_groups
|
89
|
+
}.merge options
|
90
|
+
|
91
|
+
# Currently not part of v1 at this time but adding future compatibility option
|
92
|
+
endpoint = version.nil? ? '/api/monitor/bulk_resolve' : "/api/#{version}/monitor/bulk_resolve"
|
93
|
+
|
94
|
+
request(Net::HTTP::Post, endpoint, nil, body, true)
|
95
|
+
end
|
96
|
+
|
86
97
|
def search_monitors(options = {})
|
87
98
|
request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/search", options, nil, false)
|
88
99
|
end
|
@@ -133,6 +144,5 @@ module Dogapi
|
|
133
144
|
request(Net::HTTP::Post, "/api/#{API_VERSION}/host/#{hostname}/unmute", nil, {}, true)
|
134
145
|
end
|
135
146
|
end
|
136
|
-
|
137
147
|
end
|
138
148
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'dogapi'
|
2
|
+
|
3
|
+
module Dogapi
|
4
|
+
class V1 # for namespacing
|
5
|
+
|
6
|
+
class UsageService < Dogapi::APIService
|
7
|
+
|
8
|
+
API_VERSION = 'v1'
|
9
|
+
|
10
|
+
# Retrieve hourly host usage information
|
11
|
+
#
|
12
|
+
# :start_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, for usage beginning at this hour
|
13
|
+
# :end_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, default start_hr+1d, for usage ending BEFORE this hour
|
14
|
+
def get_hosts_usage(start_hr, end_hr = nil)
|
15
|
+
params = {
|
16
|
+
start_hr: start_hr
|
17
|
+
}
|
18
|
+
|
19
|
+
params['end_hr'] = end_hr if end_hr
|
20
|
+
|
21
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/usage/hosts", params, nil, false)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Retrieve hourly logs usage information
|
25
|
+
#
|
26
|
+
# :start_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, for usage beginning at this hour
|
27
|
+
# :end_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, default start_hr+1d, for usage ending BEFORE this hour
|
28
|
+
def get_logs_usage(start_hr, end_hr = nil)
|
29
|
+
params = {
|
30
|
+
start_hr: start_hr
|
31
|
+
}
|
32
|
+
|
33
|
+
params['end_hr'] = end_hr if end_hr
|
34
|
+
|
35
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/usage/logs", params, nil, false)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Retrieve hourly custom metrics usage information
|
39
|
+
#
|
40
|
+
# :start_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, for usage beginning at this hour
|
41
|
+
# :end_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, default start_hr+1d, for usage ending BEFORE this hour
|
42
|
+
def get_custom_metrics_usage(start_hr, end_hr = nil)
|
43
|
+
params = {
|
44
|
+
start_hr: start_hr
|
45
|
+
}
|
46
|
+
|
47
|
+
params['end_hr'] = end_hr if end_hr
|
48
|
+
|
49
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/usage/timeseries", params, nil, false)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Retrieve hourly trace search usage information
|
53
|
+
#
|
54
|
+
# :start_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, for usage beginning at this hour
|
55
|
+
# :end_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, default start_hr+1d, for usage ending BEFORE this hour
|
56
|
+
def get_traces_usage(start_hr, end_hr = nil)
|
57
|
+
params = {
|
58
|
+
start_hr: start_hr
|
59
|
+
}
|
60
|
+
|
61
|
+
params['end_hr'] = end_hr if end_hr
|
62
|
+
|
63
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/usage/traces", params, nil, false)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Retrieve hourly synthetics usage information
|
67
|
+
#
|
68
|
+
# :start_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, for usage beginning at this hour
|
69
|
+
# :end_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, default start_hr+1d, for usage ending BEFORE this hour
|
70
|
+
def get_synthetics_usage(start_hr, end_hr = nil)
|
71
|
+
params = {
|
72
|
+
start_hr: start_hr
|
73
|
+
}
|
74
|
+
|
75
|
+
params['end_hr'] = end_hr if end_hr
|
76
|
+
|
77
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/usage/synthetics", params, nil, false)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Retrieve hourly fargate usage information
|
81
|
+
#
|
82
|
+
# :start_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, for usage beginning at this hour
|
83
|
+
# :end_hr => String: Datetime ISO-8601 UTC YYYY-MM-DDThh, default start_hr+1d, for usage ending BEFORE this hour
|
84
|
+
def get_fargate_usage(start_hr, end_hr = nil)
|
85
|
+
params = {
|
86
|
+
start_hr: start_hr
|
87
|
+
}
|
88
|
+
|
89
|
+
params['end_hr'] = end_hr if end_hr
|
90
|
+
|
91
|
+
request(Net::HTTP::Get, "/api/#{API_VERSION}/usage/fargate", params, nil, false)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/dogapi/v2.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'dogapi/v2/dashboard_list'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'dogapi'
|
2
|
+
|
3
|
+
module Dogapi
|
4
|
+
class V2 # for namespacing
|
5
|
+
|
6
|
+
# Dashboard List API
|
7
|
+
class DashboardListService < Dogapi::APIService
|
8
|
+
|
9
|
+
API_VERSION = 'v2'
|
10
|
+
RESOURCE_NAME = 'dashboard/lists/manual'
|
11
|
+
SUB_RESOURCE_NAME = 'dashboards'
|
12
|
+
|
13
|
+
def get_items(resource_id)
|
14
|
+
request(
|
15
|
+
Net::HTTP::Get,
|
16
|
+
"/api/#{API_VERSION}/#{RESOURCE_NAME}/#{resource_id}/#{SUB_RESOURCE_NAME}",
|
17
|
+
nil,
|
18
|
+
nil,
|
19
|
+
false
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_items(resource_id, dashboards)
|
24
|
+
body = {
|
25
|
+
dashboards: dashboards
|
26
|
+
}
|
27
|
+
|
28
|
+
request(
|
29
|
+
Net::HTTP::Post,
|
30
|
+
"/api/#{API_VERSION}/#{RESOURCE_NAME}/#{resource_id}/#{SUB_RESOURCE_NAME}",
|
31
|
+
nil,
|
32
|
+
body,
|
33
|
+
true
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_items(resource_id, dashboards)
|
38
|
+
body = {
|
39
|
+
dashboards: dashboards
|
40
|
+
}
|
41
|
+
|
42
|
+
request(
|
43
|
+
Net::HTTP::Put,
|
44
|
+
"/api/#{API_VERSION}/#{RESOURCE_NAME}/#{resource_id}/#{SUB_RESOURCE_NAME}",
|
45
|
+
nil,
|
46
|
+
body,
|
47
|
+
true
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete_items(resource_id, dashboards)
|
52
|
+
body = {
|
53
|
+
dashboards: dashboards
|
54
|
+
}
|
55
|
+
|
56
|
+
request(
|
57
|
+
Net::HTTP::Delete,
|
58
|
+
"/api/#{API_VERSION}/#{RESOURCE_NAME}/#{resource_id}/#{SUB_RESOURCE_NAME}",
|
59
|
+
nil,
|
60
|
+
body,
|
61
|
+
true
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/dogapi/version.rb
CHANGED
@@ -6,7 +6,6 @@ describe Dogapi::Client do
|
|
6
6
|
|
7
7
|
DASHBOARD_LIST_ID = 1_234_567
|
8
8
|
DASHBOARD_LIST_NAME = 'My new dashboard list'.freeze
|
9
|
-
|
10
9
|
DASHBOARDS = [
|
11
10
|
{
|
12
11
|
'type' => 'custom_timeboard',
|
@@ -83,3 +82,48 @@ describe Dogapi::Client do
|
|
83
82
|
:get, "/#{RESOURCE_NAME}/#{DASHBOARD_LIST_ID}/#{SUB_RESOURCE_NAME}"
|
84
83
|
end
|
85
84
|
end
|
85
|
+
|
86
|
+
describe Dogapi::ClientV2 do
|
87
|
+
RESOURCE_NAME = 'dashboard/lists/manual'.freeze
|
88
|
+
SUB_RESOURCE_NAME = 'dashboards'.freeze
|
89
|
+
|
90
|
+
DASHBOARD_LIST_ID = 1_234_567
|
91
|
+
DASHBOARD_LIST_NAME = 'My new dashboard list'.freeze
|
92
|
+
DASHBOARDS = [
|
93
|
+
{
|
94
|
+
'type' => 'custom_timeboard',
|
95
|
+
'id' => 1234
|
96
|
+
},
|
97
|
+
{
|
98
|
+
'type' => 'custom_screenboard',
|
99
|
+
'id' => 1234
|
100
|
+
}
|
101
|
+
].freeze
|
102
|
+
|
103
|
+
describe '#add_items_to_dashboard_list' do
|
104
|
+
it_behaves_like 'an api v2 method',
|
105
|
+
:add_items_to_dashboard_list, [DASHBOARD_LIST_ID] + [DASHBOARDS],
|
106
|
+
:post, "/#{RESOURCE_NAME}/#{DASHBOARD_LIST_ID}/#{SUB_RESOURCE_NAME}",
|
107
|
+
DASHBOARD_LIST_WITH_DASHES_BODY
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#update_items_of_dashboard_list' do
|
111
|
+
it_behaves_like 'an api v2 method',
|
112
|
+
:update_items_of_dashboard_list, [DASHBOARD_LIST_ID] + [DASHBOARDS],
|
113
|
+
:put, "/#{RESOURCE_NAME}/#{DASHBOARD_LIST_ID}/#{SUB_RESOURCE_NAME}",
|
114
|
+
DASHBOARD_LIST_WITH_DASHES_BODY
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#delete_items_from_dashboard_list' do
|
118
|
+
it_behaves_like 'an api v2 method',
|
119
|
+
:delete_items_from_dashboard_list, [DASHBOARD_LIST_ID] + [DASHBOARDS],
|
120
|
+
:delete, "/#{RESOURCE_NAME}/#{DASHBOARD_LIST_ID}/#{SUB_RESOURCE_NAME}",
|
121
|
+
DASHBOARD_LIST_WITH_DASHES_BODY
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#get_items_of_dashboard_list' do
|
125
|
+
it_behaves_like 'an api v2 method',
|
126
|
+
:get_items_of_dashboard_list, [DASHBOARD_LIST_ID],
|
127
|
+
:get, "/#{RESOURCE_NAME}/#{DASHBOARD_LIST_ID}/#{SUB_RESOURCE_NAME}"
|
128
|
+
end
|
129
|
+
end
|
@@ -34,6 +34,7 @@ describe Dogapi::Client do
|
|
34
34
|
}.freeze
|
35
35
|
|
36
36
|
METRIC_PARAMS = { query: METRIC_QUERY, from: FROM.to_i, to: TO.to_i }.freeze
|
37
|
+
ACTIVE_METRICS_PARAMS = { from: FROM.to_i }.freeze
|
37
38
|
|
38
39
|
describe '#emit_point' do
|
39
40
|
it 'queries the api' do
|
@@ -93,4 +94,10 @@ describe Dogapi::Client do
|
|
93
94
|
)
|
94
95
|
end
|
95
96
|
end
|
97
|
+
|
98
|
+
describe '#get_active_metrics' do
|
99
|
+
it_behaves_like 'an api method with params',
|
100
|
+
:get_active_metrics, [],
|
101
|
+
:get, '/metrics', ACTIVE_METRICS_PARAMS
|
102
|
+
end
|
96
103
|
end
|
@@ -7,6 +7,7 @@ describe Dogapi::Client do
|
|
7
7
|
DOWNTIME_SCOPE = 'host:vagrant-ubuntu-trusty-64'.freeze
|
8
8
|
DOWNTIME_ID = 424_242_424_242
|
9
9
|
MUTE_HOSTNAME = 'vagrant-ubuntu-trusty-32'.freeze
|
10
|
+
MONITOR_GROUPS = [{ 'check_a' => 'group_x' }, { 'check_a' => 'group_y' }, { 'check_b' => 'ALL_GROUPS' }].freeze
|
10
11
|
|
11
12
|
describe '#monitor' do
|
12
13
|
it_behaves_like 'an api method with options',
|
@@ -68,6 +69,12 @@ describe Dogapi::Client do
|
|
68
69
|
:post, "/monitor/#{MONITOR_ID}/unmute", {}
|
69
70
|
end
|
70
71
|
|
72
|
+
describe '#resolve_monitors' do
|
73
|
+
it_behaves_like 'an api method with options',
|
74
|
+
:resolve_monitors, [MONITOR_GROUPS],
|
75
|
+
:post, '/monitor/bulk_resolve', 'resolve' => MONITOR_GROUPS
|
76
|
+
end
|
77
|
+
|
71
78
|
describe '#schedule_downtime' do
|
72
79
|
it_behaves_like 'an api method with options',
|
73
80
|
:schedule_downtime, [DOWNTIME_SCOPE],
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Dogapi::Client do
|
4
|
+
USAGE_PARAMS = {
|
5
|
+
start_hr: (Time.now - (3600 * 24)).utc.strftime('%Y-%m-%dT%H'),
|
6
|
+
end_hr: Time.now.utc.strftime('%Y-%m-%dT%H')
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
describe '#get_hosts_usage' do
|
10
|
+
it_behaves_like 'an api method with params',
|
11
|
+
:get_hosts_usage, [],
|
12
|
+
:get, '/usage/hosts', USAGE_PARAMS
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#get_logs_usage' do
|
16
|
+
it_behaves_like 'an api method with params',
|
17
|
+
:get_logs_usage, [],
|
18
|
+
:get, '/usage/logs', USAGE_PARAMS
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#get_custom_metrics_usage' do
|
22
|
+
it_behaves_like 'an api method with params',
|
23
|
+
:get_custom_metrics_usage, [],
|
24
|
+
:get, '/usage/timeseries', USAGE_PARAMS
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#get_traces_usage' do
|
28
|
+
it_behaves_like 'an api method with params',
|
29
|
+
:get_traces_usage, [],
|
30
|
+
:get, '/usage/traces', USAGE_PARAMS
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#get_synthetics_usage' do
|
34
|
+
it_behaves_like 'an api method with params',
|
35
|
+
:get_synthetics_usage, [],
|
36
|
+
:get, '/usage/synthetics', USAGE_PARAMS
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#get_fargate_usage' do
|
40
|
+
it_behaves_like 'an api method with params',
|
41
|
+
:get_fargate_usage, [],
|
42
|
+
:get, '/usage/fargate', USAGE_PARAMS
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -20,18 +20,23 @@ module SpecDog
|
|
20
20
|
let(:api_key) { 'API_KEY' }
|
21
21
|
let(:app_key) { 'APP_KEY' }
|
22
22
|
let(:dog) { Dogapi::Client.new(api_key, app_key, 'data.dog', nil, false) }
|
23
|
+
let(:dog2) { Dogapi::ClientV2.new(api_key, app_key, 'data.dog', nil, false) }
|
23
24
|
let(:api_url) { "#{DATADOG_HOST}/api/v1" }
|
25
|
+
let(:old_api_url) { "#{DATADOG_HOST}/api" }
|
26
|
+
let(:api_v2_url) { "#{DATADOG_HOST}/api/v2" }
|
27
|
+
|
24
28
|
let(:default_query) { { api_key: api_key, application_key: app_key } }
|
25
29
|
|
26
30
|
shared_examples 'an api method' do |command, args, request, endpoint, body|
|
27
31
|
it 'queries the api' do
|
28
32
|
url = api_url + endpoint
|
29
|
-
|
33
|
+
old_url = old_api_url + endpoint
|
34
|
+
stub_request(request, /#{url}|#{old_url}/).to_return(body: '{}').then.to_raise(StandardError)
|
30
35
|
expect(dog.send(command, *args)).to eq ['200', {}]
|
31
36
|
|
32
37
|
body = MultiJson.dump(body) if body
|
33
38
|
|
34
|
-
expect(WebMock).to have_requested(request, url).with(
|
39
|
+
expect(WebMock).to have_requested(request, /#{url}|#{old_url}/).with(
|
35
40
|
query: default_query,
|
36
41
|
body: body
|
37
42
|
)
|
@@ -42,13 +47,14 @@ module SpecDog
|
|
42
47
|
include_examples 'an api method', command, args, request, endpoint, body
|
43
48
|
it 'queries the api with options' do
|
44
49
|
url = api_url + endpoint
|
50
|
+
old_url = old_api_url + endpoint
|
45
51
|
options = { 'zzz' => 'aaa' }
|
46
|
-
stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError)
|
52
|
+
stub_request(request, /#{url}|#{old_url}/).to_return(body: '{}').then.to_raise(StandardError)
|
47
53
|
expect(dog.send(command, *args, options)).to eq ['200', {}]
|
48
54
|
|
49
55
|
body = MultiJson.dump(body ? (body.merge options) : options)
|
50
56
|
|
51
|
-
expect(WebMock).to have_requested(request, url).with(
|
57
|
+
expect(WebMock).to have_requested(request, /#{url}|#{old_url}/).with(
|
52
58
|
query: default_query,
|
53
59
|
body: body
|
54
60
|
)
|
@@ -60,7 +66,6 @@ module SpecDog
|
|
60
66
|
url = api_url + endpoint
|
61
67
|
stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError)
|
62
68
|
expect(dog.send(command, *args, *params.values)).to eq ['200', {}]
|
63
|
-
|
64
69
|
params.each { |k, v| params[k] = v.join(',') if v.is_a? Array }
|
65
70
|
params = params.merge default_query
|
66
71
|
|
@@ -85,6 +90,67 @@ module SpecDog
|
|
85
90
|
)
|
86
91
|
end
|
87
92
|
end
|
93
|
+
|
94
|
+
# Support for new API version (v2)
|
95
|
+
|
96
|
+
shared_examples 'an api v2 method' do |command, args, request, endpoint, body|
|
97
|
+
it 'queries the api v2' do
|
98
|
+
url = api_v2_url + endpoint
|
99
|
+
stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError)
|
100
|
+
expect(dog2.send(command, *args)).to eq ['200', {}]
|
101
|
+
body = MultiJson.dump(body) if body
|
102
|
+
|
103
|
+
expect(WebMock).to have_requested(request, url).with(
|
104
|
+
query: default_query,
|
105
|
+
body: body
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
shared_examples 'an api v2 method with options' do |command, args, request, endpoint, body|
|
111
|
+
include_examples 'an api method', command, args, request, endpoint, body
|
112
|
+
it 'queries the api v2 with options' do
|
113
|
+
url = api_v2_url + endpoint
|
114
|
+
options = { 'zzz' => 'aaa' }
|
115
|
+
stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError)
|
116
|
+
expect(dog2.send(command, *args, options)).to eq ['200', {}]
|
117
|
+
body = MultiJson.dump(body ? (body.merge options) : options)
|
118
|
+
|
119
|
+
expect(WebMock).to have_requested(request, url).with(
|
120
|
+
query: default_query,
|
121
|
+
body: body
|
122
|
+
)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
shared_examples 'an api v2 method with params' do |command, args, request, endpoint, params|
|
127
|
+
it 'queries the api v2 with params' do
|
128
|
+
url = api_v2_url + endpoint
|
129
|
+
stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError)
|
130
|
+
expect(dog2.send(command, *args, *params.values)).to eq ['200', {}]
|
131
|
+
params.each { |k, v| params[k] = v.join(',') if v.is_a? Array }
|
132
|
+
params = params.merge default_query
|
133
|
+
|
134
|
+
expect(WebMock).to have_requested(request, url).with(
|
135
|
+
query: params
|
136
|
+
)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
shared_examples 'an api v2 method with optional params' do |command, args, request, endpoint, opt_params|
|
141
|
+
include_examples 'an api v2 method', command, args, request, endpoint
|
142
|
+
it 'queries the api v2 with optional params' do
|
143
|
+
url = api_v2_url + endpoint
|
144
|
+
stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError)
|
145
|
+
expect(dog2.send(command, *args, opt_params)).to eq ['200', {}]
|
146
|
+
opt_params.each { |k, v| opt_params[k] = v.join(',') if v.is_a? Array }
|
147
|
+
params = opt_params.merge default_query
|
148
|
+
|
149
|
+
expect(WebMock).to have_requested(request, url).with(
|
150
|
+
query: params
|
151
|
+
)
|
152
|
+
end
|
153
|
+
end
|
88
154
|
end
|
89
155
|
|
90
156
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
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.
|
4
|
+
version: 1.36.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: 2019-
|
11
|
+
date: 2019-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -116,7 +116,10 @@ files:
|
|
116
116
|
- lib/dogapi/v1/service_check.rb
|
117
117
|
- lib/dogapi/v1/snapshot.rb
|
118
118
|
- lib/dogapi/v1/tag.rb
|
119
|
+
- lib/dogapi/v1/usage.rb
|
119
120
|
- lib/dogapi/v1/user.rb
|
121
|
+
- lib/dogapi/v2.rb
|
122
|
+
- lib/dogapi/v2/dashboard_list.rb
|
120
123
|
- lib/dogapi/version.rb
|
121
124
|
- spec/integration/alert_spec.rb
|
122
125
|
- spec/integration/comment_spec.rb
|
@@ -135,6 +138,7 @@ files:
|
|
135
138
|
- spec/integration/service_check_spec.rb
|
136
139
|
- spec/integration/snapshot_spec.rb
|
137
140
|
- spec/integration/tag_spec.rb
|
141
|
+
- spec/integration/usage_spec.rb
|
138
142
|
- spec/integration/user_spec.rb
|
139
143
|
- spec/spec_helper.rb
|
140
144
|
- spec/unit/capistrano_spec.rb
|
@@ -169,7 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
173
|
- !ruby/object:Gem::Version
|
170
174
|
version: '0'
|
171
175
|
requirements: []
|
172
|
-
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.6.8
|
173
178
|
signing_key:
|
174
179
|
specification_version: 4
|
175
180
|
summary: Ruby bindings for Datadog's API
|
@@ -191,6 +196,7 @@ test_files:
|
|
191
196
|
- spec/integration/service_check_spec.rb
|
192
197
|
- spec/integration/snapshot_spec.rb
|
193
198
|
- spec/integration/tag_spec.rb
|
199
|
+
- spec/integration/usage_spec.rb
|
194
200
|
- spec/integration/user_spec.rb
|
195
201
|
- spec/spec_helper.rb
|
196
202
|
- spec/unit/capistrano_spec.rb
|