Skip to content

Commit

Permalink
change aggr to last value and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Nov 4, 2024
1 parent dc1e4c9 commit a93ffdc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def record(value, attributes: {})

# TODO: replace the default aggregation to LastValue
def default_aggregation
OpenTelemetry::SDK::Metrics::Aggregation::Sum.new
OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
it 'gauge should count -2' do
gauge.record(-2, attributes: { 'foo' => 'bar' })
metric_exporter.pull
last_snapshot = metric_exporter.metric_snapshots.last
last_snapshot = metric_exporter.metric_snapshots

_(last_snapshot[0].name).must_equal('gauge')
_(last_snapshot[0].unit).must_equal('smidgen')
Expand All @@ -30,4 +30,29 @@
_(last_snapshot[0].data_points[0].value).must_equal(-2)
_(last_snapshot[0].aggregation_temporality).must_equal(:delta)
end

it 'gauge should count 1 for last recording' do
gauge.record(-2, attributes: { 'foo' => 'bar' })
gauge.record(1, attributes: { 'foo' => 'bar' })
metric_exporter.pull
last_snapshot = metric_exporter.metric_snapshots

_(last_snapshot.size).must_equal(1)
_(last_snapshot[0].data_points.size).must_equal(1)
_(last_snapshot[0].data_points[0].value).must_equal(1)
end

it 'gauge should count 1 for last recording' do
gauge.record(-2, attributes: { 'foo' => 'bar' })
gauge.record(1, attributes: { 'foo' => 'bar' })
gauge2 = meter.create_gauge('gauge2', unit: 'smidgen', description: 'a small amount of something')
gauge2.record(10, attributes: {})

metric_exporter.pull
last_snapshot = metric_exporter.metric_snapshots

_(last_snapshot.size).must_equal(2)
_(last_snapshot[0].data_points[0].value).must_equal(1)
_(last_snapshot[1].data_points[0].value).must_equal(10)
end
end

0 comments on commit a93ffdc

Please sign in to comment.