logbox 0.2.10

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.
Files changed (46) hide show
  1. data/.bundle/config +3 -0
  2. data/.rvmrc +2 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +30 -0
  5. data/README +14 -0
  6. data/Rakefile +74 -0
  7. data/VERSION +1 -0
  8. data/bin/download_logs +20 -0
  9. data/bin/obsstats +39 -0
  10. data/bin/rotate +17 -0
  11. data/bin/viewobs +198 -0
  12. data/lib/logbox.rb +9 -0
  13. data/lib/logbox/ansi_colors.rb +28 -0
  14. data/lib/logbox/log_parser.rb +79 -0
  15. data/lib/logbox/mockup_log.rb +44 -0
  16. data/lib/logbox/observation.rb +162 -0
  17. data/lib/logbox/observation_compiler.rb +311 -0
  18. data/lib/logbox/observation_mover.rb +142 -0
  19. data/lib/logbox/stream_wrapper.rb +20 -0
  20. data/lib/logbox/stream_wrapper/gzip_multi_file.rb +90 -0
  21. data/lib/logbox/stream_wrapper/observation_filter.rb +113 -0
  22. data/lib/logbox/stream_wrapper/order_blob_splitter.rb +96 -0
  23. data/lib/setup_environment.rb +15 -0
  24. data/logbox.gemspec +110 -0
  25. data/test/bin_viewobs_test.rb +42 -0
  26. data/test/fixtures/aws_keys_yaml.txt +3 -0
  27. data/test/fixtures/double-obs.log +1 -0
  28. data/test/fixtures/error_line.log +1 -0
  29. data/test/fixtures/log-for-md5.log +1 -0
  30. data/test/fixtures/log0.log +0 -0
  31. data/test/fixtures/log1.log +1 -0
  32. data/test/fixtures/log1.log.gz +0 -0
  33. data/test/fixtures/log2.log +2 -0
  34. data/test/fixtures/log2.log.gz +0 -0
  35. data/test/fixtures/log_invalid_mixed_encoding.log +1 -0
  36. data/test/fixtures/observation_filter.log +5 -0
  37. data/test/fixtures/unquoted_ugliness.log +2 -0
  38. data/test/log_parser_test.rb +84 -0
  39. data/test/observation_compiler_test.rb +216 -0
  40. data/test/observation_mover_test.rb +135 -0
  41. data/test/observation_test.rb +114 -0
  42. data/test/stream_wrapper/gzip_multi_file_test.rb +147 -0
  43. data/test/stream_wrapper/observation_filter_test.rb +171 -0
  44. data/test/stream_wrapper/order_blob_splitter_test.rb +129 -0
  45. data/test/test_helper.rb +23 -0
  46. metadata +177 -0
