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

CloudWatch logger should let the caller choose broadcast logger #79

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- **BREAKING** Drop automatic broadcast of Cloudwatch to Container logger [(#79)](https://github.com/ManageIQ/manageiq-loggers/pull/79)

## [1.2.0] - 2024-09-30
### Added
Expand Down
6 changes: 2 additions & 4 deletions lib/manageiq/loggers/cloud_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ def self.new(*args, access_key_id: nil, secret_access_key: nil, log_group: nil,
log_group ||= ENV["CLOUD_WATCH_LOG_GROUP"].presence
log_stream ||= ENV["HOSTNAME"].presence

container_logger = ManageIQ::Loggers::Container.new
return container_logger unless access_key_id && secret_access_key && log_group && log_stream
raise ArgumentError, "Required parameters: access_key_id, secret_access_key, log_group, log_stream" unless access_key_id && secret_access_key && log_group && log_stream

require 'cloudwatchlogger'

creds = {:access_key_id => access_key_id, :secret_access_key => secret_access_key}
cloud_watch_logdev = CloudWatchLogger::Client.new(creds, log_group, log_stream)
cloud_watch_logger = super(cloud_watch_logdev)
cloud_watch_logger.wrap(container_logger)
super(cloud_watch_logdev)
end

def initialize(logdev, *args)
Expand Down
30 changes: 14 additions & 16 deletions spec/manageiq/cloud_watch_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'cloudwatchlogger'

describe ManageIQ::Loggers::CloudWatch do
it "unconfigured returns a Container logger" do
expect(described_class.new).to be_kind_of(ManageIQ::Loggers::Container)
let(:cloud_watch_logdev) { double("CloudWatchLogger::Client::AWS_SDK::DeliveryThreadManager") }

it "raises an exception if cloudwatch parameters are missing" do
expect { described_class.new }.to raise_error(ArgumentError, /Required parameters: access_key_id, secret_access_key, log_group, log_stream/)
end

context "configured via env" do
Expand All @@ -22,15 +24,13 @@
end

before do
expect(CloudWatchLogger::Client::AWS_SDK::DeliveryThreadManager).to receive(:new).and_return(double("CloudWatchLogger::Client::AWS_SDK::DeliveryThreadManager", :deliver => nil))
expect(CloudWatchLogger::Client::AWS_SDK::DeliveryThreadManager)
.to receive(:new)
.and_return(cloud_watch_logdev)
end

it "the Container logger also receives the same messages" do
container_logger = ManageIQ::Loggers::Container.new
expect(ManageIQ::Loggers::Container).to receive(:new).and_return(container_logger)

expect(container_logger).to receive(:add).with(1, nil, "Testing 1,2,3")

it "calls deliver on the CloudWatch logger" do
expect(cloud_watch_logdev).to receive(:deliver).with(a_string_matching("\"level\":\"info\",\"message\":\"Testing 1,2,3\""))
described_class.new.info("Testing 1,2,3")
end
end
Expand All @@ -46,15 +46,13 @@
end

before do
expect(CloudWatchLogger::Client::AWS_SDK::DeliveryThreadManager).to receive(:new).and_return(double("CloudWatchLogger::Client::AWS_SDK::DeliveryThreadManager", :deliver => nil))
expect(CloudWatchLogger::Client::AWS_SDK::DeliveryThreadManager)
.to receive(:new)
.and_return(cloud_watch_logdev)
end

it "the Container logger also receives the same messages" do
container_logger = ManageIQ::Loggers::Container.new
expect(ManageIQ::Loggers::Container).to receive(:new).and_return(container_logger)

expect(container_logger).to receive(:add).with(1, nil, "Testing 1,2,3")

it "calls deliver on the CloudWatch logger" do
expect(cloud_watch_logdev).to receive(:deliver).with(a_string_matching("\"level\":\"info\",\"message\":\"Testing 1,2,3\""))
described_class.new(**params).info("Testing 1,2,3")
end
end
Expand Down