Skip to content

Commit f5bec99

Browse files
authored
drop aggregation_temporality method and instance variable for last_value and drop aggregation (#1885)
1 parent 752080a commit f5bec99

File tree

6 files changed

+9
-60
lines changed

6 files changed

+9
-60
lines changed

metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/drop.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ module Metrics
1010
module Aggregation
1111
# Contains the implementation of the Drop aggregation
1212
class Drop
13-
def initialize
14-
@aggregation_temporality = nil
15-
end
16-
1713
def collect(start_time, end_time, data_points)
1814
data_points.values.map!(&:dup)
1915
end
@@ -28,10 +24,6 @@ def update(increment, attributes, data_points)
2824
)
2925
nil
3026
end
31-
32-
def aggregation_temporality
33-
nil
34-
end
3527
end
3628
end
3729
end

metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/last_value.rb

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,14 @@ module Metrics
1010
module Aggregation
1111
# Contains the implementation of the LastValue aggregation
1212
class LastValue
13-
def initialize(aggregation_temporality: :delta)
14-
@aggregation_temporality = aggregation_temporality == :cumulative ? AggregationTemporality.cumulative : AggregationTemporality.delta
15-
end
16-
1713
def collect(start_time, end_time, data_points)
18-
if @aggregation_temporality.delta?
19-
# Set timestamps and 'move' data point values to result.
20-
ndps = data_points.values.map! do |ndp|
21-
ndp.start_time_unix_nano = start_time
22-
ndp.time_unix_nano = end_time
23-
ndp
24-
end
25-
data_points.clear
26-
ndps
27-
else
28-
# Update timestamps and take a snapshot.
29-
data_points.values.map! do |ndp|
30-
ndp.start_time_unix_nano ||= start_time # Start time of a data point is from the first observation.
31-
ndp.time_unix_nano = end_time
32-
ndp.dup
33-
end
14+
ndps = data_points.values.map! do |ndp|
15+
ndp.start_time_unix_nano = start_time
16+
ndp.time_unix_nano = end_time
17+
ndp
3418
end
19+
data_points.clear
20+
ndps
3521
end
3622

3723
def update(increment, attributes, data_points)
@@ -44,10 +30,6 @@ def update(increment, attributes, data_points)
4430
)
4531
nil
4632
end
47-
48-
def aggregation_temporality
49-
@aggregation_temporality.temporality
50-
end
5133
end
5234
end
5335
end

metrics_sdk/lib/opentelemetry/sdk/metrics/state/metric_stream.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def update(value, attributes)
7272
def aggregate_metric_data(start_time, end_time, aggregation: nil)
7373
aggregator = aggregation || @default_aggregation
7474
is_monotonic = aggregator.respond_to?(:monotonic?) ? aggregator.monotonic? : nil
75+
aggregation_temporality = aggregator.respond_to?(:aggregation_temporality) ? aggregator.aggregation_temporality : nil
7576

7677
MetricData.new(
7778
@name,
@@ -81,7 +82,7 @@ def aggregate_metric_data(start_time, end_time, aggregation: nil)
8182
@meter_provider.resource,
8283
@instrumentation_scope,
8384
aggregator.collect(start_time, end_time, @data_points),
84-
aggregator.aggregation_temporality,
85+
aggregation_temporality,
8586
start_time,
8687
end_time,
8788
is_monotonic

metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/last_value_test.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,12 @@
88

99
describe OpenTelemetry::SDK::Metrics::Aggregation::LastValue do
1010
let(:data_points) { {} }
11-
let(:last_value_aggregation) { OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new(aggregation_temporality:) }
12-
let(:aggregation_temporality) { :delta }
11+
let(:last_value_aggregation) { OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new }
1312

1413
# Time in nano
1514
let(:start_time) { (Time.now.to_r * 1_000_000_000).to_i }
1615
let(:end_time) { ((Time.now + 60).to_r * 1_000_000_000).to_i }
1716

18-
describe '#initialize' do
19-
it 'defaults to the delta aggregation temporality' do
20-
exp = OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new
21-
_(exp.aggregation_temporality).must_equal :delta
22-
end
23-
24-
it 'valid aggregation_temporality delta as symbol from parameters' do
25-
exp = OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new(aggregation_temporality: :delta)
26-
_(exp.aggregation_temporality).must_equal :delta
27-
end
28-
29-
it 'valid aggregation_temporality cumulative as symbol from parameters' do
30-
exp = OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new(aggregation_temporality: :cumulative)
31-
_(exp.aggregation_temporality).must_equal :cumulative
32-
end
33-
34-
it 'invalid aggregation_temporality pickles as symbol from parameters return to defaults delta' do
35-
exp = OpenTelemetry::SDK::Metrics::Aggregation::LastValue.new(aggregation_temporality: :pickles)
36-
_(exp.aggregation_temporality).must_equal :delta
37-
end
38-
end
39-
4017
it 'sets the timestamps' do
4118
last_value_aggregation.update(0, {}, data_points)
4219
ndp = last_value_aggregation.collect(start_time, end_time, data_points)[0]

metrics_sdk/test/opentelemetry/sdk/metrics/instrument/gauge_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
_(last_snapshot[0].instrumentation_scope.name).must_equal('test')
2929
_(last_snapshot[0].data_points[0].attributes).must_equal('foo' => 'bar')
3030
_(last_snapshot[0].data_points[0].value).must_equal(-2)
31-
_(last_snapshot[0].aggregation_temporality).must_equal(:delta)
3231
end
3332

3433
it 'gauge should count 1 for last recording' do

metrics_sdk/test/opentelemetry/sdk/metrics/instrument/observable_gauge_test.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
_(last_snapshot[0].instrumentation_scope.name).must_equal('test')
3030
_(last_snapshot[0].data_points[0].value).must_equal(10)
3131
_(last_snapshot[0].data_points[0].attributes).must_equal({})
32-
_(last_snapshot[0].aggregation_temporality).must_equal(:delta)
3332
end
3433

3534
it 'counts with observe' do
@@ -49,6 +48,5 @@
4948

5049
_(last_snapshot[0].data_points[1].value).must_equal(10)
5150
_(last_snapshot[0].data_points[1].attributes).must_equal({})
52-
_(last_snapshot[0].aggregation_temporality).must_equal(:delta)
5351
end
5452
end

0 commit comments

Comments
 (0)