This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor sinks to be stateful; Add a logger sink
- Loading branch information
Showing
13 changed files
with
106 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require 'aws-embedded-metrics-customink/sinks/lambda' | ||
require 'aws-embedded-metrics-customink/sinks/logger' | ||
require 'aws-embedded-metrics-customink/sinks/stdout' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Aws | ||
module Embedded | ||
module Metrics | ||
module Sinks | ||
class Logger | ||
|
||
attr_reader :logger, :level | ||
|
||
def initialize(logger, level: 'info') | ||
@logger = logger | ||
@level = level | ||
end | ||
|
||
def accept(message) | ||
logger.public_send(level, JSON.dump(message)) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module Aws | ||
module Embedded | ||
module Metrics | ||
VERSION = '0.1.0'.freeze | ||
VERSION = '0.2.0'.freeze | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'logger' | ||
require 'stringio' | ||
|
||
module Sinks | ||
class LoggerTest < TestCase | ||
let(:logger) { Logger.new(StringIO.new) } | ||
let(:level) { :info } | ||
let(:msg) { { hello: 'world' } } | ||
let(:sink) { Aws::Embedded::Metrics::Sinks::Logger.new(logger, level: level) } | ||
|
||
it 'initializes with an instance of a logger and a log level' do | ||
expect(sink).must_be_instance_of Aws::Embedded::Metrics::Sinks::Logger | ||
expect(sink.logger).must_equal logger | ||
expect(sink.level).must_equal level | ||
end | ||
|
||
it '#accept dumps its message as json to the logger at the prescribed log level' do | ||
logger.expects(:info).with(JSON.dump(msg)).once | ||
sink.accept(msg) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Sinks | ||
class StdoutTest < TestCase | ||
let(:msg) { { hello: 'world' } } | ||
let(:sink) { Aws::Embedded::Metrics::Sinks::Stdout.new } | ||
|
||
it 'initializes with no arguments' do | ||
expect(sink).must_be_instance_of Aws::Embedded::Metrics::Sinks::Stdout | ||
end | ||
|
||
it '#accept dumps its message as json to stdout' do | ||
STDOUT.expects(:puts).with(JSON.dump(msg)).once | ||
sink.accept(msg) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters