process_metrics_activerecord 0.1.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 +7 -0
- data/README.md +1 -0
- data/lib/process_metrics/persistence/active_record.rb +29 -0
- data/lib/process_metrics/persistence/active_record/metric.rb +8 -0
- data/lib/process_metrics/persistence/active_record/migration.rb +21 -0
- data/lib/process_metrics/persistence/version.rb +7 -0
- data/lib/process_metrics_activerecord.rb +7 -0
- data/test/test_simple.rb +159 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 80cd1a3f50fbee3ef9269339108eddaf6fab8540
|
4
|
+
data.tar.gz: da628822038403b92fda381e6bab6ff879040c4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e1e4f95e5bbd2bfdf21f0e633351c28cc12552cb5371d5d7ebfe442985acb4282867fbf1ecbcf586d4e4e6bfa689343182d6cc24de88d90d4b56ca5825fb764
|
7
|
+
data.tar.gz: 42047ca458f9fb2949247ca5fcde9522a45231ac95f56675e91c60bcd9666251a786fc196598050e219bfedf2f4115bd3565e52a120754927a88d43da22b1383
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
[](https://codeclimate.com/github/locaweb/process_metrics_activerecord)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'process_metrics/persistence/active_record/metric'
|
3
|
+
require 'process_metrics/persistence/active_record/migration'
|
4
|
+
|
5
|
+
module ProcessMetrics
|
6
|
+
module Persistence
|
7
|
+
module ActiveRecord
|
8
|
+
def self.table_name=(table_name)
|
9
|
+
ProcessMetrics::Persistence::ActiveRecord::Metric.table_name = table_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.connection=(connection_info)
|
13
|
+
::ActiveRecord::Base.establish_connection(connection_info)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.setup!
|
17
|
+
::ActiveRecord::Base.connection_pool.with_connection do
|
18
|
+
ProcessMetrics::Persistence::ActiveRecord::Migration.new.change
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.save metric
|
23
|
+
::ActiveRecord::Base.connection_pool.with_connection do
|
24
|
+
Metric.create metric.attributes
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ProcessMetrics
|
2
|
+
module Persistence
|
3
|
+
module ActiveRecord
|
4
|
+
class Migration < ::ActiveRecord::Migration
|
5
|
+
def change
|
6
|
+
table_name = ProcessMetrics::Persistence::ActiveRecord::Metric.table_name
|
7
|
+
create_table(table_name, id: false) do |t|
|
8
|
+
t.string :uuid, :parent_uuid, limit: 36
|
9
|
+
t.string :name
|
10
|
+
t.text :data
|
11
|
+
t.datetime :started_at, :finished_at, limit: 6
|
12
|
+
|
13
|
+
t.timestamps(6)
|
14
|
+
end
|
15
|
+
add_index table_name.to_sym, :uuid
|
16
|
+
add_index table_name.to_sym, :parent_uuid
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'process_metrics'
|
2
|
+
require 'process_metrics/persistence/active_record'
|
3
|
+
|
4
|
+
::Time::DATE_FORMATS[:db] = "%Y-%m-%d %H:%M:%S.%N"
|
5
|
+
ProcessMetrics.config.persistence = ProcessMetrics::Persistence::ActiveRecord
|
6
|
+
ProcessMetrics.config.active_record = Hashie::Mash.new
|
7
|
+
ProcessMetrics.config.active_record.connection = nil
|
data/test/test_simple.rb
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require 'process_metrics_activerecord'
|
4
|
+
|
5
|
+
ProcessMetrics::Persistence::ActiveRecord.connection = {
|
6
|
+
adapter: "sqlite3",
|
7
|
+
database: "process_metrics_test.sqlite3"
|
8
|
+
}
|
9
|
+
|
10
|
+
# ProcessMetrics::Persistence::ActiveRecord.table_name = 'onon'
|
11
|
+
ProcessMetrics::Persistence::ActiveRecord.setup!
|
12
|
+
|
13
|
+
class MyClass
|
14
|
+
include ProcessMetrics::Timer
|
15
|
+
measure :do_simple_work,
|
16
|
+
:do_work_with_params,
|
17
|
+
:do_work_with_block,
|
18
|
+
:do_work_with_params_and_block
|
19
|
+
|
20
|
+
attr_accessor :my_var
|
21
|
+
|
22
|
+
def initialize(my_var)
|
23
|
+
@my_var = my_var
|
24
|
+
end
|
25
|
+
|
26
|
+
def do_simple_work
|
27
|
+
@my_var += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def do_work_with_block(&block)
|
31
|
+
block.call(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def do_work_with_params(user_id)
|
35
|
+
@my_var += user_id + 3
|
36
|
+
end
|
37
|
+
|
38
|
+
def do_work_with_params_and_block(user_id, &block)
|
39
|
+
@my_var += user_id + 5
|
40
|
+
block.call self
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
class MyChildSymbolClass
|
46
|
+
include ProcessMetrics::Timer
|
47
|
+
measure :do_simple_work,
|
48
|
+
parent_uuid: :parent_object_uuid
|
49
|
+
|
50
|
+
attr_accessor :my_var
|
51
|
+
|
52
|
+
def initialize(my_var)
|
53
|
+
@my_var = my_var
|
54
|
+
end
|
55
|
+
|
56
|
+
def do_simple_work
|
57
|
+
@my_var += 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def parent_object_uuid
|
61
|
+
"fe51cfe1-114f-4516-8c5f-e488e48c3778"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class MyChildProcClass
|
66
|
+
include ProcessMetrics::Timer
|
67
|
+
measure :do_simple_work,
|
68
|
+
parent_uuid: -> { "b0d50400-cae0-4cc4-b289-f487d3c9b397" }
|
69
|
+
|
70
|
+
attr_accessor :my_var
|
71
|
+
|
72
|
+
def initialize(my_var)
|
73
|
+
@my_var = my_var
|
74
|
+
end
|
75
|
+
|
76
|
+
def do_simple_work
|
77
|
+
@my_var += 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class MyChildStringClass
|
82
|
+
include ProcessMetrics::Timer
|
83
|
+
measure :do_simple_work,
|
84
|
+
parent_uuid: "c9b104fb-3389-4c21-b0e9-6c88fd905e4f"
|
85
|
+
|
86
|
+
attr_accessor :my_var
|
87
|
+
|
88
|
+
def initialize(my_var)
|
89
|
+
@my_var = my_var
|
90
|
+
end
|
91
|
+
|
92
|
+
def do_simple_work
|
93
|
+
@my_var += 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class TestBlock < Minitest::Test
|
98
|
+
def test_simple_method
|
99
|
+
my_object = MyClass.new(1)
|
100
|
+
my_object.do_simple_work
|
101
|
+
|
102
|
+
assert_equal 2, my_object.my_var
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_method_with_params
|
106
|
+
my_object = MyClass.new(2)
|
107
|
+
my_object.do_work_with_params(3)
|
108
|
+
|
109
|
+
assert_equal 8, my_object.my_var
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_method_with_block
|
113
|
+
my_object = MyClass.new(5)
|
114
|
+
|
115
|
+
my_object.do_work_with_block do |that_object|
|
116
|
+
that_object.my_var += 7
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_equal 12, my_object.my_var
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_method_with_params_and_block
|
123
|
+
my_object = MyClass.new(11)
|
124
|
+
|
125
|
+
my_object.do_work_with_params_and_block(13) do |that_object|
|
126
|
+
that_object.my_var += 17
|
127
|
+
end
|
128
|
+
|
129
|
+
assert_equal 46, my_object.my_var
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_child_symbol_simple_method
|
133
|
+
my_object = MyChildSymbolClass.new(1)
|
134
|
+
my_object.do_simple_work
|
135
|
+
|
136
|
+
assert_equal 2, my_object.my_var
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_child_proc_simple_method
|
140
|
+
my_object = MyChildProcClass.new(1)
|
141
|
+
my_object.do_simple_work
|
142
|
+
|
143
|
+
assert_equal 2, my_object.my_var
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_child_string_simple_method
|
147
|
+
my_object = MyChildStringClass.new(1)
|
148
|
+
my_object.do_simple_work
|
149
|
+
|
150
|
+
assert_equal 2, my_object.my_var
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_block
|
154
|
+
ProcessMetrics.measure('anon') do |metric|
|
155
|
+
sleep rand
|
156
|
+
metric.data = { my_key: 'my_value'}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: process_metrics_activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Uyezu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.2.17
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.2.17
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: process_metrics
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.1'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.1.2
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.1'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.1.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: minitest
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '5.3'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 5.3.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '5.3'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 5.3.1
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: sqlite3
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '1.3'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.3.9
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.3.9
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: pry-debugger
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.2'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.2.2
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.2'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.2.2
|
113
|
+
description: Store your metrics generated with the 'process_metrics' gem using ActiveRecord
|
114
|
+
email: lucas@uyezu.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files:
|
118
|
+
- README.md
|
119
|
+
files:
|
120
|
+
- README.md
|
121
|
+
- lib/process_metrics/persistence/active_record.rb
|
122
|
+
- lib/process_metrics/persistence/active_record/metric.rb
|
123
|
+
- lib/process_metrics/persistence/active_record/migration.rb
|
124
|
+
- lib/process_metrics/persistence/version.rb
|
125
|
+
- lib/process_metrics_activerecord.rb
|
126
|
+
- test/test_simple.rb
|
127
|
+
homepage: https://github.com/locaweb/process_metrics_activerecord
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options:
|
133
|
+
- "--charset=UTF-8"
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.2.2
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: ActiveRecord Metrics serializer
|
152
|
+
test_files:
|
153
|
+
- test/test_simple.rb
|