Sha256: 4d62a5bbc4762582e3cca14f391426f30a7cda1bd3bbb7706e4361d8b0877d9a

Contents?: true

Size: 615 Bytes

Versions: 2

Compression:

Stored size: 615 Bytes

Contents

# frozen_string_literal: true

class Async::App::WebServer::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

2 entries across 2 versions & 1 rubygems

Version Path
async-tools-0.2.9 lib/async/app/web_server/metrics_app/serializer.rb
async-tools-0.2.8 lib/async/app/web_server/metrics_app/serializer.rb