Class: Temporalio::Runtime::MetricBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/runtime/metric_buffer.rb

Overview

Note:

WARNING: It is important that the buffer size is set to a high number and that #retrieve_updates is called regularly to drain the buffer. If the buffer is full, metric updates will be dropped and an error will be logged.

Metric buffer for use with a runtime to capture metrics. Only one metric buffer can be associated with a runtime and #retrieve_updates cannot be called before the runtime is created. Once runtime created, users should regularly call #retrieve_updates to drain the buffer.

Defined Under Namespace

Modules: DurationFormat Classes: Metric, Update

Instance Method Summary collapse

Constructor Details

#initialize(buffer_size, duration_format: DurationFormat::MILLISECONDS) ⇒ MetricBuffer

Note:

WARNING: It is important that the buffer size is set to a high number and is drained regularly. See Temporalio::Runtime::MetricBuffer warning.

Create a metric buffer with the given size.

Parameters:

  • buffer_size (Integer)

    Maximum size of the buffer before metrics will be dropped.

  • duration_format (DurationFormat) (defaults to: DurationFormat::MILLISECONDS)

    How durations are represented.



64
65
66
67
68
# File 'lib/temporalio/runtime/metric_buffer.rb', line 64

def initialize(buffer_size, duration_format: DurationFormat::MILLISECONDS)
  @buffer_size = buffer_size
  @duration_format = duration_format
  @runtime = nil
end

Instance Method Details

#retrieve_updatesArray<Update>

Note:

WARNING: It is important that this is called regularly. See Temporalio::Runtime::MetricBuffer warning.

Drain the buffer and return all metric updates.

Returns:

  • (Array<Update>)

    Updates since last time this was called.



75
76
77
78
79
# File 'lib/temporalio/runtime/metric_buffer.rb', line 75

def retrieve_updates
  raise 'Attempting to retrieve updates before runtime created' unless @runtime

  @runtime._core_runtime.retrieve_buffered_metrics(@duration_format == DurationFormat::SECONDS)
end