From fb163ffc9898fb82144d6d8b59905a10e67b80bc Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 14 Jun 2018 11:49:27 -0400 Subject: [PATCH 1/3] Move CloudWatch to v2 of AWS SDK Use v2 of CloudWatch API - enables use of more standard options from the AWS mixin fixes #30 (includes rudimentary IT to test correct behavior with password types) --- lib/logstash/inputs/cloudwatch.rb | 9 ++++----- spec/inputs/cloudwatch_spec.rb | 3 ++- spec/integration/cloudwatch_spec.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 spec/integration/cloudwatch_spec.rb diff --git a/lib/logstash/inputs/cloudwatch.rb b/lib/logstash/inputs/cloudwatch.rb index 7c6459f..8f41c40 100644 --- a/lib/logstash/inputs/cloudwatch.rb +++ b/lib/logstash/inputs/cloudwatch.rb @@ -71,7 +71,7 @@ # class LogStash::Inputs::CloudWatch < LogStash::Inputs::Base - include LogStash::PluginMixins::AwsConfig + include LogStash::PluginMixins::AwsConfig::V2 config_name "cloudwatch" @@ -126,8 +126,6 @@ def aws_service_endpoint(region) end def register - AWS.config(:logger => @logger) - raise 'Interval needs to be higher than period' unless @interval >= @period raise 'Interval must be divisible by period' unless @interval % @period == 0 @@ -230,8 +228,9 @@ def clients @clients ||= Hash.new do |client_hash, namespace| namespace = namespace[4..-1] if namespace[0..3] == 'AWS/' namespace = 'EC2' if namespace == 'EBS' - cls = AWS.const_get(namespace) - client_hash[namespace] = cls::Client.new(aws_options_hash) + cls = Aws.const_get(namespace) + # TODO: Move logger configuration into mixin. + client_hash[namespace] = cls::Client.new(aws_options_hash.merge(:logger => @logger)) end end diff --git a/spec/inputs/cloudwatch_spec.rb b/spec/inputs/cloudwatch_spec.rb index b78309c..0d83388 100644 --- a/spec/inputs/cloudwatch_spec.rb +++ b/spec/inputs/cloudwatch_spec.rb @@ -12,7 +12,7 @@ let(:config) { { 'access_key_id' => '1234', - 'secret_access_key' => 'secret', + 'secret_access_key' => LogStash::Util::Password.new('secret'), 'namespace' => 'AWS/EC2', 'filters' => { 'instance-id' => 'i-12344321' }, 'region' => 'us-east-1' @@ -25,6 +25,7 @@ end end + context "EC2 events" do let(:config) { { diff --git a/spec/integration/cloudwatch_spec.rb b/spec/integration/cloudwatch_spec.rb new file mode 100644 index 0000000..371ef1b --- /dev/null +++ b/spec/integration/cloudwatch_spec.rb @@ -0,0 +1,26 @@ +require "logstash/devutils/rspec/spec_helper" +require "logstash/inputs/cloudwatch" +require "aws-sdk" + +describe LogStash::Inputs::CloudWatch, :integration => true do + + let(:settings) { { "access_key_id" => ENV['AWS_ACCESS_KEY_ID'], + "secret_access_key" => LogStash::Util::Password.new(ENV['AWS_SECRET_ACCESS_KEY']), + "region" => ENV["AWS_REGION"] || "us-east-1", + "namespace" => "AWS/S3", + 'filters' => { "BucketName" => "*"}, + 'metrics' => ["BucketSizeBytes","NumberOfObjects"] + + }} + + def metrics_for(settings) + cw = LogStash::Inputs::CloudWatch.new(settings) + cw.register + cw.send('metrics_for', settings['namespace']) + end + + # + it "should not raise a type error when using a password" do + expect{metrics_for(settings)}.not_to raise_error + end +end From e1fa4e61d13e75a2d7c22993a0abe920e2a0d56b Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 14 Jun 2018 12:06:25 -0400 Subject: [PATCH 2/3] Fix broken test --- spec/inputs/cloudwatch_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/inputs/cloudwatch_spec.rb b/spec/inputs/cloudwatch_spec.rb index 0d83388..dd97df7 100644 --- a/spec/inputs/cloudwatch_spec.rb +++ b/spec/inputs/cloudwatch_spec.rb @@ -4,7 +4,7 @@ describe LogStash::Inputs::CloudWatch do before do - AWS.stub! + Aws.config[:stub_responses] = true Thread.abort_on_exception = true end From 97fe1eea405d5371e30558cb08c1d985759bfb74 Mon Sep 17 00:00:00 2001 From: Rob Bavey Date: Thu, 14 Jun 2018 12:10:30 -0400 Subject: [PATCH 3/3] Version Bump to 2.2.0 Also fixes license identifier in gemspec to be valid SPDX identifier --- CHANGELOG.md | 9 +++++++-- logstash-input-cloudwatch.gemspec | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac75b5a..82d6f5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.2.0 + - Changed to use the underlying version of the AWS SDK to v2. [#32](https://github.com/logstash-plugins/logstash-input-cloudwatch/pull/32) + - Fixed License definition in gemspec to be valid SPDX identifier [#32](https://github.com/logstash-plugins/logstash-input-cloudwatch/pull/32) + - Fixed fatal error when using secret key attribute in config [#30](https://github.com/logstash-plugins/logstash-input-cloudwatch/issues/30) + ## 2.1.1 - Docs: Set the default_codec doc attribute. @@ -15,5 +20,5 @@ - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash # 1.1.1 - New dependency requirements for logstash-core for the 5.0 release -## 1.1.0 - - Moved from jrgns/logstash-input-cloudwatch to logstash-plugins +## 1.1.0 + - Moved from jrgns/logstash-input-cloudwatch to logstash-plugins diff --git a/logstash-input-cloudwatch.gemspec b/logstash-input-cloudwatch.gemspec index ef302d1..20060e6 100644 --- a/logstash-input-cloudwatch.gemspec +++ b/logstash-input-cloudwatch.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = 'logstash-input-cloudwatch' - s.version = '2.1.1' - s.licenses = ['Apache License (2.0)'] + s.version = '2.2.0' + s.licenses = ['Apache-2.0'] s.summary = "Pulls events from the Amazon Web Services CloudWatch API " s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" s.authors = ["Jurgens du Toit"]