Skip to content

Commit

Permalink
Merge pull request #52 from gocardless/duration_in_seconds
Browse files Browse the repository at this point in the history
DET-69 Report `duration` in seconds
  • Loading branch information
Harry Maclean authored Jun 13, 2019
2 parents c337289 + 98b3bad commit 1b5a97b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inherit_gem:
AllCops:
TargetRubyVersion: 2.2

Metrics/MethodLength:
Max: 15

Style/RescueStandardError:
Exclude:
- "*/**/*_spec.rb"
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* [#60](https://github.com/gocardless/coach/pull/60) Add `Middleware.requires?`, which
behaves like `Middleware.provides?` but for requirements.

* [#52](https://github.com/gocardless/coach/pull/52) Add `duration_seconds` to statistic
logging. The `duration` field is now deprecated and will be removed in a future release.

## Breaking changes

* [#70](https://github.com/gocardless/coach/pull/70) The following deprecated event names have been removed:
Expand Down
7 changes: 6 additions & 1 deletion lib/coach/request_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ def stats
endpoint_name: @endpoint_name,
started_at: @start,
duration: format_ms(@duration),
duration_seconds: @duration,
chain: sorted_chain.map do |event|
{ name: event[:name], duration: format_ms(event[:duration]) }
{
name: event[:name],
duration: format_ms(event[:duration]),
duration_seconds: event[:duration],
}
end,
}
end
Expand Down
2 changes: 0 additions & 2 deletions lib/coach/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

# Middleware stubbing ######################################

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def build_middleware(name)
Class.new(Coach::Middleware) do
Expand All @@ -28,7 +27,6 @@ def call
end
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength

def null_middleware
double(call: nil)
Expand Down
5 changes: 3 additions & 2 deletions spec/lib/coach/request_benchmark_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

it "computes overall duration" do
expect(stats[:duration]).to eq(5000)
expect(stats[:duration_seconds]).to eq(5.0)
end

it "captures the endpoint_name" do
Expand All @@ -35,11 +36,11 @@
end

it "computes duration of middleware with no children" do
expect(stats[:chain]).to include(name: "B", duration: 1000)
expect(stats[:chain]).to include(name: "B", duration: 1000, duration_seconds: 1.0)
end

it "adjusts duration of middleware for their children" do
expect(stats[:chain]).to include(name: "A", duration: 2000)
expect(stats[:chain]).to include(name: "A", duration: 2000, duration_seconds: 2.0)
end

it "correctly orders chain" do
Expand Down

0 comments on commit 1b5a97b

Please sign in to comment.