Skip to content

Commit

Permalink
Cleanup gem setup (#20)
Browse files Browse the repository at this point in the history
* Ignore Gemfile.lock from Git

We don't really want to lock folks working on this gem into exact
versions of the various dependencies. Especially for  certain
dependencies with native extensions, which might not install on
different platforms. This also organizes the .gitignore.

* Exclude dev-specific files from packed Gem

We can keep the size of the packaged Gem smaller by no including specs,
binstubs, git/github config, and other development-time-only files.

* Upgrade Rake (b/c why not?)

* Fix some spelling, grammar, and formatting

* Test newer Rubies and Ubuntus too!

* fixup ubuntu

* Run tests on a new PR

* Bring back Gemfile.lock and use latest Ruby 2.6

Even though Ruby 2.6 (and 2.7) are EoL'd, they are still supported by
this Gem. So let's use that oldest one locally too. Also, it appears it
is now recommended to include the Gemfile.lock in Git for Gems. The
guidance from Bundler use to be _NOT_ to include the .lock file. But,
time moves forward and things change. I'll adapt and learn too! 😅

https://bundler.io/guides/faq.html#using-gemfiles-inside-gems

* Appease Rubocop 👮
  • Loading branch information
stevenharman authored May 13, 2024
1 parent 30537c8 commit 6563528
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 62 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
name: build

on: [push, create]
on: [push, create, pull_request]

jobs:
build_matrix:
strategy:
matrix:
os: ['ubuntu-18.04', 'ubuntu-20.04']
ruby: ['2.6', '2.7', '3.0', '3.1']
os:
- "ubuntu-20.04"
- "ubuntu-22.04"
- "ubuntu-latest"
ruby:
- "2.6"
- "2.7"
- "3.0"
- "3.1"
- "3.2"
- "3.3"

runs-on: ${{ matrix.os }}

steps:
# Environment setup
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
Expand Down Expand Up @@ -45,7 +54,7 @@ jobs:
if: github.event_name == 'create' && startsWith(github.ref, 'refs/tags/v')

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1

- name: Create credentials
Expand Down
25 changes: 18 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
/.bundle/
# Ignore all logfiles and tempfiles
/tmp/
/tags

# Environment normalisation
/.rspec-local
/.yardoc
/_yardoc/
/coverage/
/doc/
/_yardoc
/lib/bundler/man/

# Gem packaging stuff
/*.gem
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
# Dependencies and such
/.bundle
/.ruby-version

# Spec housekeeping
/coverage/
/spec/reports
.rspec_status
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 2.6.6
ruby 2.6.10
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gemspec
gem 'dogstatsd-ruby'

gem 'rack'
gem 'rake', '~> 12.0'
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 1.5'
gem 'rubocop-performance', '~> 1.9'
70 changes: 38 additions & 32 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,66 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
diff-lcs (1.5.0)
dogstatsd-ruby (5.5.0)
nio4r (2.5.8)
parallel (1.22.1)
parser (3.1.2.0)
diff-lcs (1.5.1)
dogstatsd-ruby (5.6.1)
json (2.7.2)
nio4r (2.7.1)
parallel (1.24.0)
parser (3.3.1.0)
ast (~> 2.4.1)
puma (6.0.1)
racc
puma (6.4.2)
nio4r (~> 2.0)
rack (2.2.3.1)
racc (1.7.3)
rack (3.0.10)
rainbow (3.1.1)
rake (12.3.3)
regexp_parser (2.5.0)
rexml (3.2.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
rake (13.2.1)
regexp_parser (2.9.0)
rexml (3.2.6)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.1)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.30.1)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.18.0)
parser (>= 3.1.1.0)
rubocop-performance (1.14.2)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-performance (1.17.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
unicode-display_width (2.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-23
ruby
x86_64-linux

DEPENDENCIES
dogstatsd-ruby
puma-plugin-telemetry!
rack
rake (~> 12.0)
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 1.5)
rubocop-performance (~> 1.9)

BUNDLED WITH
2.3.12
2.4.22
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Puma plugin which should be able to handle all your metric needs regarding your webserver:

- ability to publish basic puma statistics (like queue backlog) to both logs and datadog
- ability to publish basic puma statistics (like queue backlog) to both logs and Datadog
- ability to add custom target whenever you need it
- ability to monitor puma socket listen queue (!)
- ability to report requests queue time via custom rack middleware - the time request spent between being accepted by Load Balancer and start of its processing by Puma worker
Expand All @@ -17,11 +17,15 @@ gem "puma-plugin-telemetry"

And then execute:

$ bundle install
```console
$ bundle install
```

Or install it yourself as:

$ gem install puma-plugin-telemetry
```console
$ gem install puma-plugin-telemetry
```

## Usage

Expand All @@ -39,15 +43,15 @@ end

### Basic

Output telemetry as JSON to STDOUT
Output telemetry as JSON to `STDOUT`

```ruby
config.add_target :io
```

### Datadog statsd target
### Datadog StatsD target

Given gem provides built in target for Datadog Statsd client, that uses batch operation to publish metrics.
Given gem provides built in target for Datadog StatsD client, that uses batch operation to publish metrics.

**NOTE** Be sure to have `dogstatsd` gem installed.

Expand Down Expand Up @@ -76,7 +80,7 @@ end

### Custom Targets

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.
Target is a simple object that implements `call` methods that accepts `telemetry` hash object. This means it can be super simple `proc` or some sophisticated class calling some external API.

Just be mindful that if the API takes long to call, it will slow down frequency with which telemetry will get reported.

Expand All @@ -87,7 +91,7 @@ Just be mindful that if the API takes long to call, it will slow down frequency

## Extra middleware

This gems comes together with middleware for measuring request queue time, which will be reported in `request.env` and published to given statsd client.
This gems comes together with middleware for measuring request queue time, which will be reported in `request.env` and published to given StatsD client.

Example configuration:

Expand All @@ -110,7 +114,7 @@ This will provide proper metric in Datadog and in logs as well. Logs can be tran

## Development

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.
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`.

Expand Down
5 changes: 4 additions & 1 deletion puma-plugin-telemetry.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
`git ls-files -z`.split("\x0").reject do |f|
(File.expand_path(f) == __FILE__) ||
f.start_with?(*%w[bin/ spec/ .git .github Gemfile])
end
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class Plugin
end

it 'executes the first target' do
true while (line = @server.next_line) !~ /target=01/
true until (line = @server.next_line).include?('target=01')
expect(line).to start_with "target=01 telemetry=#{expected_telemetry.inspect}"
end

it 'executes the second target' do
true while (line = @server.next_line) !~ /target=02/
true until (line = @server.next_line).include?('target=02')
expect(line).to start_with "target=02 telemetry=#{expected_telemetry.inspect}"
end
end
Expand All @@ -67,7 +67,7 @@ class Plugin
end

it 'logs only selected telemetry' do
true while (line = @server.next_line) !~ /Puma::Plugin::Telemetry/
true until (line = @server.next_line).include?('Puma::Plugin::Telemetry')
expect(line).to start_with expected_telemetry
end
end
Expand All @@ -87,7 +87,7 @@ class Plugin
end

it "doesn't crash" do
true while (line = @server.next_line) !~ /DEBUG -- : Statsd/
true until (line = @server.next_line).include?('DEBUG -- : Statsd')

lines = ([line.slice(/workers.*/)] + Array.new(6) { @server.next_line.strip })

Expand Down
4 changes: 2 additions & 2 deletions spec/support/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def start
@server = IO.popen("BIND_PATH=#{bind_path} bundle exec puma -C spec/fixtures/#{@config}.rb -v --debug", 'r')
@server_pid = @server.pid

true while next_line !~ /PID:\ /
true until next_line.include?('PID: ')
@puma_pid = @lines.last.split(': ').last.to_i

true while next_line !~ /Ctrl-C/
true until next_line.include?('Ctrl-C')
end

def stop
Expand Down

0 comments on commit 6563528

Please sign in to comment.