-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Sentry::Metrics.timing API to measure blocks
- Loading branch information
1 parent
0e87bab
commit e6bbb90
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
module Metrics | ||
module Timing | ||
class << self | ||
def nanosecond | ||
time = Sentry.utc_now | ||
time.to_i * (10 ** 9) + time.nsec | ||
end | ||
|
||
def microsecond | ||
time = Sentry.utc_now | ||
time.to_i * (10 ** 6) + time.usec | ||
end | ||
|
||
def millisecond | ||
Sentry.utc_now.to_i * (10 ** 3) | ||
end | ||
|
||
def second | ||
Sentry.utc_now.to_i | ||
end | ||
|
||
def minute | ||
Sentry.utc_now.to_i / 60.0 | ||
end | ||
|
||
def hour | ||
Sentry.utc_now.to_i / 3600.0 | ||
end | ||
|
||
def day | ||
Sentry.utc_now.to_i / (3600.0 * 24.0) | ||
end | ||
|
||
def week | ||
Sentry.utc_now.to_i / (3600.0 * 24.0 * 7.0) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Sentry::Metrics::Timing do | ||
let(:fake_time) { Time.new(2024, 1, 2, 3, 4, 5) } | ||
before { allow(Time).to receive(:now).and_return(fake_time) } | ||
|
||
describe '.nanosecond' do | ||
it 'returns nanoseconds' do | ||
expect(described_class.nanosecond).to eq(fake_time.to_i * 10 ** 9) | ||
end | ||
end | ||
|
||
describe '.microsecond' do | ||
it 'returns microseconds' do | ||
expect(described_class.microsecond).to eq(fake_time.to_i * 10 ** 6) | ||
end | ||
end | ||
|
||
describe '.millisecond' do | ||
it 'returns milliseconds' do | ||
expect(described_class.millisecond).to eq(fake_time.to_i * 10 ** 3) | ||
end | ||
end | ||
|
||
describe '.second' do | ||
it 'returns seconds' do | ||
expect(described_class.second).to eq(fake_time.to_i) | ||
end | ||
end | ||
|
||
describe '.minute' do | ||
it 'returns minutes' do | ||
expect(described_class.minute).to eq(fake_time.to_i / 60.0) | ||
end | ||
end | ||
|
||
describe '.hour' do | ||
it 'returns hours' do | ||
expect(described_class.hour).to eq(fake_time.to_i / 3600.0) | ||
end | ||
end | ||
|
||
describe '.day' do | ||
it 'returns days' do | ||
expect(described_class.day).to eq(fake_time.to_i / (3600.0 * 24.0)) | ||
end | ||
end | ||
|
||
describe '.week' do | ||
it 'returns weeks' do | ||
expect(described_class.week).to eq(fake_time.to_i / (3600.0 * 24.0 * 7.0)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters