Skip to content

Commit 6563528

Browse files
authored
Cleanup gem setup (#20)
* 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 👮
1 parent 30537c8 commit 6563528

File tree

9 files changed

+95
-62
lines changed

9 files changed

+95
-62
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
name: build
22

3-
on: [push, create]
3+
on: [push, create, pull_request]
44

55
jobs:
66
build_matrix:
77
strategy:
88
matrix:
9-
os: ['ubuntu-18.04', 'ubuntu-20.04']
10-
ruby: ['2.6', '2.7', '3.0', '3.1']
9+
os:
10+
- "ubuntu-20.04"
11+
- "ubuntu-22.04"
12+
- "ubuntu-latest"
13+
ruby:
14+
- "2.6"
15+
- "2.7"
16+
- "3.0"
17+
- "3.1"
18+
- "3.2"
19+
- "3.3"
1120

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

1423
steps:
1524
# Environment setup
16-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
1726

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

4756
steps:
48-
- uses: actions/checkout@v3
57+
- uses: actions/checkout@v4
4958
- uses: ruby/setup-ruby@v1
5059

5160
- name: Create credentials

.gitignore

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
/.bundle/
1+
# Ignore all logfiles and tempfiles
2+
/tmp/
3+
/tags
4+
5+
# Environment normalisation
6+
/.rspec-local
27
/.yardoc
3-
/_yardoc/
4-
/coverage/
5-
/doc/
8+
/_yardoc
9+
/lib/bundler/man/
10+
11+
# Gem packaging stuff
12+
/*.gem
613
/pkg/
7-
/spec/reports/
8-
/tmp/
914

10-
# rspec failure tracking
15+
# Dependencies and such
16+
/.bundle
17+
/.ruby-version
18+
19+
# Spec housekeeping
20+
/coverage/
21+
/spec/reports
1122
.rspec_status

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby 2.6.6
1+
ruby 2.6.10

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ gemspec
88
gem 'dogstatsd-ruby'
99

1010
gem 'rack'
11-
gem 'rake', '~> 12.0'
11+
gem 'rake', '~> 13.0'
1212
gem 'rspec', '~> 3.0'
1313
gem 'rubocop', '~> 1.5'
1414
gem 'rubocop-performance', '~> 1.9'

Gemfile.lock

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,66 @@ GEM
88
remote: https://rubygems.org/
99
specs:
1010
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)
11+
diff-lcs (1.5.1)
12+
dogstatsd-ruby (5.6.1)
13+
json (2.7.2)
14+
nio4r (2.7.1)
15+
parallel (1.24.0)
16+
parser (3.3.1.0)
1617
ast (~> 2.4.1)
17-
puma (6.0.1)
18+
racc
19+
puma (6.4.2)
1820
nio4r (~> 2.0)
19-
rack (2.2.3.1)
21+
racc (1.7.3)
22+
rack (3.0.10)
2023
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)
24+
rake (13.2.1)
25+
regexp_parser (2.9.0)
26+
rexml (3.2.6)
27+
rspec (3.13.0)
28+
rspec-core (~> 3.13.0)
29+
rspec-expectations (~> 3.13.0)
30+
rspec-mocks (~> 3.13.0)
31+
rspec-core (3.13.0)
32+
rspec-support (~> 3.13.0)
33+
rspec-expectations (3.13.0)
3134
diff-lcs (>= 1.2.0, < 2.0)
32-
rspec-support (~> 3.11.0)
33-
rspec-mocks (3.11.1)
35+
rspec-support (~> 3.13.0)
36+
rspec-mocks (3.13.0)
3437
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+
rspec-support (~> 3.13.0)
39+
rspec-support (3.13.1)
40+
rubocop (1.50.2)
41+
json (~> 2.3)
3842
parallel (~> 1.10)
39-
parser (>= 3.1.0.0)
43+
parser (>= 3.2.0.0)
4044
rainbow (>= 2.2.2, < 4.0)
4145
regexp_parser (>= 1.8, < 3.0)
4246
rexml (>= 3.2.5, < 4.0)
43-
rubocop-ast (>= 1.18.0, < 2.0)
47+
rubocop-ast (>= 1.28.0, < 2.0)
4448
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+
unicode-display_width (>= 2.4.0, < 3.0)
50+
rubocop-ast (1.30.0)
51+
parser (>= 3.2.1.0)
52+
rubocop-performance (1.17.1)
4953
rubocop (>= 1.7.0, < 2.0)
5054
rubocop-ast (>= 0.4.0)
51-
ruby-progressbar (1.11.0)
52-
unicode-display_width (2.1.0)
55+
ruby-progressbar (1.13.0)
56+
unicode-display_width (2.5.0)
5357

5458
PLATFORMS
59+
arm64-darwin-23
5560
ruby
61+
x86_64-linux
5662

5763
DEPENDENCIES
5864
dogstatsd-ruby
5965
puma-plugin-telemetry!
6066
rack
61-
rake (~> 12.0)
67+
rake (~> 13.0)
6268
rspec (~> 3.0)
6369
rubocop (~> 1.5)
6470
rubocop-performance (~> 1.9)
6571

6672
BUNDLED WITH
67-
2.3.12
73+
2.4.22

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
- ability to publish basic puma statistics (like queue backlog) to both logs and datadog
5+
- ability to publish basic puma statistics (like queue backlog) to both logs and Datadog
66
- ability to add custom target whenever you need it
77
- ability to monitor puma socket listen queue (!)
88
- 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
@@ -17,11 +17,15 @@ gem "puma-plugin-telemetry"
1717

1818
And then execute:
1919

20-
$ bundle install
20+
```console
21+
$ bundle install
22+
```
2123

2224
Or install it yourself as:
2325

24-
$ gem install puma-plugin-telemetry
26+
```console
27+
$ gem install puma-plugin-telemetry
28+
```
2529

2630
## Usage
2731

@@ -39,15 +43,15 @@ end
3943

4044
### Basic
4145

42-
Output telemetry as JSON to STDOUT
46+
Output telemetry as JSON to `STDOUT`
4347

4448
```ruby
4549
config.add_target :io
4650
```
4751

48-
### Datadog statsd target
52+
### Datadog StatsD target
4953

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

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

@@ -76,7 +80,7 @@ end
7680

7781
### Custom Targets
7882

79-
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.
83+
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.
8084

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

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

8892
## Extra middleware
8993

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

9296
Example configuration:
9397

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

111115
## Development
112116

113-
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.
117+
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.
114118

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

puma-plugin-telemetry.gemspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
3333
# Specify which files should be added to the gem when it is released.
3434
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
3535
spec.files = Dir.chdir(File.expand_path(__dir__)) do
36-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
36+
`git ls-files -z`.split("\x0").reject do |f|
37+
(File.expand_path(f) == __FILE__) ||
38+
f.start_with?(*%w[bin/ spec/ .git .github Gemfile])
39+
end
3740
end
3841
spec.bindir = 'exe'
3942
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }

spec/integration/plugin_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class Plugin
5050
end
5151

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

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

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

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

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

spec/support/server.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def start
1212
@server = IO.popen("BIND_PATH=#{bind_path} bundle exec puma -C spec/fixtures/#{@config}.rb -v --debug", 'r')
1313
@server_pid = @server.pid
1414

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

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

2121
def stop

0 commit comments

Comments
 (0)