@@ -0,0 +1,129 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'stream_wrapper'
4
+ include StreamWrapper
5
+
6
+ class StreamWrapper::OrderBlobSplitterTest < Test::Unit::TestCase
7
+
8
+ PICK_ITEM = %Q{81.225.100.141 - - [23/Nov/2009:06:26:04 +0100] "GET /log.gif?_item_id=3895&a=Mozilla%2F4.0%20(compatible%3B%20MSIE%207.0%3B%20Windows%20NT%205.1%3B%20Mozilla%2F4.0%20(compatible%3B%20MSIE%206.0%3B%20Windows%20NT%205.1%3B%20SV1)%20%3B%20.NET%20CLR%201.1.4322%3B%20.NET%20CLR%202.0.50727%3B%20.NET%20CLR%203.0.4506.2152%3B%20.NET%20CLR%203.5.30729%3B%20InfoPath.2)&aid=jetshop&e=click&l=sv&n=microsoft%20internet%20explorer&o=pick_item&p=win32&r=http%3A%2F%2Fwww.24.se%2Fsandisk-micro-secure-digital-2gb-p-1485.aspx&s=1024x768&sid=www.24.se&t=Sandisk%20MicroSD%20HC%208GB&u=http%3A%2F%2Fwww.24.se%2Fsandisk-microsd-hc-8gb-p-3895.aspx&uid=1258953499669667731&x=28543&z=-60& HTTP/1.1" 200 35 "http://www.24.se/sandisk-microsd-hc-8gb-p-3895.aspx" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)"\n}
9
+ BUY_BASKET = %Q{81.225.100.141 - - [23/Nov/2009:06:45:23 +0100] "GET /log.gif?_order_blob=RW%3AT%7C2142%7C%7C1079.00%7C215.80%7C0.00%7Cstr%C3%B6mstad%7C%7CSweden%7C%20%0ARW%3AI%7C2142%7CMATAW09%20Wanni%20L%7COverall%20(98)%7C%7C1079.00%7C1%7C&a=Mozilla%2F4.0%20(compatible%3B%20MSIE%208.0%3B%20Windows%20NT%205.1%3B%20Trident%2F4.0%3B%20Mozilla%2F4.0%20(compatible%3B%20MSIE%206.0%3B%20Windows%20NT%205.1%3B%20SV1)%20%3B%20.NET%20CLR%202.0.50727%3B%20.NET%20CLR%203.0.4506.2152%3B%20.NET%20CLR%203.5.30729)&aid=jetshop&l=sv&n=microsoft%20internet%20explorer&o=buy_basket&p=win32&s=1024x600&sid=www.pixiekids.se&t=Unika%20barnkl%C3%A4der%20%26%20babykl%C3%A4der%20hos%20Pixiekids%20%E2%8E%AE%200-10%20%C3%A5r&u=https%3A%2F%2Fwww.pixiekids.se%2FOrderDetailsConfirmed.aspx&uid=1258954551578656003&x=87544&z=-60& HTTP/1.1" 200 35 "https://www.pixiekids.se/OrderDetailsConfirmed.aspx" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"\n}
10
+ BUY_BASKET_WITH_2_ITEMS = %Q{81.225.100.141 - - [23/Nov/2009:06:45:23 +0100] "GET /log.gif?_order_blob=RW%3AT%7C2142%7C%7C1079.00%7C215.80%7C0.00%7Cstr%C3%B6mstad%7C%7CSweden%7C%20%0ARW%3AI%7C2142%7CMATAW09%20Wanni%20L%7COverall%20(98)%7C%7C1079.00%7C1%7CRW%3AI%7C2142%7CMATAW09%20Wanni%20L%7COverall%20(98)%7C%7C1079.00%7C1%7C&a=Mozilla%2F4.0%20(compatible%3B%20MSIE%208.0%3B%20Windows%20NT%205.1%3B%20Trident%2F4.0%3B%20Mozilla%2F4.0%20(compatible%3B%20MSIE%206.0%3B%20Windows%20NT%205.1%3B%20SV1)%20%3B%20.NET%20CLR%202.0.50727%3B%20.NET%20CLR%203.0.4506.2152%3B%20.NET%20CLR%203.5.30729)&aid=jetshop&l=sv&n=microsoft%20internet%20explorer&o=buy_basket&p=win32&s=1024x600&sid=www.pixiekids.se&t=Unika%20barnkl%C3%A4der%20%26%20babykl%C3%A4der%20hos%20Pixiekids%20%E2%8E%AE%200-10%20%C3%A5r&u=https%3A%2F%2Fwww.pixiekids.se%2FOrderDetailsConfirmed.aspx&uid=1258954551578656003&x=87544&z=-60& HTTP/1.1" 200 35 "https://www.pixiekids.se/OrderDetailsConfirmed.aspx" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"\n}
11
+ EXPANDED_BUY_BASKET = %Q{81.225.100.141 - - [23/Nov/2009:06:45:23 +0100] "GET /log.gif?_city=str%C3%B6mstad&_country=Sweden&_order_blob=RW%3AT%7C2142%7C%7C1079.00%7C215.80%7C0.00%7Cstr%C3%B6mstad%7C%7CSweden%7C%20%0ARW%3AI%7C2142%7CMATAW09%20Wanni%20L%7COverall%20(98)%7C%7C1079.00%7C1%7C&_order_id=2142&_shipping=0.00&_tax=215.80&_total=1079.00&a=Mozilla%2F4.0%20(compatible%3B%20MSIE%208.0%3B%20Windows%20NT%205.1%3B%20Trident%2F4.0%3B%20Mozilla%2F4.0%20(compatible%3B%20MSIE%206.0%3B%20Windows%20NT%205.1%3B%20SV1)%20%3B%20.NET%20CLR%202.0.50727%3B%20.NET%20CLR%203.0.4506.2152%3B%20.NET%20CLR%203.5.30729)&aid=jetshop&l=sv&n=microsoft%20internet%20explorer&o=buy_basket&p=win32&s=1024x600&sid=www.pixiekids.se&t=Unika%20barnkl%C3%A4der%20%26%20babykl%C3%A4der%20hos%20Pixiekids%20%E2%8E%AE%200-10%20%C3%A5r&u=https%3A%2F%2Fwww.pixiekids.se%2FOrderDetailsConfirmed.aspx&uid=1258954551578656003&x=87544&z=-60& HTTP/1.1" 200 35 "https://www.pixiekids.se/OrderDetailsConfirmed.aspx" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"\n}
12
+ BUY_ITEM = %Q{81.225.100.141 - - [23/Nov/2009:06:45:23 +0100] "GET /log.gif?_current_price=1079.00&_order_id=2142&_quantity=1&_sku=MATAW09+Wanni+L&_title=Overall+%2898%29&a=Mozilla%2F4.0%20(compatible%3B%20MSIE%208.0%3B%20Windows%20NT%205.1%3B%20Trident%2F4.0%3B%20Mozilla%2F4.0%20(compatible%3B%20MSIE%206.0%3B%20Windows%20NT%205.1%3B%20SV1)%20%3B%20.NET%20CLR%202.0.50727%3B%20.NET%20CLR%203.0.4506.2152%3B%20.NET%20CLR%203.5.30729)&aid=jetshop&l=sv&n=microsoft%20internet%20explorer&o=buy_item&p=win32&s=1024x600&sid=www.pixiekids.se&t=Unika%20barnkl%C3%A4der%20%26%20babykl%C3%A4der%20hos%20Pixiekids%20%E2%8E%AE%200-10%20%C3%A5r&u=https%3A%2F%2Fwww.pixiekids.se%2FOrderDetailsConfirmed.aspx&uid=1258954551578656003&x=87544&z=-60& HTTP/1.1" 200 35 "https://www.pixiekids.se/OrderDetailsConfirmed.aspx" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"\n}
13
+
14
+ context "An OrderBlobSplitter" do
15
+
16
+ should "not report eof unless stream is eof" do
17
+ s = OrderBlobSplitter.new("oneline\n")
18
+ assert(!s.eof?)
19
+ s.gets
20
+ assert(s.eof?)
21
+ end
22
+
23
+ should "handle an empty stream" do
24
+ s = OrderBlobSplitter.new("")
25
+ assert(s.eof?)
26
+ assert_equal(nil, s.gets)
27
+ end
28
+
29
+ should "pass a nonsense line right through" do
30
+ s = OrderBlobSplitter.new("apa")
31
+ assert_equal("apa", s.gets)
32
+ end
33
+
34
+ should "just let non buy_baskets through unmodified" do
35
+ s = OrderBlobSplitter.new(PICK_ITEM + PICK_ITEM)
36
+ assert_equal(PICK_ITEM, s.gets)
37
+ assert_equal(PICK_ITEM, s.gets)
38
+ assert(s.eof?)
39
+ end
40
+
41
+ should "expand a buy_basket with attributes from an order_blob" do
42
+ s = OrderBlobSplitter.new(BUY_BASKET)
43
+ assert_equal(EXPANDED_BUY_BASKET, s.gets)
44
+ assert(s.eof?)
45
+ end
46
+
47
+ should "add one buy_item line for an order_blob with an item" do
48
+ s = OrderBlobSplitter.new(BUY_BASKET)
49
+ s.gets # EXPANDED_BUY_BASKET
50
+ assert_equal(BUY_ITEM, s.gets)
51
+ assert(s.eof?)
52
+ end
53
+
54
+ should "add one buy_item for each item in an order_blob with two items" do
55
+ s = OrderBlobSplitter.new(BUY_BASKET_WITH_2_ITEMS)
56
+ s.gets # EXPANDED_BUY_BASKET
57
+ assert_equal(BUY_ITEM, s.gets)
58
+ assert_equal(BUY_ITEM, s.gets)
59
+ assert_equal(nil, s.gets)
60
+ assert(s.eof?)
61
+ end
62
+
63
+ context "with private method" do
64
+
65
+ setup do
66
+ @s = OrderBlobSplitter.new("")
67
+ end
68
+
69
+ context "extract_order_blob" do
70
+ should "know extract the blob if it is there" do
71
+ blob = @s.send(:extract_order_blob, BUY_BASKET)
72
+ assert_equal(%Q{RW:T|2142||1079.00|215.80|0.00|strömstad||Sweden| \nRW:I|2142|MATAW09 Wanni L|Overall (98)||1079.00|1|}, blob)
73
+ end
74
+ should "return an empty string if there is no blob" do
75
+ blob = @s.send(:extract_order_blob, PICK_ITEM)
76
+ assert_equal("", blob)
77
+ end
78
+ end
79
+
80
+ context "insert_user_attributes" do
81
+ should "return the same string if no attributes are given." do
82
+ line = @s.send(:insert_user_attributes, BUY_BASKET, {})
83
+ assert_equal(BUY_BASKET, line)
84
+ end
85
+ should "add parameters in alphabetic order" do
86
+ line = @s.send(:insert_user_attributes, "...?_aa=11&_dd=44&aid=...", {:cc => "33", :bb => "22"})
87
+ assert_equal("...?_aa=11&_bb=22&_cc=33&_dd=44&aid=...", line)
88
+ end
89
+ should "encode keys" do
90
+ line = @s.send(:insert_user_attributes, "...?_a=1&aid=...", {"|".to_sym => "a"})
91
+ assert_equal("...?_%7C=a&_a=1&aid=...", line)
92
+ end
93
+ should "encode values" do
94
+ line = @s.send(:insert_user_attributes, "...?_a=1&aid=...", {:b => "|"})
95
+ assert_equal("...?_a=1&_b=%7C&aid=...", line)
96
+ end
97
+ should "not include empty values" do
98
+ line = @s.send(:insert_user_attributes, "...?_a=1&aid=...", {:b => "", :c => nil})
99
+ assert_equal("...?_a=1&aid=...", line)
100
+ end
101
+ should "overwite attributes found in the line" do
102
+ line = @s.send(:insert_user_attributes, "...?_a=1&aid=...", {:a => "2"})
103
+ assert_equal("...?_a=2&aid=...", line)
104
+ end
105
+ should "let through multiple values for an attribute in the line" do
106
+ line = @s.send(:insert_user_attributes, "...?_a=1&_a=1&aid=...", {})
107
+ assert_equal("...?_a=1&_a=1&aid=...", line)
108
+ end
109
+ should "replace multiple values for an attribute in the line" do
110
+ line = @s.send(:insert_user_attributes, "...?_a=1&_a=1&aid=...", {:a => "2"})
111
+ assert_equal("...?_a=2&aid=...", line)
112
+ end
113
+ context "in replace mode" do
114
+ should "return an observation with no user attributes if none are given." do
115
+ line = @s.send(:insert_user_attributes, "...?_aa=11&_dd=44&aid=...", {}, :replace)
116
+ assert_equal("...?aid=...", line)
117
+ end
118
+ should "add parameters in alphabetic order without old parameters" do
119
+ line = @s.send(:insert_user_attributes, "...?_aa=11&_dd=44&aid=...", {:cc => "33", :bb => "22"}, :replace)
120
+ assert_equal("...?_bb=22&_cc=33&aid=...", line)
121
+ end
122
+ end
123
+
124
+ end
125
+
126
+ end
127
+ end
128
+ end
129
+
@@ -0,0 +1,23 @@
1
+ TEST_RUN = true
2
+
3
+ require 'setup_environment'
4
+ require 'test/unit'
5
+
6
+ require 'shoulda'
7
+ require 'mocha'
8
+
9
+
10
+ require 'mockup_log'
11
+
12
+ class Test::Unit::TestCase
13
+ include MockupLog
14
+
15
+ def read_fixture_file (name)
16
+ File.read(fixture_file(name))
17
+ end
18
+
19
+ def fixture_file (name)
20
+ File.join(File.dirname(__FILE__), "fixtures/#{name}")
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.10
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - dvrensk
9
+ - enarsson
10
+ - Jell
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-12-22 00:00:00.000000000 +01:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: right_aws
19
+ requirement: &70161206465840 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '2.0'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: *70161206465840
28
+ - !ruby/object:Gem::Dependency
29
+ name: single_instance
30
+ requirement: &70161206464580 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: *70161206464580
39
+ - !ruby/object:Gem::Dependency
40
+ name: rake
41
+ requirement: &70161206463560 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *70161206463560
50
+ - !ruby/object:Gem::Dependency
51
+ name: bundler
52
+ requirement: &70161206462420 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 1.0.0
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: *70161206462420
61
+ - !ruby/object:Gem::Dependency
62
+ name: jeweler
63
+ requirement: &70161206461260 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.1
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: *70161206461260
72
+ - !ruby/object:Gem::Dependency
73
+ name: rcov
74
+ requirement: &70161206460020 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: *70161206460020
83
+ description: Log-related code and tools that are used cross different applications
84
+ email: dev@icehouse.se
85
+ executables:
86
+ - download_logs
87
+ - obsstats
88
+ - rotate
89
+ - viewobs
90
+ extensions: []
91
+ extra_rdoc_files:
92
+ - README
93
+ files:
94
+ - .bundle/config
95
+ - .rvmrc
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - README
99
+ - Rakefile
100
+ - VERSION
101
+ - bin/download_logs
102
+ - bin/obsstats
103
+ - bin/rotate
104
+ - bin/viewobs
105
+ - lib/logbox.rb
106
+ - lib/logbox/ansi_colors.rb
107
+ - lib/logbox/log_parser.rb
108
+ - lib/logbox/mockup_log.rb
109
+ - lib/logbox/observation.rb
110
+ - lib/logbox/observation_compiler.rb
111
+ - lib/logbox/observation_mover.rb
112
+ - lib/logbox/stream_wrapper.rb
113
+ - lib/logbox/stream_wrapper/gzip_multi_file.rb
114
+ - lib/logbox/stream_wrapper/observation_filter.rb
115
+ - lib/logbox/stream_wrapper/order_blob_splitter.rb
116
+ - lib/setup_environment.rb
117
+ - logbox.gemspec
118
+ - test/bin_viewobs_test.rb
119
+ - test/fixtures/aws_keys_yaml.txt
120
+ - test/fixtures/double-obs.log
121
+ - test/fixtures/error_line.log
122
+ - test/fixtures/log-for-md5.log
123
+ - test/fixtures/log0.log
124
+ - test/fixtures/log1.log
125
+ - test/fixtures/log1.log.gz
126
+ - test/fixtures/log2.log
127
+ - test/fixtures/log2.log.gz
128
+ - test/fixtures/log_invalid_mixed_encoding.log
129
+ - test/fixtures/observation_filter.log
130
+ - test/fixtures/unquoted_ugliness.log
131
+ - test/log_parser_test.rb
132
+ - test/observation_compiler_test.rb
133
+ - test/observation_mover_test.rb
134
+ - test/observation_test.rb
135
+ - test/stream_wrapper/gzip_multi_file_test.rb
136
+ - test/stream_wrapper/observation_filter_test.rb
137
+ - test/stream_wrapper/order_blob_splitter_test.rb
138
+ - test/test_helper.rb
139
+ has_rdoc: true
140
+ homepage: https://github.com/icehouse/logbox
141
+ licenses:
142
+ - MIT
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ segments:
154
+ - 0
155
+ hash: -3282874155162756304
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 1.6.2
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: A Toolbox for Logs and Observations
168
+ test_files:
169
+ - test/bin_viewobs_test.rb
170
+ - test/log_parser_test.rb
171
+ - test/observation_compiler_test.rb
172
+ - test/observation_mover_test.rb
173
+ - test/observation_test.rb
174
+ - test/stream_wrapper/gzip_multi_file_test.rb
175
+ - test/stream_wrapper/observation_filter_test.rb
176
+ - test/stream_wrapper/order_blob_splitter_test.rb
177
+ - test/test_helper.rb