Class: RoutesAlerts::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/routes_alerts/metrics/base.rb

Direct Known Subclasses

Count, Duration, SuccessRate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, route_info) ⇒ Base



4
5
6
7
# File 'lib/routes_alerts/metrics/base.rb', line 4

def initialize(config, route_info)
  @config = config
  @route_info = route_info
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



2
3
4
# File 'lib/routes_alerts/metrics/base.rb', line 2

def config
  @config
end

#route_infoObject (readonly)

Returns the value of attribute route_info.



2
3
4
# File 'lib/routes_alerts/metrics/base.rb', line 2

def route_info
  @route_info
end

Instance Method Details

#actionsObject



34
35
36
# File 'lib/routes_alerts/metrics/base.rb', line 34

def actions
  route_info.actions.any? ? route_info.actions : nil
end

#alarm_paramsObject

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/routes_alerts/metrics/base.rb', line 13

def alarm_params
  raise NotImplementedError, "Subclasses must implement the alarm_params method"
end

#create!Object



17
18
19
20
# File 'lib/routes_alerts/metrics/base.rb', line 17

def create!
  config.cloudwatch_logs.put_metric_filter(metric_params)
  config.cloudwatch.put_metric_alarm(alarm_params)
end

#log_group_nameObject



22
23
24
# File 'lib/routes_alerts/metrics/base.rb', line 22

def log_group_name
  route_info.log_group_name
end

#metric_paramsObject

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/routes_alerts/metrics/base.rb', line 9

def metric_params
  raise NotImplementedError, "Subclasses must implement the metric_params method"
end

#namespaceObject



26
27
28
# File 'lib/routes_alerts/metrics/base.rb', line 26

def namespace
  route_info.namespace
end

#prefixObject



38
39
40
41
42
43
44
# File 'lib/routes_alerts/metrics/base.rb', line 38

def prefix
  if route_info.prefix.empty?
    ""
  else
    "#{route_info.prefix}-"
  end
end

#route_nameObject



30
31
32
# File 'lib/routes_alerts/metrics/base.rb', line 30

def route_name
  "#{route_info.method}-#{route_info.path.gsub("/", "_").gsub("{", "").gsub("}", "")}"
end