Class: Attio::Observability::Metrics::Memory
- Inherits:
-
Object
- Object
- Attio::Observability::Metrics::Memory
- Defined in:
- lib/attio/observability.rb
Overview
In-memory metrics for testing
Instance Attribute Summary collapse
- #counters ⇒ Object readonly
- #gauges ⇒ Object readonly
- #histograms ⇒ Object readonly
Instance Method Summary collapse
- #format_tags(tags) ⇒ Object private
- #gauge(metric, value, tags: {}) ⇒ Object
- #histogram(metric, value, tags: {}) ⇒ Object
- #increment(metric, tags: {}) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
185 186 187 188 189 |
# File 'lib/attio/observability.rb', line 185 def initialize @counters = Hash.new(0) @gauges = {} @histograms = Hash.new { |h, k| h[k] = [] } end |
Instance Attribute Details
#counters ⇒ Object (readonly)
183 184 185 |
# File 'lib/attio/observability.rb', line 183 def counters @counters end |
#gauges ⇒ Object (readonly)
183 184 185 |
# File 'lib/attio/observability.rb', line 183 def gauges @gauges end |
#histograms ⇒ Object (readonly)
183 184 185 |
# File 'lib/attio/observability.rb', line 183 def histograms @histograms end |
Instance Method Details
#format_tags(tags) ⇒ Object (private)
212 213 214 215 216 217 |
# File 'lib/attio/observability.rb', line 212 private def () # Format tags in a consistent way that works across Ruby versions sorted = .sort.to_h content = sorted.map { |k, v| ":#{k}=>#{v.inspect}" }.join(", ") "{#{content}}" end |
#gauge(metric, value, tags: {}) ⇒ Object
196 197 198 199 |
# File 'lib/attio/observability.rb', line 196 def gauge(metric, value, tags: {}) key = .empty? ? "#{metric}:" : "#{metric}:#{format_tags(tags)}" @gauges[key] = value end |
#histogram(metric, value, tags: {}) ⇒ Object
201 202 203 204 |
# File 'lib/attio/observability.rb', line 201 def histogram(metric, value, tags: {}) key = .empty? ? "#{metric}:" : "#{metric}:#{format_tags(tags)}" @histograms[key] << value end |
#increment(metric, tags: {}) ⇒ Object
191 192 193 194 |
# File 'lib/attio/observability.rb', line 191 def increment(metric, tags: {}) key = .empty? ? "#{metric}:" : "#{metric}:#{format_tags(tags)}" @counters[key] += 1 end |
#reset! ⇒ Object
206 207 208 209 210 |
# File 'lib/attio/observability.rb', line 206 def reset! @counters.clear @gauges.clear @histograms.clear end |