aws-embedded-metrics-customink 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 76477125adcfa5d534ff63eda7c6b3469e5ca3c5c778ce40b9b23bce906d1da5
4
+ data.tar.gz: 0bee3bd7ea8e7d2d1ed0a72f928c29741caf17c9d3af2e83901896bfcb40f39a
5
+ SHA512:
6
+ metadata.gz: 5a73a2ab9be29c38ab9dd833642d22877481d46b909740820cfa2420d9fa655f9dc348c9dbf82aa73f61621a00ce1263e4eef4e9b4edc6bb380e67410cfce558
7
+ data.tar.gz: 5ae92d80a90c497a264775a1a5db28ea7614a922cb33865bc7f102e0b65303f80dad0d6f18d485a665100b3a73988a4e387a74dad8e53fe1e267b861df076276
@@ -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
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -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!!! 🎉🎊🥳
@@ -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/
data/Gemfile ADDED
@@ -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
@@ -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
@@ -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.
@@ -0,0 +1,67 @@
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
+ [Enhancing workload observability using Amazon CloudWatch Embedded Metric Format](https://awsfeed.com/whats-new/management-tools/enhancing-workload-observability-using-amazon-cloudwatch-embedded-metric-format)
6
+
7
+ #### Inspiration
8
+
9
+ 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.
10
+
11
+ * Node: https://github.com/awslabs/aws-embedded-metrics-node
12
+ * Python: https://github.com/awslabs/aws-embedded-metrics-python
13
+
14
+ 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.
15
+
16
+ * Initial focus on Lambda. No other sinks.
17
+ * As such, no default Dimensions or Configuraiton for:
18
+ - `LogGroupName`
19
+ - `LogStreamName`
20
+ - `ServiceName`
21
+ - `ServiceType`
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'aws-embedded-metrics-customink'
29
+ ```
30
+ ## Usage
31
+
32
+ Simple configuration.
33
+
34
+ ```ruby
35
+ Aws::Embedded::Metrics.configure do |c|
36
+ c.namespace = 'MyApplication'
37
+ end
38
+ ```
39
+
40
+ Usage is in a scope block. All metrics are flushed afterward
41
+
42
+ ```ruby
43
+ Aws::Embedded::Metrics.logger do |metrics|
44
+ metrics.put_dimension 'SomeDimension', 'SomeDimensionValue'
45
+ metrics.set_property 'EventKey', 'some/s3/path'
46
+ metrics.put_metric 'Processor', 232, 'Milliseconds'
47
+ metrics.put_metric 'Total', 4008, 'Milliseconds'
48
+ end
49
+ ```
50
+
51
+ ## Development
52
+
53
+ 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.
54
+
55
+ 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).
56
+
57
+ ## Contributing
58
+
59
+ 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).
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
64
+
65
+ ## Code of Conduct
66
+
67
+ 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).
@@ -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
@@ -0,0 +1,22 @@
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['homepage_uri'] = spec.homepage
14
+ spec.metadata['source_code_uri'] = 'https://github.com/customink/aws-embedded-metrics-customink'
15
+ spec.metadata['changelog_uri'] = 'https://github.com/customink/aws-embedded-metrics-customink/blob/master/CHANGELOG.md'
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ end
@@ -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__)
@@ -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
@@ -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
@@ -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
@@ -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,0 +1,70 @@
1
+ module Aws
2
+ module Embedded
3
+ module Metrics
4
+ class Logger
5
+
6
+ def initialize(sink = Sinks::Lambda)
7
+ @sink = sink.new
8
+ @namespace = Config.config.namespace
9
+ @dimensions = []
10
+ @metrics = []
11
+ @properties = {}
12
+ end
13
+
14
+ def metrics
15
+ yield(self)
16
+ ensure
17
+ flush
18
+ end
19
+
20
+ def flush
21
+ Metrics.sink.accept(message) unless empty?
22
+ end
23
+
24
+ def put_dimension(name, value)
25
+ @dimensions << { name => value }
26
+ self
27
+ end
28
+
29
+ def put_metric(name, value, unit = nil)
30
+ @metrics << { 'Name' => name }.tap { |m|
31
+ m['Unit'] = unit if unit
32
+ }
33
+ set_property name, value
34
+ end
35
+
36
+ def set_property(name, value)
37
+ @properties[name] = value
38
+ self
39
+ end
40
+
41
+ def empty?
42
+ [@dimensions, @metrics, @properties].all? { |x| x.empty? }
43
+ end
44
+
45
+ def message
46
+ {
47
+ '_aws' => {
48
+ 'Timestamp' => timestamp,
49
+ 'CloudWatchMetrics' => [
50
+ {
51
+ 'Namespace' => @namespace,
52
+ 'Dimensions' => [@dimensions.map(&:keys).flatten],
53
+ 'Metrics' => @metrics
54
+ }
55
+ ]
56
+ }
57
+ }.tap do |m|
58
+ @dimensions.each { |dim| m.merge!(dim) }
59
+ m.merge!(@properties)
60
+ end
61
+ end
62
+
63
+ def timestamp
64
+ Time.now.strftime('%s%3N').to_i
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1 @@
1
+ require 'aws-embedded-metrics-customink/sinks/lambda'
@@ -0,0 +1,15 @@
1
+ module Aws
2
+ module Embedded
3
+ module Metrics
4
+ module Sinks
5
+ class Lambda
6
+
7
+ def accept(message)
8
+ puts JSON.dump(message)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Aws
2
+ module Embedded
3
+ module Metrics
4
+ VERSION = '0.1.0'.freeze
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-embedded-metrics-customink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ken Collins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Amazon CloudWatch Embedded Metric Format Client Library for Ruby.
14
+ email:
15
+ - ken@metaskills.net
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/ci.yml"
21
+ - ".gitignore"
22
+ - CHANGELOG.md
23
+ - CODE_OF_CONDUCT.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - aws-embedded-metrics-customink.gemspec
30
+ - bin/console
31
+ - bin/setup
32
+ - bin/test
33
+ - lib/aws-embedded-metrics-customink.rb
34
+ - lib/aws-embedded-metrics-customink/config.rb
35
+ - lib/aws-embedded-metrics-customink/logger.rb
36
+ - lib/aws-embedded-metrics-customink/sinks.rb
37
+ - lib/aws-embedded-metrics-customink/sinks/lambda.rb
38
+ - lib/aws-embedded-metrics-customink/version.rb
39
+ homepage: https://github.com/customink/aws-embedded-metrics-customink
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/customink/aws-embedded-metrics-customink
44
+ source_code_uri: https://github.com/customink/aws-embedded-metrics-customink
45
+ changelog_uri: https://github.com/customink/aws-embedded-metrics-customink/blob/master/CHANGELOG.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.1.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Amazon CloudWatch Embedded Metric Format Client Library
65
+ test_files: []