cloudwatch-metrics 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb532d3ef368646603acb0246884a36c398dd42b8bcd17cfe9aad3c69dabe8b4
4
- data.tar.gz: b3f06ecce07db061df5d992eb847c82ae28ff704f4649d5f6bdd8bc720519c3f
3
+ metadata.gz: c05a115e1d85721a94703a582811740101ded81e2eaab2bbbbf6812a28d5d02e
4
+ data.tar.gz: 9cc9c8113894d10d20592206c4c0131e281e3b8973be026f3d9c7d907dca6b98
5
5
  SHA512:
6
- metadata.gz: 39104d7d1796b1fd74a65ad98df38f81f84d635370d71aefb27bc851de97543b07061efa4a51ddb7468bc3190305517dde60f251d383e24a03e9abfadfc59931
7
- data.tar.gz: ba0a2202fde50efd5fe08e3cd641653901955281b60b30d4a9dbca488268183c3f2520b3dcf265cb7afb69213292f36b72c113b9680afa6a745c84d007505ac0
6
+ metadata.gz: c3d062eff18b802d34fb9b1126d52297832d339beac6dfc0db6af23ebe131c0c11b28281140e9bd8f631943ad625ce7f1160409d8c2aad36c8941abcaa0e79cd
7
+ data.tar.gz: 600219d188edd77b5969fbfafe3633ed888abba04afc40edb43e99f06189b5b1cdf155c5056ebdf5ffcfd99126e2f4f5571ab05cefefdd76b4932fa117f2848d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudwatch-metrics (1.0.0)
4
+ cloudwatch-metrics (1.1.2)
5
5
  activesupport (~> 7.0)
6
6
  aws-sdk-cloudwatch (~> 1.73)
7
7
  rake (~> 13.0)
@@ -16,7 +16,7 @@ GEM
16
16
  tzinfo (~> 2.0)
17
17
  ast (2.4.2)
18
18
  aws-eventstream (1.2.0)
19
- aws-partitions (1.780.0)
19
+ aws-partitions (1.781.0)
20
20
  aws-sdk-cloudwatch (1.75.0)
21
21
  aws-sdk-core (~> 3, >= 3.174.0)
22
22
  aws-sigv4 (~> 1.1)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudwatchMetrics
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.2'
5
5
  end
@@ -45,6 +45,8 @@ module CloudwatchMetrics
45
45
  timestamp: timestamp
46
46
  }]
47
47
  put_data(namespace: full_namespace(namespace), metric_data: metric_data)
48
+ rescue StandardError => e
49
+ handle_error(e)
48
50
  end
49
51
 
50
52
  def record_all(
@@ -59,6 +61,8 @@ module CloudwatchMetrics
59
61
  timestamp: timestamp
60
62
  }]
61
63
  put_data(namespace: full_namespace(namespace), metric_data: metric_data)
64
+ rescue StandardError => e
65
+ handle_error(e)
62
66
  end
63
67
 
64
68
  private
@@ -71,8 +75,6 @@ module CloudwatchMetrics
71
75
  end
72
76
 
73
77
  nil
74
- rescue StandardError => e
75
- handle_error(e)
76
78
  end
77
79
 
78
80
  def cloudwatch_client
@@ -90,20 +92,19 @@ module CloudwatchMetrics
90
92
  end
91
93
 
92
94
  # convert key/value hash to format expected by AWS SDK
95
+ # ignore any keys with blank values
93
96
  def map_dimensions(dimensions)
94
97
  combined_dimensions = (configuration.default_dimensions || {}).merge(dimensions || {})
95
98
 
96
99
  mapped_values = []
97
100
  combined_dimensions.keys.each do |key|
98
- mapped_values << {
99
- name: key.to_s,
100
- value: combined_dimensions[key]
101
- }
101
+ mapped_values << {name: key.to_s, value: combined_dimensions[key]} if combined_dimensions[key].present?
102
102
  end
103
103
 
104
104
  mapped_values
105
105
  end
106
106
 
107
+ # handle error by calling configured error handler or logging and raising
107
108
  def handle_error(error)
108
109
  if !configuration.error_handler.nil?
109
110
  configuration.error_handler.call(error)
@@ -114,9 +115,10 @@ module CloudwatchMetrics
114
115
  raise CloudwatchMetrics::Error, error.message
115
116
  end
116
117
 
118
+ # get namespace from configuration or use provided value and apply non-production prefix if applicable
117
119
  def full_namespace(provided_namespace)
118
120
  constructed_namespace = provided_namespace || configuration.namespace
119
- raise CloudwatchMetrics::Error, 'Namespace must be provided' if constructed_namespace.nil?
121
+ raise CloudwatchMetrics::Error, 'Namespace must be provided' if constructed_namespace.blank?
120
122
 
121
123
  if environment != 'production' && configuration.non_production_prefix.present?
122
124
  constructed_namespace = configuration.non_production_prefix + constructed_namespace
@@ -35,7 +35,7 @@ CloudwatchMetrics.configure do |config|
35
35
 
36
36
  # This is an optional configuration to set the namespace prefix for non-production
37
37
  # environments. This is useful if you want to avoid polluting your production
38
- # metrics with test data. Defaults to 'test-'.
38
+ # metrics with test data. If empty or nil no prefix will be applied. Defaults to 'test-'.
39
39
  # config.non_production_prefix = 'test-'
40
40
 
41
41
  # This is an optional configuration to set an error handler proc.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudwatch-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Puckett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-20 00:00:00.000000000 Z
11
+ date: 2023-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport