Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MA-557] Add support for new Monitor.can_delete endpoint. #195

Merged
merged 4 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 35 additions & 53 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-10-01 12:52:09 +0200 using RuboCop version 0.49.1.
# on 2019-11-25 14:34:01 -0500 using RuboCop version 0.49.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -51,14 +51,14 @@ Layout/EmptyLines:
- 'lib/capistrano/datadog/v2.rb'
- 'lib/dogapi/facade.rb'

# Offense count: 63
# Offense count: 73
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundClassBody:
Enabled: false

# Offense count: 1
# Offense count: 4
# Cop supports --auto-correct.
Layout/EmptyLinesAroundMethodBody:
Exclude:
Expand Down Expand Up @@ -120,7 +120,7 @@ Layout/SpaceAfterComma:
Exclude:
- 'examples/custom_metric.rb'

# Offense count: 75
# Offense count: 83
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Expand Down Expand Up @@ -201,44 +201,47 @@ Lint/UselessAssignment:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 11
# Offense count: 12
Metrics/AbcSize:
Max: 51

# Offense count: 18
# Offense count: 24
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 96
Exclude:
- 'spec/integration/monitor_spec.rb'
Max: 114

# Offense count: 2
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 105

# Offense count: 3
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 15
# Offense count: 17
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 34

# Offense count: 2
# Offense count: 4
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 7

# Offense count: 1
# Offense count: 2
Metrics/PerceivedComplexity:
Max: 9

# Offense count: 11
# Offense count: 13
Style/AccessorMethodName:
Exclude:
- 'lib/dogapi/facade.rb'
- 'lib/dogapi/v1/alert.rb'
- 'lib/dogapi/v1/dash.rb'
- 'lib/dogapi/v1/dashboard.rb'
- 'lib/dogapi/v1/embed.rb'
- 'lib/dogapi/v1/screenboard.rb'
- 'lib/dogapi/v1/dashboard.rb'
- 'lib/dogapi/v1/user.rb'

# Offense count: 1
Expand Down Expand Up @@ -283,7 +286,7 @@ Style/ClassMethods:
Exclude:
- 'lib/dogapi/common.rb'

# Offense count: 2
# Offense count: 3
Style/ClassVars:
Exclude:
- 'lib/dogapi/common.rb'
Expand All @@ -295,13 +298,12 @@ Style/ColonMethodCall:
- 'lib/capistrano/datadog.rb'
- 'lib/capistrano/datadog/v2.rb'

# Offense count: 2
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerBackticks.
# SupportedStyles: backticks, percent_x, mixed
Style/CommandLiteral:
Exclude:
- 'lib/capistrano/datadog.rb'
- 'lib/dogapi/common.rb'

# Offense count: 1
Expand All @@ -312,7 +314,7 @@ Style/ConditionalAssignment:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 20
# Offense count: 21
# Cop supports --auto-correct.
Style/DefWithParentheses:
Exclude:
Expand All @@ -322,36 +324,17 @@ Style/DefWithParentheses:
- 'lib/dogapi/v1/metric.rb'
- 'lib/dogapi/v1/screenboard.rb'

# Offense count: 21
# Offense count: 23
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/capistrano/datadog.rb'
- 'lib/capistrano/datadog/v2.rb'
- 'lib/capistrano/datadog/v3.rb'
- 'lib/dogapi/common.rb'
- 'lib/dogapi/v1/alert.rb'
- 'lib/dogapi/v1/comment.rb'
- 'lib/dogapi/v1/dash.rb'
- 'lib/dogapi/v1/metadata.rb'
- 'lib/dogapi/v1/monitor.rb'
- 'lib/dogapi/v1/screenboard.rb'
- 'lib/dogapi/v1/search.rb'
- 'lib/dogapi/v1/service_check.rb'
- 'lib/dogapi/v1/snapshot.rb'
- 'lib/dogapi/v1/user.rb'
- 'lib/dogapi/v1/integration.rb'
- 'lib/dogapi/v1/usage.rb'
- 'lib/dogapi/v1/metric.rb'
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/EmptyLiteral:
Exclude:
- 'lib/dogapi/v1/metric.rb'

