Class: Fluent::Plugin::JsonSizeLimit::Telemetry
- Inherits:
-
Object
- Object
- Fluent::Plugin::JsonSizeLimit::Telemetry
- Defined in:
- lib/fluent/plugin/json_size_limit/telemetry.rb
Constant Summary collapse
- DEFINITIONS =
{ oversized_records: "Number of records exceeding max_size", reduced_records: "Number of oversized records reduced to max_size", unreducible_records: "Number of records whose immutable JSON exceeds max_size", error_records: "Number of records that failed measurement or reduction", dropped_records: "Number of records dropped by configured actions", processing_limit_records: "Number of records stopped by automatic safety limits", unsupported_records: "Number of records containing unsupported Ruby value classes", removed_bytes: "Total JSON bytes removed from oversized records" }.freeze
Instance Method Summary collapse
- #increment(name, amount = 1) ⇒ Object
-
#initialize(&metric_factory) ⇒ Telemetry
constructor
A new instance of Telemetry.
- #record_error(error) ⇒ Object
- #statistics ⇒ Object
Constructor Details
#initialize(&metric_factory) ⇒ Telemetry
Returns a new instance of Telemetry.
20 21 22 23 24 25 26 27 28 |
# File 'lib/fluent/plugin/json_size_limit/telemetry.rb', line 20 def initialize(&metric_factory) raise ArgumentError, "metric factory block is required" unless metric_factory @metrics = DEFINITIONS.to_h do |name, help_text| metric = metric_factory.call(name.to_s, help_text) validate_metric!(name, metric) [name, metric] end end |
Instance Method Details
#increment(name, amount = 1) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/json_size_limit/telemetry.rb', line 30 def increment(name, amount = 1) unless amount.is_a?(Integer) && amount.positive? raise ArgumentError, "metric increment must be a positive integer" end metric = @metrics.fetch(name) (amount == 1) ? metric.inc : metric.add(amount) end |
#record_error(error) ⇒ Object
39 40 41 42 43 |
# File 'lib/fluent/plugin/json_size_limit/telemetry.rb', line 39 def record_error(error) increment(:error_records) increment(:processing_limit_records) if error.is_a?(ProcessingLimitError) || error.is_a?(CyclicRecordError) increment(:unsupported_records) if error.is_a?(UnsupportedRecordError) end |
#statistics ⇒ Object
45 46 47 |
# File 'lib/fluent/plugin/json_size_limit/telemetry.rb', line 45 def statistics @metrics.transform_keys(&:to_s).transform_values(&:get) end |