Class: Flare::MetricKey

Inherits:
Object
  • Object
show all
Defined in:
lib/flare/metric_key.rb

Overview

Identifies a unique metric for aggregation. Immutable and hashable for use as Concurrent::Map keys.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket:, namespace:, service:, target:, operation:) ⇒ MetricKey

Returns a new instance of MetricKey.



9
10
11
12
13
14
15
16
# File 'lib/flare/metric_key.rb', line 9

def initialize(bucket:, namespace:, service:, target:, operation:)
  @bucket = bucket
  @namespace = namespace.to_s.freeze
  @service = service.to_s.freeze
  @target = target&.to_s&.freeze
  @operation = operation.to_s.freeze
  freeze
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



7
8
9
# File 'lib/flare/metric_key.rb', line 7

def bucket
  @bucket
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/flare/metric_key.rb', line 7

def namespace
  @namespace
end

#operationObject (readonly)

Returns the value of attribute operation.



7
8
9
# File 'lib/flare/metric_key.rb', line 7

def operation
  @operation
end

#serviceObject (readonly)

Returns the value of attribute service.



7
8
9
# File 'lib/flare/metric_key.rb', line 7

def service
  @service
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/flare/metric_key.rb', line 7

def target
  @target
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/flare/metric_key.rb', line 18

def eql?(other)
  self.class.eql?(other.class) &&
    bucket == other.bucket &&
    namespace == other.namespace &&
    service == other.service &&
    target == other.target &&
    operation == other.operation
end

#hashObject



28
29
30
# File 'lib/flare/metric_key.rb', line 28

def hash
  [self.class, bucket, namespace, service, target, operation].hash
end

#to_hObject



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

def to_h
  {
    bucket: bucket,
    namespace: namespace,
    service: service,
    target: target,
    operation: operation
  }
end