# Offense count: 2
# Offense count: 3
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
Expand Down Expand Up @@ -399,7 +382,7 @@ Style/LineEndConcatenation:
Exclude:
- 'dogapi.gemspec'

# Offense count: 15
# Offense count: 18
# Cop supports --auto-correct.
Style/MethodCallWithoutArgsParentheses:
Exclude:
Expand All @@ -414,7 +397,7 @@ Style/MultilineIfThen:
Exclude:
- 'lib/capistrano/datadog.rb'

# Offense count: 21
# Offense count: 29
# Cop supports --auto-correct.
Style/MutableConstant:
Enabled: false
Expand All @@ -434,12 +417,11 @@ Style/Not:
Exclude:
- 'lib/dogapi/v1/metric.rb'

# Offense count: 5
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'lib/capistrano/datadog.rb'
- 'lib/dogapi/common.rb'
- 'spec/integration/event_spec.rb'
- 'spec/integration/monitor_spec.rb'
Expand All @@ -452,15 +434,14 @@ Style/PreferredHashMethods:
Exclude:
- 'lib/dogapi/common.rb'

# Offense count: 3
# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'lib/capistrano/datadog.rb'
- 'lib/dogapi/common.rb'
- 'lib/dogapi/v1/metric.rb'

# Offense count: 2
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Expand Down Expand Up @@ -497,7 +478,7 @@ Style/SpecialGlobalVars:
Exclude:
- 'dogapi.gemspec'

# Offense count: 22
# Offense count: 25
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand All @@ -509,8 +490,9 @@ Style/StringLiterals:
- 'examples/Capfile'
- 'examples/custom_event.rb'
- 'lib/dogapi/event.rb'
- 'lib/dogapi/v1/monitor.rb'

# Offense count: 10
# Offense count: 9
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Expand All @@ -526,11 +508,11 @@ Style/TrailingCommaInLiteral:

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, MinSize, WordRegex.
# Configuration parameters: SupportedStyles, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
Exclude:
- 'examples/custom_event.rb'
EnforcedStyle: percent
MinSize: 3

# Offense count: 1
# Cop supports --auto-correct.
Expand Down
4 changes: 4 additions & 0 deletions lib/dogapi/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ def get_monitor(monitor_id, options= {})
@monitor_svc.get_monitor(monitor_id, options)
end

def can_delete_monitors(monitor_ids)
@monitor_svc.can_delete_monitors(monitor_ids)
end

def delete_monitor(monitor_id)
@monitor_svc.delete_monitor(monitor_id)
end
Expand Down
13 changes: 11 additions & 2 deletions lib/dogapi/v1/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

module Dogapi
class V1 # for namespacing

class MonitorService < Dogapi::APIService

API_VERSION = 'v1'

def monitor(type, query, options = {})
Expand Down Expand Up @@ -42,6 +40,17 @@ def get_monitor(monitor_id, options = {})
request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", extra_params, nil, false)
end

def can_delete_monitors(monitor_ids)
extra_params =
if monitor_ids.respond_to?(:join)
{ "monitor_ids" => monitor_ids.join(",") }
else
{ "monitor_ids" => monitor_ids }
end

request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/can_delete", extra_params, nil, false)
end

def delete_monitor(monitor_id)
request(Net::HTTP::Delete, "/api/#{API_VERSION}/monitor/#{monitor_id}", nil, nil, false)
end
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
:get, "/monitor/#{MONITOR_ID}", group_states: %w(custom all)
end

describe '#can_delete_monitors' do
context 'with one id' do
it_behaves_like 'an api method',
:can_delete_monitors, [MONITOR_ID],
:get, '/monitor/can_delete'
end

context 'with multiple ids' do
it_behaves_like 'an api method',
:can_delete_monitors, [[MONITOR_ID, MONITOR_ID + 1, MONITOR_ID + 2]],
:get, '/monitor/can_delete'
end
end

describe '#delete_monitor' do
it_behaves_like 'an api method',
:delete_monitor, [MONITOR_ID],
Expand Down