puma-plugin-telemetry 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fe506b3cee809f3647bdbd9215b7ed150e8efaadc0d3ce6971c76cbca375dde8
4
+ data.tar.gz: 0c7a16268af68cd404297699db57a0f253c95e341e78b25555f114debeb6c86b
5
+ SHA512:
6
+ metadata.gz: c3f48102a6b14d5ba37135788d63b7c489e18a06640217d9df6080a98c9f62efdfdc5f9cf563e192225496d04e342a5829e192ce88b926d9c90e4cf4b68153db
7
+ data.tar.gz: 36f0d6c18542b52f9c77764bd6a84b7693af50e84a1e398333cf1d6207d76297fbf5dbcf2b906b8ef855bb9de42764a11b7877467ae3e4872a1dd01044b145e7
@@ -0,0 +1,5 @@
1
+ # Individuals and teams that are responsible for code in the repository.
2
+ #
3
+ # Read more at https://help.github.com/en/articles/about-code-owners
4
+
5
+ * @babbel/tnt
@@ -0,0 +1,46 @@
1
+ name: build
2
+
3
+ on: [push, create]
4
+
5
+ jobs:
6
+ build_matrix:
7
+ strategy:
8
+ matrix:
9
+ os: ['ubuntu-18.04', 'ubuntu-20.04']
10
+ ruby: ['2.6', '2.7', '3.0', '3.1']
11
+
12
+ runs-on: ${{ matrix.os }}
13
+
14
+ steps:
15
+ # Environment setup
16
+ - uses: actions/checkout@v3
17
+
18
+ - uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+
23
+ - name: Run rubocop
24
+ run: |
25
+ bundle exec rubocop --display-cop-names
26
+
27
+ - name: Run tests
28
+ run: |
29
+ bundle exec rspec
30
+
31
+ build:
32
+ needs: [build_matrix]
33
+ runs-on: ubuntu-20.04
34
+ steps:
35
+ - name: Dummy for branch status checks
36
+ run: |
37
+ echo "build complete"
38
+
39
+ release:
40
+ needs: build
41
+ if: contains(github.ref, 'tags') && github.event_name == 'create'
42
+ runs-on: ubuntu-20.04
43
+ steps:
44
+ - uses: actions/checkout@v3
45
+ - uses: ruby/setup-ruby@v1
46
+ - uses: babbel/publish-gem@v1
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+ NewCops: enable
7
+
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - spec/**/*
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.6.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,76 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.1.0]
11
+
12
+ Out of beta testing, reading for usage. Following is a recap from Alpha & Beta releases.
13
+
14
+ ### Added
15
+ - new metric: `sockets.backlog` (disabled by default), pulls information from Puma
16
+ sockets about the state of their backlogs. This together with `queue.backlog`
17
+ allows for full insights into total number of requests waiting to be processed
18
+ - `config.sockets_telemetry!` option to enable sockets telemetry
19
+ - `config.socket_parser` option to allow custom parser implementation as needed
20
+ - Datadog widgets examples under `docs/examples.md`
21
+
22
+ ## [1.1.0 Beta]
23
+
24
+ ### Added
25
+
26
+ Different ways to parse `Socket::Option`. Mainly due to the fact that `#inspect` can't
27
+ generate proper data on AWS Fargate, which runs Amazon Linux 2 with 4.14 kernel. So now
28
+ besides `#inspect` there's also `#unpack` that parses binary data and picks proper field.
29
+
30
+ It depends on the kernel, but new fields are usually added at the end of the `tcp_info`
31
+ struct, so it should more or less stay stable.
32
+
33
+ You can configure it by passing in `config.socket_parser = :inspect` or
34
+ `config.socket_parser = ->(opt) { your implementation }`.
35
+
36
+ ## [1.1.0 Alpha]
37
+
38
+ ### Added
39
+
40
+ Socket telemetry, and to be more precise new metric: `sockets.backlog`. If enabled it will
41
+ pull information from Puma sockets about the state of their backlogs (requests waiting to
42
+ be acknowledged by Puma). It will be exposed under `sockets-backlog` metric.
43
+
44
+ You can enable and test it via `config.sockets_telemetry!` option.
45
+
46
+ ## [1.0.0] - 2021-09-08
47
+ ### Added
48
+ - Release to Github Packages
49
+ - Explicitly flush datadog metrics after publishing them
50
+ - Middleware for measuring and tracking request queue time
51
+
52
+ ### Changed
53
+ - Replace `statsd.batch` with direct calls, as it aggregates metrics interally by default now.
54
+ Also `#batch` method is deprecated and will be removed in version 6 of Datadog Statsd client.
55
+
56
+ ## [0.3.1] - 2021-03-26
57
+ ### Changed
58
+ - IO target replaces dots in telemetry keys with dashes for better integration with AWS CloudWatch
59
+
60
+ ## [0.3.0] - 2020-12-21
61
+ ### Added
62
+ - Datadog Target integration tests
63
+
64
+ ### Fixed
65
+ - Datadog Target
66
+
67
+ ## [0.2.0] - 2020-12-21
68
+ ### Fixed
69
+ - Removed debugging information
70
+
71
+ ## [0.1.0] - 2020-12-18
72
+ ### Added
73
+ - Core Plugin
74
+ - Telemetry generation
75
+ - IO Target with JSON formatter
76
+ - Datadog Statsd Target
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tnt@babbel.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in puma-plugin-telemetry.gemspec
6
+ gemspec
7
+
8
+ gem 'dogstatsd-ruby'
9
+
10
+ gem 'rack'
11
+ gem 'rake', '~> 12.0'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rubocop', '~> 1.5'
14
+ gem 'rubocop-performance', '~> 1.9'
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ puma-plugin-telemetry (1.1.0)
5
+ puma (>= 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ diff-lcs (1.5.0)
12
+ dogstatsd-ruby (5.5.0)
13
+ nio4r (2.5.8)
14
+ parallel (1.22.1)
15
+ parser (3.1.2.0)
16
+ ast (~> 2.4.1)
17
+ puma (5.6.4)
18
+ nio4r (~> 2.0)
19
+ rack (2.2.3.1)
20
+ rainbow (3.1.1)
21
+ rake (12.3.3)
22
+ regexp_parser (2.5.0)
23
+ rexml (3.2.5)
24
+ rspec (3.11.0)
25
+ rspec-core (~> 3.11.0)
26
+ rspec-expectations (~> 3.11.0)
27
+ rspec-mocks (~> 3.11.0)
28
+ rspec-core (3.11.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-expectations (3.11.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-mocks (3.11.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-support (3.11.0)
37
+ rubocop (1.30.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 3.1.0.0)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8, < 3.0)
42
+ rexml (>= 3.2.5, < 4.0)
43
+ rubocop-ast (>= 1.18.0, < 2.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 3.0)
46
+ rubocop-ast (1.18.0)
47
+ parser (>= 3.1.1.0)
48
+ rubocop-performance (1.14.2)
49
+ rubocop (>= 1.7.0, < 2.0)
50
+ rubocop-ast (>= 0.4.0)
51
+ ruby-progressbar (1.11.0)
52
+ unicode-display_width (2.1.0)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ dogstatsd-ruby
59
+ puma-plugin-telemetry!
60
+ rack
61
+ rake (~> 12.0)
62
+ rspec (~> 3.0)
63
+ rubocop (~> 1.5)
64
+ rubocop-performance (~> 1.9)
65
+
66
+ BUNDLED WITH
67
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Babbel GmbH
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.
data/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # Puma::Plugin::Telemetry
2
+
3
+ Puma plugin adding ability to publish various metrics to your prefered targets.
4
+
5
+ ## Install
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "puma-plugin-telemetry"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install puma-plugin-telemetry
20
+
21
+ ## Usage
22
+
23
+ In your puma configuration file (i.e. `config/puma.rb` or `config/puma/<env>.rb`):
24
+
25
+ ```ruby
26
+ plugin "telemetry"
27
+
28
+ Puma::Plugin::Telemetry.configure do |config|
29
+ config.enabled = true
30
+
31
+ # << here rest of the configuration, examples below
32
+ end
33
+ ```
34
+
35
+ ### Basic
36
+
37
+ Output telemetry as JSON to STDOUT
38
+
39
+ ```ruby
40
+ config.add_target :io
41
+ ```
42
+
43
+ ### Datadog statsd target
44
+
45
+ Given gem provides built in target for Datadog Statsd client, that uses batch operation to publish metrics.
46
+
47
+ **NOTE** Be sure to have `dogstatsd` gem installed.
48
+
49
+ ```ruby
50
+ config.add_target :dogstatsd, client: Datadog::Statsd.new
51
+ ```
52
+
53
+ You can provide all the tags, namespaces, and other configuration options as always to `Datadog::Statsd.new` method.
54
+
55
+ ### All available options
56
+
57
+ For detailed documentation checkout [`Puma::Plugin::Telemetry::Config`](./lib/puma/plugin/telemetry/config.rb) class.
58
+
59
+ ```ruby
60
+ Puma::Plugin::Telemetry.configure do |config|
61
+ config.enabled = true
62
+ config.initial_delay = 10
63
+ config.frequency = 30
64
+ config.puma_telemetry = %w[workers.requests_count queue.backlog queue.capacity]
65
+ config.socket_telemetry!
66
+ config.socket_parser = :inspect
67
+ config.add_target :io, formatter: :json, io: StringIO.new
68
+ config.add_target :dogstatsd, client: Datadog::Statsd.new(tags: { env: ENV["RAILS_ENV"] })
69
+ end
70
+ ```
71
+
72
+ ### Custom Targets
73
+
74
+ Target is a simple object that implements `call` methods that accepts `telemetry` hash object. This means it can be super simple `proc` or some sofisticated class calling some external API.
75
+
76
+ Just be mindful that if the API takes long to call, it will slow down frequency with which telemetry will get reported.
77
+
78
+ ```ruby
79
+ # Example logfmt to stdout target
80
+ config.add_target proc { |telemetry| puts telemetry.map { |k, v| "#{k}=#{v.inspect}" }.join(" ") }
81
+ ```
82
+
83
+ ## Extra middleware
84
+
85
+ This gems comes together with middleware for measuring request queue time, which will be reported in `request.env` and published to given statsd client.
86
+
87
+ Example configuration:
88
+
89
+ ```ruby
90
+ # in Gemfile add `require` part
91
+ gem "puma-plugin-telemetry", require: ["rack/request_queue_time_middleware"]
92
+
93
+ # in initializer, i.e. `request_queue_time.rb`
94
+ Rails.application.config.middleware.insert_after(
95
+ 0,
96
+ RequestQueueTimeMiddleware,
97
+ statsd: Datadog::Statsd.new(namespace: "ruby.puma", tags: { "app" => "accounts" })
98
+ )
99
+
100
+ Rails.application.config.log_tags ||= {}
101
+ Rails.application.config.log_tags[:queue_time] = ->(req) { req.env[::RequestQueueTimeMiddleware::ENV_KEY] }
102
+ ```
103
+
104
+ This will provide proper metric in Datadog and in logs as well. Logs can be transformed into log metrics and used for auto scaling purposes.
105
+
106
+ ## Development
107
+
108
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
109
+
110
+ To install this gem onto your local machine, run `bundle exec rake install`.
111
+
112
+ ## Release
113
+
114
+ All gem releases are manual, in order to create a new release follow:
115
+
116
+ 1. Create new PR (this could be included in feature PR, if it's meant to be released)
117
+ - update `VERSION`, we use [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
118
+ - update `CHANGELOG`
119
+ - merge
120
+ 2. Draft new release via Github Releases
121
+ - use `v#{VERSION}` as a tag, i.e. `v0.1.0`
122
+ - add release notes based on the Changelog
123
+ - create
124
+ 3. Gem will get automatically published to given rubygems server
125
+
126
+ ## Contributing
127
+
128
+ Bug reports and pull requests are welcome on GitHub at https://github.com/babbel/puma-plugin-telemetry.
129
+
130
+ ## License
131
+
132
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
133
+
134
+ ## Code of Conduct
135
+
136
+ Everyone interacting in the puma-plugin-telemetry project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/babbel/puma-plugin-telemetry/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[rubocop spec]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'puma/plugin/telemetry'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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
Binary file