Skip to content

Commit 1b8d287

Browse files
committed
Initial release.
0 parents  commit 1b8d287

22 files changed

+555
-0
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
on: [push]
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
ruby:
9+
- '2.5'
10+
- '2.7'
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v1
14+
- name: Setup Ruby
15+
uses: actions/setup-ruby@v1
16+
with:
17+
ruby-version: ${{ matrix.ruby }}
18+
- name: Bundle
19+
run: |
20+
./bin/setup
21+
- name: Test
22+
run: |
23+
./bin/test

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# Keep A Changelog!
3+
4+
See this http://keepachangelog.com link for information on how we want this documented formatted.
5+
6+
## v0.1.0
7+
8+
### Added
9+
10+
- Initial Release!!! 🎉🎊🥳

CODE_OF_CONDUCT.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at ken@metaskills.net. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [https://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: https://contributor-covenant.org
74+
[version]: https://contributor-covenant.org/version/1/4/

Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source "https://rubygems.org"
2+
gemspec
3+
4+
gem 'rake'
5+
gem 'minitest'
6+
7+
group :test do
8+
gem 'mocha'
9+
gem 'pry'
10+
end

Gemfile.lock

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
PATH
2+
remote: .
3+
specs:
4+
aws-embedded-metrics-customink (0.1.0)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
coderay (1.1.3)
10+
method_source (1.0.0)
11+
minitest (5.14.1)
12+
mocha (1.11.2)
13+
pry (0.13.1)
14+
coderay (~> 1.1)
15+
method_source (~> 1.0)
16+
rake (13.0.1)
17+
18+
PLATFORMS
19+
ruby
20+
21+
DEPENDENCIES
22+
aws-embedded-metrics-customink!
23+
minitest
24+
mocha
25+
pry
26+
rake
27+
28+
BUNDLED WITH
29+
2.1.2

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Ken Collins
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Aws::Embedded::Metrics for Ruby [![Actions Status](https://github.com/customink/aws-embedded-metrics-customink/workflows/CI/badge.svg)](https://github.com/customink/aws-embedded-metrics-customink/actions)
2+
3+
⚠️ Bare minimum code to explore [Amazon CloudWatch Embedded Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html) with Ruby. Any and all help welcome to raise the quality of our implementation.
4+
5+
#### Inspiration
6+
7+
Pulled from these two projects using the [Embedded Metric Format Specification](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Manual.html) as a reference guide.
8+
9+
* Node: https://github.com/awslabs/aws-embedded-metrics-node
10+
* Python: https://github.com/awslabs/aws-embedded-metrics-python
11+
12+
However, unlike these projects, we differ in the following ways. Again, contributions are very much welcome if you want to see more or change this.
13+
14+
* Initial focus on Lambda. No other sinks.
15+
* As such, no default Dimensions or Configuraiton for:
16+
- `LogGroupName`
17+
- `LogStreamName`
18+
- `ServiceName`
19+
- `ServiceType`
20+
21+
## Installation
22+
23+
Add this line to your application's Gemfile:
24+
25+
```ruby
26+
gem 'aws-embedded-metrics-customink'
27+
```
28+
## Usage
29+
30+
Simple configuration.
31+
32+
```ruby
33+
Aws::Embedded::Metrics.configure do |c|
34+
c.namespace = 'MyApplication'
35+
end
36+
```
37+
38+
Usage is in a scope block. All metrics are flushed afterward
39+
40+
```ruby
41+
Aws::Embedded::Metrics.logger do |metrics|
42+
metrics.put_dimension 'SomeDimension', 'SomeDimensionValue'
43+
metrics.set_property 'EventKey', 'some/s3/path'
44+
metrics.put_metric 'Processor', 232, 'Milliseconds'
45+
metrics.put_metric 'Total', 4008, 'Milliseconds'
46+
end
47+
```
48+
49+
## Development
50+
51+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52+
53+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54+
55+
## Contributing
56+
57+
Bug reports and pull requests are welcome on GitHub at https://github.com/customink/aws-embedded-metrics-customink. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/customink/aws-embedded-metrics-customink/blob/master/CODE_OF_CONDUCT.md).
58+
59+
## License
60+
61+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
62+
63+
## Code of Conduct
64+
65+
Everyone interacting in the Aws::Embedded::Metrics project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/customink/aws-embedded-metrics-customink/blob/master/CODE_OF_CONDUCT.md).

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "bundler/gem_tasks"
2+
require "rake/testtask"
3+
4+
Rake::TestTask.new(:test) do |t|
5+
t.libs << "test"
6+
t.libs << "lib"
7+
t.test_files = FileList["test/**/*_test.rb"]
8+
end
9+
10+
task :default => :test
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require_relative 'lib/aws-embedded-metrics-customink/version'
2+
3+
Gem::Specification.new do |spec|
4+
spec.name = "aws-embedded-metrics-customink"
5+
spec.version = Aws::Embedded::Metrics::VERSION
6+
spec.authors = ["Ken Collins"]
7+
spec.email = ["ken@metaskills.net"]
8+
spec.summary = 'Amazon CloudWatch Embedded Metric Format Client Library'
9+
spec.description = 'Amazon CloudWatch Embedded Metric Format Client Library for Ruby.'
10+
spec.homepage = 'https://github.com/customink/aws-embedded-metrics-customink'
11+
spec.license = "MIT"
12+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13+
spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
14+
spec.metadata['homepage_uri'] = spec.homepage
15+
spec.metadata['source_code_uri'] = 'https://github.com/customink/aws-embedded-metrics-customink'
16+
spec.metadata['changelog_uri'] = 'https://github.com/customink/aws-embedded-metrics-customink/blob/master/CHANGELOG.md'
17+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19+
end
20+
spec.bindir = "exe"
21+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22+
spec.require_paths = ["lib"]
23+
end

bin/console

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "aws-embedded-metrics-customink"
5+
6+
# You can add fixtures and/or initialization code here to make experimenting
7+
# with your gem easier. You can also use a different console, if you like.
8+
9+
# (If you use this, don't forget to add pry to your Gemfile!)
10+
# require "pry"
11+
# Pry.start
12+
13+
require "irb"
14+
IRB.start(__FILE__)

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

bin/test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle exec rake test

lib/aws-embedded-metrics-customink.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'json'
2+
require 'benchmark'
3+
require 'aws-embedded-metrics-customink/version'
4+
require 'aws-embedded-metrics-customink/config'
5+
require 'aws-embedded-metrics-customink/sinks'
6+
require 'aws-embedded-metrics-customink/logger'
7+
8+
module Aws
9+
module Embedded
10+
module Metrics
11+
12+
def configure
13+
Config.configure { |c| yield(c) }
14+
end
15+
16+
def reconfigure
17+
Config.reconfigure { |c| yield(c) if block_given? }
18+
end
19+
20+
def logger
21+
Logger.new.tap do |l|
22+
l.metrics { |m| yield(m) } if block_given?
23+
end
24+
end
25+
26+
def sink
27+
@sink ||= Sinks::Lambda.new
28+
end
29+
30+
extend self
31+
32+
end
33+
end
34+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Aws
2+
module Embedded
3+
module Metrics
4+
module Config
5+
6+
def configure
7+
yield(config)
8+
config
9+
end
10+
11+
def reconfigure
12+
config.reconfigure { |c| yield(c) if block_given? }
13+
end
14+
15+
def config
16+
@config ||= Configuration.new
17+
end
18+
19+
extend self
20+
21+
class Configuration
22+
23+
attr_writer :namespace
24+
25+
def reconfigure
26+
instance_variables.each { |var| instance_variable_set var, nil }
27+
yield(self) if block_given?
28+
self
29+
end
30+
31+
def namespace
32+
return @namespace if defined?(@namespace)
33+
ENV['AWS_EMF_NAMESPACE'] || 'aws-embedded-metrics'
34+
end
35+
36+
end
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)