Class: Anomonitor::MetricPoint

Inherits:
Struct
  • Object
show all
Defined in:
lib/anomonitor/metric_point.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, metric:, value:, tags: {}, sampled_at: Time.current) ⇒ MetricPoint

Returns a new instance of MetricPoint.



7
8
9
10
11
12
13
14
15
# File 'lib/anomonitor/metric_point.rb', line 7

def initialize(source:, metric:, value:, tags: {}, sampled_at: Time.current)
  super(
    source: source.to_s,
    metric: metric.to_s,
    value: value.to_f,
    tags: tags || {},
    sampled_at: sampled_at
  )
end

Instance Attribute Details

#metricObject

Returns the value of attribute metric

Returns:

  • (Object)

    the current value of metric



6
7
8
# File 'lib/anomonitor/metric_point.rb', line 6

def metric
  @metric
end

#sampled_atObject

Returns the value of attribute sampled_at

Returns:

  • (Object)

    the current value of sampled_at



6
7
8
# File 'lib/anomonitor/metric_point.rb', line 6

def sampled_at
  @sampled_at
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



6
7
8
# File 'lib/anomonitor/metric_point.rb', line 6

def source
  @source
end

#tagsObject

Returns the value of attribute tags

Returns:

  • (Object)

    the current value of tags



6
7
8
# File 'lib/anomonitor/metric_point.rb', line 6

def tags
  @tags
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



6
7
8
# File 'lib/anomonitor/metric_point.rb', line 6

def value
  @value
end

Instance Method Details

#cooldown_keyObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/anomonitor/metric_point.rb', line 21

def cooldown_key
  tenant = tags[:tenant] || tags["tenant"]
  queue = tags[:queue] || tags["queue"]
  parts = [source, metric, tenant, queue]
  if sticky?
    digest = sticky_items_digest
    parts << digest if digest
  end
  parts.compact.join(":")
end

#sticky?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/anomonitor/metric_point.rb', line 17

def sticky?
  source == "schema_drift"
end

#sticky_items_digestObject



32
33
34
35
36
37
38
39
40
# File 'lib/anomonitor/metric_point.rb', line 32

def sticky_items_digest
  digest = tags[:items_digest] || tags["items_digest"]
  return digest.to_s if digest && !digest.to_s.empty?

  items = tags[:items] || tags["items"]
  return nil if items.nil? || items.to_s.empty?

  Digest::SHA256.hexdigest(items.to_s)[0, 16]
end