Sha256: 5da0b1f748244bc84b2d110491a914eb4d3a0c8c2b54605b5cd079ab56612af3

Contents?: true

Size: 613 Bytes

Versions: 1

Compression:

Stored size: 613 Bytes

Contents

# frozen_string_literal: true

class Async::App::WebApps::MetricsApp::Serializer
  def initialize(prefix:, store:)
    @prefix = prefix
    @store = store
  end

  def serialize
    @store.flat_map { metric_line(_1) }
          .compact
          .join("\n")
          .then { "#{_1}\n" }
  end

  def metric_name(value) = "#{@prefix}_#{value[:name]}_#{value[:suffix]}"

  def metric_labels(value) = value[:labels].map { |tag, tag_value| "#{tag}=#{tag_value.to_s.inspect}" }.join(",")

  def metric_line(value)
    "#{metric_name(value)}{#{metric_labels(value)}} #{value[:value]}" if value.key?(:value)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
async-tools-0.2.10 lib/async/app/web_apps/metrics_app/serializer.rb