class Invoca::Metrics::Prometheus::DeclareMetrics::Base

Attributes

default_labels[R]
graphite[R]
metric[R]
name[R]
source[R]
type[R]

Public Class Methods

new(name, type, source, metric, labels:, graphite:) click to toggle source
# File lib/invoca/metrics/prometheus/declare_metrics/base.rb, line 11
def initialize(name, type, source, metric, labels:, graphite:)
  @name           = name
  @type           = type
  @source         = source
  @metric         = metric
  @default_labels = labels
  @graphite       = graphite

  if labels
    labels.is_a?(Hash) or raise ArgumentError, "Labels must be type Hash but got #{labels.inspect}"
  end
end

Public Instance Methods

reset_metric(new_metric) click to toggle source

TODO: This is temporary; the invoca-metrics metrics objects should be made immutable, in which case the entire object would be replaced rather than resetting the Prometheus metric object as is done here

# File lib/invoca/metrics/prometheus/declare_metrics/base.rb, line 33
def reset_metric(new_metric)
  @metric = new_metric
end
settings() click to toggle source

TODO: Could default_labels be renamed to labels?

# File lib/invoca/metrics/prometheus/declare_metrics/base.rb, line 25
def settings
  { type: type, labels: default_labels, graphite: graphite }
end

Private Instance Methods

render_graphite_string(**labels) click to toggle source
# File lib/invoca/metrics/prometheus/declare_metrics/base.rb, line 39
def render_graphite_string(**labels)
  rendered_string = graphite.dup
  labels.map do |key, value|
    rendered_string.gsub!(":#{key}", value.to_s)
  end

  rendered_string.include?(':') and warn("Graphite string #{rendered_string} not fully rendered. Expecting additional label that has not been rendered.")
  rendered_string
end