diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 22a1f2fe..ef1cc51c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-10-23 14:52:35 -0500 using RuboCop version 0.49.1. +# on 2018-10-01 12:52:09 +0200 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 @@ -51,14 +51,14 @@ Layout/EmptyLines: - 'lib/capistrano/datadog/v2.rb' - 'lib/dogapi/facade.rb' -# Offense count: 78 +# Offense count: 63 # 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: 4 +# Offense count: 1 # Cop supports --auto-correct. Layout/EmptyLinesAroundMethodBody: Exclude: @@ -85,20 +85,10 @@ Layout/ExtraSpacing: # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Layout/FirstParameterIndentation: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# Configuration parameters: SupportedStyles, IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_braces Layout/IndentHash: - Exclude: - - 'lib/dogapi/v1/event.rb' - - 'lib/dogapi/v1/service_level_objective.rb' + EnforcedStyle: consistent # Offense count: 1 # Cop supports --auto-correct. @@ -130,7 +120,7 @@ Layout/SpaceAfterComma: Exclude: - 'examples/custom_metric.rb' -# Offense count: 83 +# Offense count: 75 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: space, no_space @@ -157,29 +147,12 @@ Layout/SpaceAroundOperators: - 'examples/custom_metric.rb' - 'lib/dogapi/event.rb' -# Offense count: 8 -# Cop supports --auto-correct. -Layout/SpaceBeforeComma: - Exclude: - - 'lib/dogapi/facade.rb' - - 'lib/dogapi/v1/service_level_objective.rb' - -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Layout/SpaceBeforeFirstArg: Exclude: - 'lib/capistrano/datadog/v2.rb' - - 'lib/dogapi/v1/service_level_objective.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'spec/integration/service_level_objective_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -228,42 +201,44 @@ Lint/UselessAssignment: Exclude: - 'lib/capistrano/datadog.rb' -# Offense count: 13 +# Offense count: 11 Metrics/AbcSize: Max: 51 -# Offense count: 24 +# Offense count: 18 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: - Max: 102 + Max: 96 + Exclude: + - 'spec/integration/monitor_spec.rb' -# Offense count: 5 +# Offense count: 2 Metrics/CyclomaticComplexity: - Max: 11 + Max: 8 -# Offense count: 18 +# Offense count: 15 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 34 -# Offense count: 7 +# Offense count: 2 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: - Max: 11 + Max: 7 -# Offense count: 4 +# Offense count: 1 Metrics/PerceivedComplexity: - Max: 12 + Max: 9 -# Offense count: 13 +# Offense count: 11 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 @@ -308,7 +283,7 @@ Style/ClassMethods: Exclude: - 'lib/dogapi/common.rb' -# Offense count: 3 +# Offense count: 2 Style/ClassVars: Exclude: - 'lib/dogapi/common.rb' @@ -320,24 +295,24 @@ Style/ColonMethodCall: - 'lib/capistrano/datadog.rb' - 'lib/capistrano/datadog/v2.rb' -# Offense count: 1 +# Offense count: 2 # 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: 2 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Exclude: - 'lib/capistrano/datadog.rb' - - 'lib/dogapi/v1/service_level_objective.rb' -# Offense count: 21 +# Offense count: 20 # Cop supports --auto-correct. Style/DefWithParentheses: Exclude: @@ -347,9 +322,28 @@ Style/DefWithParentheses: - 'lib/dogapi/v1/metric.rb' - 'lib/dogapi/v1/screenboard.rb' -# Offense count: 23 +# Offense count: 21 Style/Documentation: - Enabled: false + 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' # Offense count: 1 # Cop supports --auto-correct. @@ -357,7 +351,7 @@ Style/EmptyLiteral: Exclude: - 'lib/dogapi/v1/metric.rb' -# Offense count: 3 +# Offense count: 2 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: @@ -405,7 +399,7 @@ Style/LineEndConcatenation: Exclude: - 'dogapi.gemspec' -# Offense count: 18 +# Offense count: 15 # Cop supports --auto-correct. Style/MethodCallWithoutArgsParentheses: Exclude: @@ -420,7 +414,7 @@ Style/MultilineIfThen: Exclude: - 'lib/capistrano/datadog.rb' -# Offense count: 30 +# Offense count: 21 # Cop supports --auto-correct. Style/MutableConstant: Enabled: false @@ -440,17 +434,12 @@ Style/Not: Exclude: - 'lib/dogapi/v1/metric.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Strict. -Style/NumericLiterals: - MinDigits: 8 - -# Offense count: 4 +# Offense count: 5 # 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' @@ -463,11 +452,12 @@ Style/PreferredHashMethods: Exclude: - 'lib/dogapi/common.rb' -# Offense count: 2 +# Offense count: 3 # Cop supports --auto-correct. Style/RedundantBegin: Exclude: - 'lib/capistrano/datadog.rb' + - 'lib/dogapi/common.rb' - 'lib/dogapi/v1/metric.rb' # Offense count: 2 @@ -507,7 +497,7 @@ Style/SpecialGlobalVars: Exclude: - 'dogapi.gemspec' -# Offense count: 23 +# Offense count: 22 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes @@ -519,7 +509,6 @@ Style/StringLiterals: - 'examples/Capfile' - 'examples/custom_event.rb' - 'lib/dogapi/event.rb' - - 'spec/integration/service_level_objective_spec.rb' # Offense count: 10 # Cop supports --auto-correct. @@ -537,11 +526,11 @@ Style/TrailingCommaInLiteral: # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, WordRegex. +# Configuration parameters: EnforcedStyle, SupportedStyles, MinSize, WordRegex. # SupportedStyles: percent, brackets Style/WordArray: - EnforcedStyle: percent - MinSize: 3 + Exclude: + - 'examples/custom_event.rb' # Offense count: 1 # Cop supports --auto-correct. diff --git a/lib/dogapi/facade.rb b/lib/dogapi/facade.rb index 6dc01b61..c5e412a7 100644 --- a/lib/dogapi/facade.rb +++ b/lib/dogapi/facade.rb @@ -95,8 +95,6 @@ def initialize(api_key, application_key=nil, host=nil, device=nil, silent=true, @hosts_svc = Dogapi::V1::HostsService.new(@api_key, @application_key, silent, timeout, @datadog_host) @integration_svc = Dogapi::V1::IntegrationService.new(@api_key, @application_key, silent, timeout, @datadog_host) @usage_svc = Dogapi::V1::UsageService.new(@api_key, @application_key, silent, timeout, @datadog_host) - @service_level_objective_svc = Dogapi::V1::ServiceLevelObjectiveService.new(@api_key, @application_key, silent, - timeout, @datadog_host) # Support for Dashboard List API v2. @v2 = Dogapi::ClientV2.new(@api_key, @application_key, true, true, @datadog_host) @@ -618,58 +616,6 @@ def unmute_host(hostname) @monitor_svc.unmute_host(hostname) end - # - # SERVICE LEVEL OBJECTIVES - # - - def create_service_level_objective(type: , name: , description: nil, tags: nil, thresholds: nil, numerator: nil, - denominator: nil, monitor_ids: nil, monitor_search: nil, groups: nil) - @service_level_objective_svc.create_service_level_objective(type: type, name: name, description: description, - tags: tags, thresholds: thresholds, - numerator: numerator, denominator: denominator, - monitor_ids: monitor_ids, - monitor_search: monitor_search, groups: groups) - end - - def update_service_level_objective(slo_id: , type: , name: nil, description: nil, tags: nil, thresholds: nil, - numerator: nil, denominator: nil, monitor_ids: nil, monitor_search: nil, - groups: nil) - @service_level_objective_svc.update_service_level_objective(slo_id: slo_id, type: type, name: name, - description: description, tags: tags, - thresholds: thresholds, numerator: numerator, - denominator: denominator, monitor_ids: monitor_ids, - monitor_search: monitor_search, groups: groups) - end - - def get_service_level_objective(slo_id) - @service_level_objective_svc.get_service_level_objective(slo_id) - end - - def get_service_level_objective_history(slo_id, from_ts, to_ts) - @service_level_objective_svc.get_service_level_objective_history(slo_id, from_ts, to_ts) - end - - def search_service_level_objective(slo_ids: nil, query: nil, offset: nil, limit: nil) - @service_level_objective_svc.search_service_level_objective(slo_ids: slo_ids, query: query, offset: offset, - limit: limit) - end - - def can_delete_service_level_objective(slo_ids) - @service_level_objective_svc.can_delete_service_level_objective(slo_ids) - end - - def delete_service_level_objective(slo_id) - @service_level_objective_svc.delete_service_level_objective(slo_id) - end - - def delete_many_service_level_objective(slo_ids) - @service_level_objective_svc.delete_many_service_level_objective(slo_ids) - end - - def delete_timeframes_service_level_objective(ops) - @service_level_objective_svc.delete_timeframes_service_level_objective(ops) - end - # # SERVICE CHECKS # diff --git a/lib/dogapi/v1.rb b/lib/dogapi/v1.rb index 50003b95..50fdcbf5 100644 --- a/lib/dogapi/v1.rb +++ b/lib/dogapi/v1.rb @@ -11,7 +11,6 @@ require 'dogapi/v1/screenboard' require 'dogapi/v1/search' require 'dogapi/v1/service_check' -require 'dogapi/v1/service_level_objective' require 'dogapi/v1/snapshot' require 'dogapi/v1/tag' require 'dogapi/v1/user' diff --git a/lib/dogapi/v1/service_level_objective.rb b/lib/dogapi/v1/service_level_objective.rb deleted file mode 100644 index 1d1a2ec7..00000000 --- a/lib/dogapi/v1/service_level_objective.rb +++ /dev/null @@ -1,117 +0,0 @@ -require 'dogapi' - -module Dogapi - class V1 # for namespacing - - # Implements Service Level Objectives endpoints - class ServiceLevelObjectiveService < Dogapi::APIService - - API_VERSION = 'v1' - - def create_service_level_objective(type: , name: , description: nil, tags: nil, thresholds: nil, - numerator: nil, denominator: nil, monitor_ids: nil, monitor_search: nil, - groups: nil) - body = { - type: type, - name: name, - thresholds: thresholds - } - if type == 'metric' - body[:query] = { - numerator: numerator, - denominator: denominator - } - else - body[:monitor_search] = monitor_search unless monitor_search.nil? - body[:monitor_ids] = monitor_ids unless monitor_ids.nil? - body[:groups] = groups unless groups.nil? - end - body[:tags] = tags unless tags.nil? - body[:description] = description unless description.nil? - - request(Net::HTTP::Post, "/api/#{API_VERSION}/slo", nil, body, true) - end - - def update_service_level_objective(slo_id: , type: , name: nil, description: nil, tags: nil, - thresholds: nil, numerator: nil, denominator: nil, monitor_ids: nil, - monitor_search: nil, groups: nil) - body = { - type: type - } - - body[:name] = name unless name.nil? - - body[:thresholds] = thresholds unless thresholds.nil? - - if type == 'metric' - if !numerator.nil? && !denominator.nil? - body[:query] = { - numerator: numerator, - denominator: denominator - } - end - else - body[:monitor_search] = monitor_search unless monitor_search.nil? - body[:monitor_ids] = monitor_ids unless monitor_ids.nil? - body[:groups] = groups unless groups.nil? - end - body[:tags] = tags unless tags.nil? - body[:description] = description unless description.nil? - - request(Net::HTTP::Put, "/api/#{API_VERSION}/slo/#{slo_id}", nil, body, true) - end - - def get_service_level_objective(slo_id) - request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/#{slo_id}", nil, nil, false) - end - - def search_service_level_objective(slo_ids: nil, query: nil, offset: nil, limit: nil) - params = {} - params[:offset] = offset unless offset.nil? - params[:limit] = limit unless limit.nil? - if !slo_ids.nil? - params[:ids] = slo_ids.join(',') - else - params[:query] = query - end - - request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/", params, nil, false) - end - - def delete_service_level_objective(slo_id) - request(Net::HTTP::Delete, "/api/#{API_VERSION}/slo/#{slo_id}", nil, nil, false) - end - - def delete_many_service_level_objective(slo_ids) - body = { - ids: slo_ids - } - request(Net::HTTP::Delete, "/api/#{API_VERSION}/slo/", nil, body, true) - end - - def delete_timeframes_service_level_objective(ops) - # ops is a hash of slo_id: [] to delete - request(Net::HTTP::Post, "/api/#{API_VERSION}/slo/bulk_delete", nil, ops, true) - end - - def get_service_level_objective_history(slo_id, from_ts, to_ts) - params = { - from_ts: from_ts, - to_ts: to_ts - } - request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/#{slo_id}/history", params, nil, false) - end - - def can_delete_service_level_objective(slo_ids) - params = {} - if slo_ids.is_a?Array - params[:ids] = slo_ids.join(',') - else - params[:ids] = slo_ids - end - request(Net::HTTP::Get, "/api/#{API_VERSION}/slo/can_delete", params, nil, false) - end - - end - end -end diff --git a/spec/integration/service_level_objective_spec.rb b/spec/integration/service_level_objective_spec.rb deleted file mode 100644 index 01da29fa..00000000 --- a/spec/integration/service_level_objective_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -require_relative '../spec_helper' - -describe Dogapi::Client do - SLO_ID = '42424242424242424242424242424242'.freeze - SLO_TYPE = 'metric'.freeze - SLO_NAME = 'test slo'.freeze - SLO_DESCRIPTION = 'test slo description'.freeze - SLO_QUERY_NUMERATOR = 'sum:test.metric.metric{type:good}.as_count()'.freeze - SLO_QUERY_DENOMINATOR = 'sum:test.metric.metric{*}.as_count()'.freeze - SLO_TAGS = ['type:test'].freeze - SLO_THRESHOLDS = [{ timeframe: '7d', target: 90 }, { timeframe: '30d', target: 95 }].freeze - - describe '#create_service_level_objective' do - it_behaves_like 'an api method with named args', - :create_service_level_objective, {type: SLO_TYPE, name: SLO_NAME, description: SLO_DESCRIPTION, - tags: SLO_TAGS, thresholds: SLO_THRESHOLDS, - numerator: SLO_QUERY_NUMERATOR, - denominator: SLO_QUERY_DENOMINATOR}, - :post, '/slo', 'type' => SLO_TYPE, 'name' => SLO_NAME, 'thresholds' => SLO_THRESHOLDS, - 'query' => { numerator: SLO_QUERY_NUMERATOR, denominator: SLO_QUERY_DENOMINATOR }, - 'tags' => SLO_TAGS, 'description' => SLO_DESCRIPTION - end - - describe '#update_service_level_objective' do - it_behaves_like 'an api method with named args', - :update_service_level_objective, {slo_id: SLO_ID, type: SLO_TYPE, name: SLO_NAME}, - :put, "/slo/#{SLO_ID}", 'type' => SLO_TYPE, 'name' => SLO_NAME - end - - describe '#get_service_level_objective' do - it_behaves_like 'an api method', - :get_service_level_objective, [SLO_ID], - :get, "/slo/#{SLO_ID}" - end - - describe '#get_service_level_objective_history' do - it_behaves_like 'an api method with params', - :get_service_level_objective_history, [SLO_ID], - :get, "/slo/#{SLO_ID}/history", 'from_ts' => 0, 'to_ts' => 1000000 - end - - describe '#can_delete_service_level_objective' do - it_behaves_like 'an api method with params', - :can_delete_service_level_objective, [], - :get, "/slo/can_delete", 'ids' => [SLO_ID] - end - - describe '#search_service_level_objective' do - it_behaves_like 'an api method with named args making params', - :search_service_level_objective, {slo_ids: [SLO_ID]}, - :get, '/slo/', 'ids' => SLO_ID - end - - describe '#delete_service_level_objective' do - it_behaves_like 'an api method', - :delete_service_level_objective, [SLO_ID], - :delete, "/slo/#{SLO_ID}" - end - - describe '#delete_many_service_level_objective' do - it_behaves_like 'an api method', - :delete_many_service_level_objective, [[SLO_ID]], - :delete, '/slo/', 'ids' => [SLO_ID] - end - - describe '#delete_timeframes_service_level_objective' do - it_behaves_like 'an api method', - :delete_timeframes_service_level_objective, [{ SLO_ID => ['7d'] }], - :post, '/slo/bulk_delete', SLO_ID => ['7d'] - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 586e905f..1e4c47b3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -42,22 +42,6 @@ module SpecDog end end - shared_examples 'an api method with named args' do |command, args, request, endpoint, body| - it 'queries the api' do - url = api_url + endpoint - old_url = old_api_url + endpoint - stub_request(request, /#{url}|#{old_url}/).to_return(body: '{}').then.to_raise(StandardError) - expect(dog.send(command, **args)).to eq ['200', {}] - - body = MultiJson.dump(body) if body - - expect(WebMock).to have_requested(request, /#{url}|#{old_url}/).with( - # ignore query: default_query -- here as in the test it's never properly included - body: body - ) - end - end - shared_examples 'an api method with options' do |command, args, request, endpoint, body| include_examples 'an api method', command, args, request, endpoint, body it 'queries the api with options' do @@ -89,20 +73,6 @@ module SpecDog end end - shared_examples 'an api method with named args making params' do |command, args, request, endpoint, params| - it 'queries the api with params' do - url = api_url + endpoint - stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError) - expect(dog.send(command, **args)).to eq ['200', {}] - params.each { |k, v| params[k] = v.join(',') if v.is_a? Array } - # hack/note: do not merge with default_query for this test case - - expect(WebMock).to have_requested(request, url).with( - query: params - ) - end - end - shared_examples 'an api method with optional params' do |command, args, request, endpoint, opt_params| include_examples 'an api method', command, args, request, endpoint it 'queries the api with optional params' do