mysql_framework 2.1.8 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mysql_framework/connector.rb +124 -85
- data/lib/mysql_framework/mysql_connection_pool.rb +176 -0
- data/lib/mysql_framework/scripts/manager.rb +1 -1
- data/lib/mysql_framework/sql_query.rb +7 -1
- data/lib/mysql_framework/stats/aws_metric_publisher.rb +124 -0
- data/lib/mysql_framework/stats/dimension_map.rb +51 -0
- data/lib/mysql_framework/version.rb +1 -1
- data/spec/lib/mysql_framework/connector_spec.rb +125 -148
- data/spec/lib/mysql_framework/mysql_connection_pool_spec.rb +239 -0
- data/spec/lib/mysql_framework/sql_query_spec.rb +27 -0
- data/spec/lib/mysql_framework/stats/aws_metric_publisher_spec.rb +89 -0
- data/spec/support/fixtures.rb +10 -0
- metadata +47 -14
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'mysql_framework/stats/aws_metric_publisher'
|
|
5
|
+
|
|
6
|
+
describe MysqlFramework::Stats::AwsMetricPublisher do
|
|
7
|
+
let(:connection_pool) { instance_double(MysqlFramework::MysqlConnectionPool, pool_stats: stats) }
|
|
8
|
+
let(:connector) { instance_double(MysqlFramework::Connector, connection_pool: connection_pool) }
|
|
9
|
+
let(:stats) { { size: 5, available: 3, idle: 2 } }
|
|
10
|
+
let(:dimensions) do
|
|
11
|
+
[
|
|
12
|
+
{ name: 'ServiceName', value: 'mysql-framework' },
|
|
13
|
+
{ name: 'Environment', value: 'test' }
|
|
14
|
+
]
|
|
15
|
+
end
|
|
16
|
+
let(:dimension_map) do
|
|
17
|
+
instance_double(
|
|
18
|
+
MysqlFramework::Stats::DimensionMap,
|
|
19
|
+
namespace: 'MysqlFramework',
|
|
20
|
+
to_cloudwatch_dimensions: dimensions
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
let(:cloudwatch_client) { instance_double(Aws::CloudWatch::Client) }
|
|
24
|
+
let(:logger) { instance_double(Logger, debug: nil, error: nil) }
|
|
25
|
+
|
|
26
|
+
subject(:reporter) do
|
|
27
|
+
described_class.new(
|
|
28
|
+
connector: connector,
|
|
29
|
+
dimension_map: dimension_map,
|
|
30
|
+
cloudwatch_client: cloudwatch_client,
|
|
31
|
+
publish_interval: 1
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
before do
|
|
36
|
+
allow(MysqlFramework).to receive(:logger).and_return(logger)
|
|
37
|
+
allow(ENV).to receive(:fetch).and_call_original
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#sample' do
|
|
41
|
+
it 'publishes connector pool stats to CloudWatch' do
|
|
42
|
+
expect(cloudwatch_client).to receive(:put_metric_data) do |payload|
|
|
43
|
+
expect(payload[:namespace]).to eq('MysqlFramework')
|
|
44
|
+
expect(payload[:metric_data].size).to eq(3)
|
|
45
|
+
|
|
46
|
+
size_metric = payload[:metric_data].find { |metric| metric[:metric_name] == 'MysqlConnectionPoolSize' }
|
|
47
|
+
available_metric = payload[:metric_data].find { |metric| metric[:metric_name] == 'MysqlConnectionPoolAvailable' }
|
|
48
|
+
idle_metric = payload[:metric_data].find { |metric| metric[:metric_name] == 'MysqlConnectionPoolIdle' }
|
|
49
|
+
|
|
50
|
+
expect(size_metric[:value]).to eq(5.0)
|
|
51
|
+
expect(available_metric[:value]).to eq(3.0)
|
|
52
|
+
expect(idle_metric[:value]).to eq(2.0)
|
|
53
|
+
expect(size_metric[:dimensions]).to eq(dimensions)
|
|
54
|
+
expect(size_metric[:unit]).to eq('Count')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
reporter.send(:sample)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'does not publish when connector is nil' do
|
|
61
|
+
subject = described_class.new(
|
|
62
|
+
connector: nil,
|
|
63
|
+
dimension_map: dimension_map,
|
|
64
|
+
cloudwatch_client: cloudwatch_client
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
expect(cloudwatch_client).not_to receive(:put_metric_data)
|
|
68
|
+
|
|
69
|
+
subject.send(:sample)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'logs an error when cloudwatch publish raises' do
|
|
73
|
+
allow(cloudwatch_client).to receive(:put_metric_data).and_raise(StandardError, 'aws unavailable')
|
|
74
|
+
expect(logger).to receive(:error)
|
|
75
|
+
|
|
76
|
+
reporter.send(:sample)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe '#build_metric_data' do
|
|
81
|
+
it 'skips nil values in stats map' do
|
|
82
|
+
data = reporter.send(:build_metric_data, size: 1, available: nil, idle: 0)
|
|
83
|
+
|
|
84
|
+
expect(data.size).to eq(2)
|
|
85
|
+
names = data.map { |metric| metric[:metric_name] }
|
|
86
|
+
expect(names).to contain_exactly('MysqlConnectionPoolSize', 'MysqlConnectionPoolIdle')
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
data/spec/support/fixtures.rb
CHANGED
|
@@ -39,6 +39,16 @@ module MysqlFramework
|
|
|
39
39
|
SQL
|
|
40
40
|
|
|
41
41
|
connector.check_in(client)
|
|
42
|
+
connector.dispose
|
|
43
|
+
|
|
44
|
+
connector = MysqlFramework::Connector.new(
|
|
45
|
+
host: ENV.fetch('MYSQL_HOST'),
|
|
46
|
+
port: ENV.fetch('MYSQL_PORT'),
|
|
47
|
+
database: ENV.fetch('MYSQL_DATABASE'),
|
|
48
|
+
username: ENV.fetch('MYSQL_USERNAME'),
|
|
49
|
+
password: ENV.fetch('MYSQL_PASSWORD')
|
|
50
|
+
)
|
|
51
|
+
connector.setup
|
|
42
52
|
|
|
43
53
|
manager = MysqlFramework::Scripts::Manager.new(connector)
|
|
44
54
|
manager.execute
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mysql_framework
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sage
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-05-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rspec
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,20 +52,48 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: aws-sdk-cloudwatch
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: connection_pool
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
55
83
|
- !ruby/object:Gem::Dependency
|
|
56
84
|
name: mysql2
|
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
|
58
86
|
requirements:
|
|
59
|
-
- - "
|
|
87
|
+
- - ">="
|
|
60
88
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0
|
|
89
|
+
version: '0'
|
|
62
90
|
type: :runtime
|
|
63
91
|
prerelease: false
|
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
93
|
requirements:
|
|
66
|
-
- - "
|
|
94
|
+
- - ">="
|
|
67
95
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0
|
|
96
|
+
version: '0'
|
|
69
97
|
- !ruby/object:Gem::Dependency
|
|
70
98
|
name: redlock
|
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -91,6 +119,7 @@ files:
|
|
|
91
119
|
- lib/mysql_framework/connector.rb
|
|
92
120
|
- lib/mysql_framework/in_condition.rb
|
|
93
121
|
- lib/mysql_framework/logger.rb
|
|
122
|
+
- lib/mysql_framework/mysql_connection_pool.rb
|
|
94
123
|
- lib/mysql_framework/scripts.rb
|
|
95
124
|
- lib/mysql_framework/scripts/base.rb
|
|
96
125
|
- lib/mysql_framework/scripts/lock_manager.rb
|
|
@@ -100,9 +129,12 @@ files:
|
|
|
100
129
|
- lib/mysql_framework/sql_condition.rb
|
|
101
130
|
- lib/mysql_framework/sql_query.rb
|
|
102
131
|
- lib/mysql_framework/sql_table.rb
|
|
132
|
+
- lib/mysql_framework/stats/aws_metric_publisher.rb
|
|
133
|
+
- lib/mysql_framework/stats/dimension_map.rb
|
|
103
134
|
- lib/mysql_framework/version.rb
|
|
104
135
|
- spec/lib/mysql_framework/connector_spec.rb
|
|
105
136
|
- spec/lib/mysql_framework/logger_spec.rb
|
|
137
|
+
- spec/lib/mysql_framework/mysql_connection_pool_spec.rb
|
|
106
138
|
- spec/lib/mysql_framework/scripts/base_spec.rb
|
|
107
139
|
- spec/lib/mysql_framework/scripts/lock_manager_spec.rb
|
|
108
140
|
- spec/lib/mysql_framework/scripts/manager_spec.rb
|
|
@@ -110,6 +142,7 @@ files:
|
|
|
110
142
|
- spec/lib/mysql_framework/sql_condition_spec.rb
|
|
111
143
|
- spec/lib/mysql_framework/sql_query_spec.rb
|
|
112
144
|
- spec/lib/mysql_framework/sql_table_spec.rb
|
|
145
|
+
- spec/lib/mysql_framework/stats/aws_metric_publisher_spec.rb
|
|
113
146
|
- spec/spec_helper.rb
|
|
114
147
|
- spec/support/fixtures.rb
|
|
115
148
|
- spec/support/procedure.sql
|
|
@@ -122,7 +155,7 @@ homepage: https://github.com/sage/mysql_framework
|
|
|
122
155
|
licenses:
|
|
123
156
|
- MIT
|
|
124
157
|
metadata: {}
|
|
125
|
-
post_install_message:
|
|
158
|
+
post_install_message:
|
|
126
159
|
rdoc_options: []
|
|
127
160
|
require_paths:
|
|
128
161
|
- lib
|
|
@@ -137,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
137
170
|
- !ruby/object:Gem::Version
|
|
138
171
|
version: '0'
|
|
139
172
|
requirements: []
|
|
140
|
-
rubygems_version: 3.
|
|
141
|
-
signing_key:
|
|
173
|
+
rubygems_version: 3.4.20
|
|
174
|
+
signing_key:
|
|
142
175
|
specification_version: 4
|
|
143
176
|
summary: A lightweight framework to provide managers for working with MySQL.
|
|
144
177
|
test_files: []
|