Class: OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Metrics::Aggregation::ExplicitBucketHistogram
- Defined in:
- lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb
Overview
Contains the implementation of the ExplicitBucketHistogram aggregation github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#explicit-bucket-histogram-aggregation
Instance Method Summary collapse
- #aggregation_temporality ⇒ Object
- #collect(start_time, end_time, data_points) ⇒ Object
-
#initialize(aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', :cumulative), boundaries: DEFAULT_BOUNDARIES, record_min_max: true) ⇒ ExplicitBucketHistogram
constructor
The default value for boundaries represents the following buckets: (-inf, 0], (0, 5.0], (5.0, 10.0], (10.0, 25.0], (25.0, 50.0], (50.0, 75.0], (75.0, 100.0], (100.0, 250.0], (250.0, 500.0], (500.0, 1000.0], (1000.0, +inf).
- #update(amount, attributes, data_points) ⇒ Object
Constructor Details
#initialize(aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', :cumulative), boundaries: DEFAULT_BOUNDARIES, record_min_max: true) ⇒ ExplicitBucketHistogram
The default value for boundaries represents the following buckets: (-inf, 0], (0, 5.0], (5.0, 10.0], (10.0, 25.0], (25.0, 50.0], (50.0, 75.0], (75.0, 100.0], (100.0, 250.0], (250.0, 500.0], (500.0, 1000.0], (1000.0, +inf)
21 22 23 24 25 26 27 28 29 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb', line 21 def initialize( aggregation_temporality: ENV.fetch('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE', :cumulative), boundaries: DEFAULT_BOUNDARIES, record_min_max: true ) @aggregation_temporality = aggregation_temporality.to_sym == :delta ? AggregationTemporality.delta : AggregationTemporality.cumulative @boundaries = boundaries && !boundaries.empty? ? boundaries.sort : nil @record_min_max = record_min_max end |
Instance Method Details
#aggregation_temporality ⇒ Object
88 89 90 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb', line 88 def aggregation_temporality @aggregation_temporality.temporality end |
#collect(start_time, end_time, data_points) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb', line 31 def collect(start_time, end_time, data_points) if @aggregation_temporality.delta? # Set timestamps and 'move' data point values to result. hdps = data_points.values.map! do |hdp| hdp.start_time_unix_nano = start_time hdp.time_unix_nano = end_time hdp end data_points.clear hdps else # Update timestamps and take a snapshot. data_points.values.map! do |hdp| hdp.start_time_unix_nano ||= start_time # Start time of a data point is from the first observation. hdp.time_unix_nano = end_time hdp = hdp.dup hdp.bucket_counts = hdp.bucket_counts.dup hdp end end end |
#update(amount, attributes, data_points) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/explicit_bucket_histogram.rb', line 53 def update(amount, attributes, data_points) hdp = data_points.fetch(attributes) do if @record_min_max min = Float::INFINITY max = -Float::INFINITY end data_points[attributes] = HistogramDataPoint.new( attributes, nil, # :start_time_unix_nano nil, # :time_unix_nano 0, # :count 0, # :sum empty_bucket_counts, # :bucket_counts @boundaries, # :explicit_bounds nil, # :exemplars min, # :min max # :max ) end if @record_min_max hdp.max = amount if amount > hdp.max hdp.min = amount if amount < hdp.min end hdp.sum += amount hdp.count += 1 if @boundaries bucket_index = @boundaries.bsearch_index { |i| i >= amount } || @boundaries.size hdp.bucket_counts[bucket_index] += 1 end nil end |