appstats 0.8.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/db/migrations/20110217215309_create_appstats_context_keys.rb +13 -0
- data/db/migrations/20110217220154_create_appstats_context_values.rb +13 -0
- data/db/migrations/20110217220357_add_additional_contexts_indexes.rb +11 -0
- data/db/schema.rb +17 -1
- data/lib/appstats.rb +2 -0
- data/lib/appstats/context_key.rb +18 -0
- data/lib/appstats/context_value.rb +18 -0
- data/lib/appstats/version.rb +1 -1
- data/lib/daemons/appstats_log_collector.rb +2 -0
- data/spec/context_key_spec.rb +51 -0
- data/spec/context_value_spec.rb +51 -0
- data/spec/entry_spec.rb +4 -4
- data/spec/logger_spec.rb +18 -18
- metadata +13 -4
data/Gemfile.lock
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateAppstatsContextValues < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :appstats_context_values do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :status
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :appstats_context_values
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddAdditionalContextsIndexes < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_index :appstats_contexts, :context_key
|
4
|
+
add_index :appstats_contexts, :context_value
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_index :appstats_contexts, :context_key
|
9
|
+
remove_index :appstats_contexts, :context_value
|
10
|
+
end
|
11
|
+
end
|
data/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended to check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(:version =>
|
13
|
+
ActiveRecord::Schema.define(:version => 20110217220357) do
|
14
14
|
|
15
15
|
create_table "appstats_actions", :force => true do |t|
|
16
16
|
t.string "name"
|
@@ -20,6 +20,20 @@ ActiveRecord::Schema.define(:version => 20110215155830) do
|
|
20
20
|
t.datetime "updated_at"
|
21
21
|
end
|
22
22
|
|
23
|
+
create_table "appstats_context_keys", :force => true do |t|
|
24
|
+
t.string "name"
|
25
|
+
t.string "status"
|
26
|
+
t.datetime "created_at"
|
27
|
+
t.datetime "updated_at"
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table "appstats_context_values", :force => true do |t|
|
31
|
+
t.string "name"
|
32
|
+
t.string "status"
|
33
|
+
t.datetime "created_at"
|
34
|
+
t.datetime "updated_at"
|
35
|
+
end
|
36
|
+
|
23
37
|
create_table "appstats_contexts", :force => true do |t|
|
24
38
|
t.string "context_key"
|
25
39
|
t.string "context_value"
|
@@ -33,6 +47,8 @@ ActiveRecord::Schema.define(:version => 20110215155830) do
|
|
33
47
|
add_index "appstats_contexts", ["context_key", "context_float"], :name => "index_appstats_contexts_on_context_key_and_context_float"
|
34
48
|
add_index "appstats_contexts", ["context_key", "context_int"], :name => "index_appstats_contexts_on_context_key_and_context_int"
|
35
49
|
add_index "appstats_contexts", ["context_key", "context_value"], :name => "index_appstats_contexts_on_context_key_and_context_value"
|
50
|
+
add_index "appstats_contexts", ["context_key"], :name => "index_appstats_contexts_on_context_key"
|
51
|
+
add_index "appstats_contexts", ["context_value"], :name => "index_appstats_contexts_on_context_value"
|
36
52
|
|
37
53
|
create_table "appstats_entries", :force => true do |t|
|
38
54
|
t.string "action"
|
data/lib/appstats.rb
CHANGED
@@ -14,6 +14,8 @@ require "#{File.dirname(__FILE__)}/appstats/parser"
|
|
14
14
|
require "#{File.dirname(__FILE__)}/appstats/query"
|
15
15
|
require "#{File.dirname(__FILE__)}/appstats/result"
|
16
16
|
require "#{File.dirname(__FILE__)}/appstats/host"
|
17
|
+
require "#{File.dirname(__FILE__)}/appstats/context_key"
|
18
|
+
require "#{File.dirname(__FILE__)}/appstats/context_value"
|
17
19
|
require "#{File.dirname(__FILE__)}/appstats/test_object"
|
18
20
|
|
19
21
|
# required in the appstats.gemspec
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Appstats
|
2
|
+
class ContextKey < ActiveRecord::Base
|
3
|
+
set_table_name "appstats_context_keys"
|
4
|
+
|
5
|
+
attr_accessible :name, :status
|
6
|
+
|
7
|
+
def self.update_context_keys
|
8
|
+
sql = "select distinct(context_key) from appstats_contexts where context_key not in (select name from appstats_context_keys)"
|
9
|
+
count = 0
|
10
|
+
ActiveRecord::Base.connection.execute(sql).each do |row|
|
11
|
+
Appstats::ContextKey.create(:name => row[0], :status => 'derived')
|
12
|
+
count += 1
|
13
|
+
end
|
14
|
+
count
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Appstats
|
2
|
+
class ContextValue < ActiveRecord::Base
|
3
|
+
set_table_name "appstats_context_values"
|
4
|
+
|
5
|
+
attr_accessible :name, :status
|
6
|
+
|
7
|
+
def self.update_context_values
|
8
|
+
sql = "select distinct(context_value) from appstats_contexts where context_value not in (select name from appstats_context_values)"
|
9
|
+
count = 0
|
10
|
+
ActiveRecord::Base.connection.execute(sql).each do |row|
|
11
|
+
Appstats::ContextValue.create(:name => row[0], :status => 'derived')
|
12
|
+
count += 1
|
13
|
+
end
|
14
|
+
count
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/appstats/version.rb
CHANGED
@@ -40,6 +40,8 @@ while($running) do
|
|
40
40
|
Appstats::LogCollector.process_local_files
|
41
41
|
Appstats::Action.update_actions
|
42
42
|
Appstats::Host.update_hosts
|
43
|
+
Appstats::ContextKey.update_context_keys
|
44
|
+
Appstats::ContextValue.update_context_values
|
43
45
|
ActiveRecord::Base.connection.disconnect!
|
44
46
|
a_day_in_seconds = 60*60*24
|
45
47
|
sleep a_day_in_seconds
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Appstats
|
4
|
+
describe ContextKey do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Appstats::Context.delete_all
|
8
|
+
Appstats::ContextKey.delete_all
|
9
|
+
@context_key = Appstats::ContextKey.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
|
14
|
+
it "should set name to nil" do
|
15
|
+
@context_key.name.should == nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set status to nil" do
|
19
|
+
@context_key.status.should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set on constructor" do
|
23
|
+
context_key = Appstats::ContextKey.new(:name => 'a', :status => 'c')
|
24
|
+
context_key.name.should == 'a'
|
25
|
+
context_key.status.should == 'c'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#update_context_keys" do
|
31
|
+
|
32
|
+
it "should do nothing if no events" do
|
33
|
+
Appstats::ContextKey.update_context_keys.should == 0
|
34
|
+
Appstats::ContextKey.count.should == 0
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should add entry context_key names" do
|
38
|
+
Appstats::Context.create(:context_key => 'a')
|
39
|
+
Appstats::ContextKey.update_context_keys.should == 1
|
40
|
+
Appstats::ContextKey.count.should == 1
|
41
|
+
|
42
|
+
context_key = Appstats::ContextKey.last
|
43
|
+
context_key.name = 'a'
|
44
|
+
context_key.status = 'derived'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Appstats
|
4
|
+
describe ContextValue do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
Appstats::Context.delete_all
|
8
|
+
Appstats::ContextValue.delete_all
|
9
|
+
@context_value = Appstats::ContextValue.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
|
14
|
+
it "should set name to nil" do
|
15
|
+
@context_value.name.should == nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set status to nil" do
|
19
|
+
@context_value.status.should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set on constructor" do
|
23
|
+
context_value = Appstats::ContextValue.new(:name => 'a', :status => 'c')
|
24
|
+
context_value.name.should == 'a'
|
25
|
+
context_value.status.should == 'c'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#update_context_values" do
|
31
|
+
|
32
|
+
it "should do nothing if no events" do
|
33
|
+
Appstats::ContextValue.update_context_values.should == 0
|
34
|
+
Appstats::ContextValue.count.should == 0
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should add entry context_value names" do
|
38
|
+
Appstats::Context.create(:context_value => 'a')
|
39
|
+
Appstats::ContextValue.update_context_values.should == 1
|
40
|
+
Appstats::ContextValue.count.should == 1
|
41
|
+
|
42
|
+
context_value = Appstats::ContextValue.last
|
43
|
+
context_value.name = 'a'
|
44
|
+
context_value.status = 'derived'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/spec/entry_spec.rb
CHANGED
@@ -188,18 +188,18 @@ module Appstats
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should understand an entry without contexts" do
|
191
|
-
entry = Entry.create_from_logger_string("0.
|
191
|
+
entry = Entry.create_from_logger_string("0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
|
192
192
|
Entry.count.should == @before_count + 1
|
193
193
|
entry.action.should == "address_search"
|
194
|
-
entry.raw_entry.should == "0.
|
194
|
+
entry.raw_entry.should == "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
|
195
195
|
entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should understand contexts" do
|
199
|
-
entry = Entry.create_from_logger_string("0.
|
199
|
+
entry = Entry.create_from_logger_string("0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
|
200
200
|
Entry.count.should == @before_count + 1
|
201
201
|
entry.action.should == "address_filter"
|
202
|
-
entry.raw_entry.should == "0.
|
202
|
+
entry.raw_entry.should == "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
|
203
203
|
entry.occurred_at.should == Time.parse("2010-09-21 23:15:20")
|
204
204
|
entry.contexts.size.should == 2
|
205
205
|
entry.contexts[0].context_key = "app_name"
|
data/spec/logger_spec.rb
CHANGED
@@ -115,7 +115,7 @@ module Appstats
|
|
115
115
|
|
116
116
|
it "should accept numbers" do
|
117
117
|
Appstats::Logger.entry(5, :blah => 6)
|
118
|
-
Appstats::Logger.raw_read.should == ["0.
|
118
|
+
Appstats::Logger.raw_read.should == ["0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=5 : blah=6"]
|
119
119
|
end
|
120
120
|
|
121
121
|
end
|
@@ -124,7 +124,7 @@ module Appstats
|
|
124
124
|
|
125
125
|
it "should look similar to regular entry" do
|
126
126
|
Appstats::Logger.exception_entry(RuntimeError.new("blah"),:on => "login")
|
127
|
-
Appstats::Logger.raw_read.should == ["0.
|
127
|
+
Appstats::Logger.raw_read.should == ["0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=appstats-exception : error=blah : on=login"]
|
128
128
|
end
|
129
129
|
|
130
130
|
end
|
@@ -141,29 +141,29 @@ module Appstats
|
|
141
141
|
|
142
142
|
it "should handle a statistics entry" do
|
143
143
|
expected = { :action => "address_search", :timestamp => "2010-09-21 23:15:20" }
|
144
|
-
actual = Appstats::Logger.entry_to_hash("0.
|
144
|
+
actual = Appstats::Logger.entry_to_hash("0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search")
|
145
145
|
actual.should == expected
|
146
146
|
end
|
147
147
|
|
148
148
|
it "should handle contexts" do
|
149
149
|
expected = { :action => "address_filter", :timestamp => "2010-09-21 23:15:20", :server => "Live", :app_name => 'Market' }
|
150
|
-
actual = Appstats::Logger.entry_to_hash("0.
|
150
|
+
actual = Appstats::Logger.entry_to_hash("0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live")
|
151
151
|
actual.should == expected
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should handle actions with the delimiter (and change the delimiter)" do
|
155
155
|
expected = { :action => "address:=search-n", :timestamp => "2010-09-21 23:15:20" }
|
156
|
-
actual = Appstats::Logger.entry_to_hash("0.
|
156
|
+
actual = Appstats::Logger.entry_to_hash("0.9.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n")
|
157
157
|
actual.should == expected
|
158
158
|
|
159
159
|
expected = { :action => "address::search==--n", :timestamp => "2010-09-21 23:15:20" }
|
160
|
-
actual = Appstats::Logger.entry_to_hash("0.
|
160
|
+
actual = Appstats::Logger.entry_to_hash("0.9.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n")
|
161
161
|
actual.should == expected
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should handle contexts with the delimiter (and change the delimiter)" do
|
165
165
|
expected = { :action => "address", :timestamp => "2010-09-21 23:15:20", :server => "market:eval=-n" }
|
166
|
-
actual = Appstats::Logger.entry_to_hash("0.
|
166
|
+
actual = Appstats::Logger.entry_to_hash("0.9.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n")
|
167
167
|
actual.should == expected
|
168
168
|
end
|
169
169
|
|
@@ -172,66 +172,66 @@ module Appstats
|
|
172
172
|
describe "#entry_to_s" do
|
173
173
|
|
174
174
|
it "should handle a statistics entry" do
|
175
|
-
expected = "0.
|
175
|
+
expected = "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search"
|
176
176
|
actual = Appstats::Logger.entry_to_s("address_search")
|
177
177
|
actual.should == expected
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should handle numbers" do
|
181
|
-
expected = "0.
|
181
|
+
expected = "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=1 : note=2.2"
|
182
182
|
actual = Appstats::Logger.entry_to_s(1,:note => 2.2)
|
183
183
|
actual.should == expected
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should handle default contexts" do
|
187
187
|
Appstats::Logger.default_contexts[:app_name] = "market"
|
188
|
-
expected = "0.
|
188
|
+
expected = "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : app_name=market"
|
189
189
|
actual = Appstats::Logger.entry_to_s("address_search")
|
190
190
|
actual.should == expected
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should handle contexts (and sort them by symbol)" do
|
194
|
-
expected = "0.
|
194
|
+
expected = "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_filter : app_name=Market : server=Live"
|
195
195
|
actual = Appstats::Logger.entry_to_s("address_filter", { :server => "Live", :app_name => 'Market' })
|
196
196
|
actual.should == expected
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should handle actions with the delimiter (and change the delimiter)" do
|
200
|
-
expected = "0.
|
200
|
+
expected = "0.9.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=search-n"
|
201
201
|
actual = Appstats::Logger.entry_to_s("address:=search-n")
|
202
202
|
actual.should == expected
|
203
203
|
|
204
|
-
expected = "0.
|
204
|
+
expected = "0.9.0 setup[:::,===,---n] 2010-09-21 23:15:20 action===address::search==--n"
|
205
205
|
actual = Appstats::Logger.entry_to_s("address::search==--n")
|
206
206
|
actual.should == expected
|
207
207
|
end
|
208
208
|
|
209
209
|
it "should handle contexts with the delimiter (and change the delimiter)" do
|
210
|
-
expected = "0.
|
210
|
+
expected = "0.9.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address :: server==market:eval=-n"
|
211
211
|
actual = Appstats::Logger.entry_to_s("address", :server => 'market:eval=-n')
|
212
212
|
actual.should == expected
|
213
213
|
end
|
214
214
|
|
215
215
|
it "should ignore spaces" do
|
216
|
-
expected = "0.
|
216
|
+
expected = "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address search"
|
217
217
|
actual = Appstats::Logger.entry_to_s("address search")
|
218
218
|
actual.should == expected
|
219
219
|
end
|
220
220
|
|
221
221
|
it "should convert newlines in action" do
|
222
|
-
expected = "0.
|
222
|
+
expected = "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_-nsearch"
|
223
223
|
actual = Appstats::Logger.entry_to_s("address_\nsearch")
|
224
224
|
actual.should == expected
|
225
225
|
end
|
226
226
|
|
227
227
|
it "should convert newlines in context" do
|
228
|
-
expected = "0.
|
228
|
+
expected = "0.9.0 setup[:,=,-n] 2010-09-21 23:15:20 action=address_search : blah=some-nlong-nstatement"
|
229
229
|
actual = Appstats::Logger.entry_to_s("address_search",:blah => "some\nlong\nstatement")
|
230
230
|
actual.should == expected
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should convert newlines based on the delimiter" do
|
234
|
-
expected = "0.
|
234
|
+
expected = "0.9.0 setup[::,==,--n] 2010-09-21 23:15:20 action==address:=--nsearch-n"
|
235
235
|
actual = Appstats::Logger.entry_to_s("address:=\nsearch-n")
|
236
236
|
actual.should == expected
|
237
237
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Forward
|
@@ -152,12 +152,17 @@ files:
|
|
152
152
|
- db/migrations/20110210185911_create_appstats_test_object.rb
|
153
153
|
- db/migrations/20110210225606_create_appstats_results.rb
|
154
154
|
- db/migrations/20110215155830_create_appstats_hosts.rb
|
155
|
+
- db/migrations/20110217215309_create_appstats_context_keys.rb
|
156
|
+
- db/migrations/20110217220154_create_appstats_context_values.rb
|
157
|
+
- db/migrations/20110217220357_add_additional_contexts_indexes.rb
|
155
158
|
- db/schema.rb
|
156
159
|
- lib/appstats.rb
|
157
160
|
- lib/appstats/action.rb
|
158
161
|
- lib/appstats/acts_as_appstatsable.rb
|
159
162
|
- lib/appstats/code_injections.rb
|
160
163
|
- lib/appstats/context.rb
|
164
|
+
- lib/appstats/context_key.rb
|
165
|
+
- lib/appstats/context_value.rb
|
161
166
|
- lib/appstats/date_range.rb
|
162
167
|
- lib/appstats/entry.rb
|
163
168
|
- lib/appstats/entry_date.rb
|
@@ -192,7 +197,9 @@ files:
|
|
192
197
|
- spec/action_spec.rb
|
193
198
|
- spec/acts_as_appstatsble_spec.rb
|
194
199
|
- spec/appstats_spec.rb
|
200
|
+
- spec/context_key_spec.rb
|
195
201
|
- spec/context_spec.rb
|
202
|
+
- spec/context_value_spec.rb
|
196
203
|
- spec/date_range_spec.rb
|
197
204
|
- spec/entry_date_spec.rb
|
198
205
|
- spec/entry_spec.rb
|
@@ -242,7 +249,9 @@ test_files:
|
|
242
249
|
- spec/action_spec.rb
|
243
250
|
- spec/acts_as_appstatsble_spec.rb
|
244
251
|
- spec/appstats_spec.rb
|
252
|
+
- spec/context_key_spec.rb
|
245
253
|
- spec/context_spec.rb
|
254
|
+
- spec/context_value_spec.rb
|
246
255
|
- spec/date_range_spec.rb
|
247
256
|
- spec/entry_date_spec.rb
|
248
257
|
- spec/entry_spec.rb
|