-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7702905
commit 11f2f29
Showing
7 changed files
with
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'sentry/metrics/metric' | ||
require 'sentry/metrics/counter_metric' | ||
require 'sentry/metrics/distribution_metric' | ||
require 'sentry/metrics/gauge_metric' | ||
require 'sentry/metrics/set_metric' | ||
|
||
module Sentry | ||
module Metrics | ||
class << self | ||
# TODO-neel-metrics define units, maybe symbols | ||
def incr(key, value: 1.0, unit: 'none', tags: nil, timestamp: nil) | ||
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
module Metrics | ||
class Aggregator | ||
def initialize | ||
@buckets = {} | ||
end | ||
|
||
def add(type, | ||
key, | ||
value, | ||
unit, | ||
tags: nil, | ||
timestamp: nil) | ||
# TODO thread check | ||
# TODO timestamp + rollup | ||
# TODO serialize tags | ||
# TODO bucket key | ||
# TODO lock and add to bucket | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
module Metrics | ||
class CounterMetric < Metric | ||
attr_reader :value | ||
|
||
def initialize(value) | ||
@value = value.to_f | ||
end | ||
|
||
def add(value) | ||
@value += value.to_f | ||
end | ||
|
||
def serialize | ||
[value] | ||
end | ||
|
||
def weight | ||
1 | ||
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,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
module Metrics | ||
class DistributionMetric < Metric | ||
attr_reader :value | ||
|
||
def initialize(value) | ||
@value = [value.to_f] | ||
end | ||
|
||
def add(value) | ||
@value << value.to_f | ||
end | ||
|
||
def serialize | ||
value | ||
end | ||
|
||
def weight | ||
value.size | ||
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
module Metrics | ||
class GaugeMetric < Metric | ||
attr_reader :last, :min, :max, :sum, :count | ||
|
||
def initialize(value) | ||
value = value.to_f | ||
@last = value | ||
@min = value | ||
@max = value | ||
@sum = value | ||
@count = 1 | ||
end | ||
|
||
def add(value) | ||
value = value.to_f | ||
@last = value | ||
@min = [@min, value].min | ||
@max = [@max, value].max | ||
@sum += value | ||
@count += 1 | ||
end | ||
|
||
def serialize | ||
[last, min, max, sum, count] | ||
end | ||
|
||
def weight | ||
5 | ||
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
module Metrics | ||
class Metric | ||
def add(value) | ||
raise NotImplementedError | ||
end | ||
|
||
def serialize | ||
raise NotImplementedError | ||
end | ||
|
||
def weight | ||
raise NotImplementedError | ||
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'set' | ||
require 'zlib' | ||
|
||
module Sentry | ||
module Metrics | ||
class SetMetric < Metric | ||
attr_reader :value | ||
|
||
def initialize(value) | ||
@value = Set[value.to_f] | ||
end | ||
|
||
def add(value) | ||
@value << value | ||
end | ||
|
||
def serialize | ||
value.map do |v| | ||
x.is_a?(String) ? Zlib.crc32(x) : x.to_i | ||
end | ||
end | ||
|
||
def weight | ||
value.size | ||
end | ||
end | ||
end | ||
end |