Skip to content

Commit 2d6d936

Browse files
committed
it fixes metrics overflow, causing time bug
1 parent b28cf18 commit 2d6d936

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ There are four different types of metrics:
105105

106106
t = Time.now
107107
Stackify::Metrics.time "MyCategory", "ElapsedTime", t
108+
# or
109+
Stackify::Metrics.time_duration "MyCategory", "ElapsedTime", 5.seconds
108110

109111
- **Counter and Timer**: Composite of the Counter and Timer metrics for convenience
110112

lib/stackify/metrics/metrics_client.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def start_upload_metrics
6161
read_queued_metrics_batch current_time
6262
handle_zero_reports current_time
6363

64-
selected_aggr_metrics = @aggregate_metrics.select { |_key, aggr| aggr.occurred_utc < current_time }
64+
selected_aggr_metrics = @aggregate_metrics.select { |_key, aggr| aggr.occurred_utc.to_i < current_time.to_i && !aggr.sent }
6565
first_50_metrics = Hash[selected_aggr_metrics.to_a.take 50]
6666
if first_50_metrics.length > 0
6767
#only getting metrics less than 10 minutes old to drop old data in case we get backed up
@@ -111,7 +111,7 @@ def handle_zero_reports current_time
111111
@metric_settings.delete[aggregate.name_key]
112112
next
113113
end
114-
agg = aggregate.dup
114+
agg = aggregate.clone
115115
agg.occurred_utc = current_time
116116

117117
disabled_autoreport_last = [
@@ -182,12 +182,12 @@ def upload_aggregates aggr_metrics
182182
else
183183
metric.monitor_id = mon_info['MonitorID']
184184
end
185-
186-
#get identified once
187-
aggr_metrics_for_upload = aggr_metrics.select { |_key, aggr_metric| !aggr_metric.monitor_id.nil? }
188-
@metrics_sender.upload_metrics aggr_metrics_for_upload
189-
all_success
190185
end
186+
187+
#get identified once
188+
aggr_metrics_for_upload = aggr_metrics.select { |_key, aggr_metric| !aggr_metric.monitor_id.nil? }
189+
@metrics_sender.upload_metrics aggr_metrics_for_upload
190+
all_success
191191
end
192192
end
193193
end

0 commit comments

Comments
 (0)