mongodb_logger 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/.gitignore +2 -1
  2. data/.rvmrc +1 -1
  3. data/.travis.yml +5 -4
  4. data/Appraisals +9 -0
  5. data/CHANGELOG.md +20 -3
  6. data/README.md +58 -35
  7. data/Rakefile +33 -96
  8. data/app/assets/javascripts/analytics.js.coffee +5 -4
  9. data/app/assets/javascripts/logs.js.coffee +11 -11
  10. data/app/assets/javascripts/mongodb_logger.js +2 -1
  11. data/app/assets/javascripts/vendors/jquery-1.9.1.min.js +5 -0
  12. data/app/assets/javascripts/vendors/jquery.pjax.min.js +15 -13
  13. data/app/assets/javascripts/vendors/mustache.min.js +10 -0
  14. data/app/assets/stylesheets/layout.css +20 -15
  15. data/app/assets/stylesheets/mongodb_logger.css +0 -3
  16. data/bin/mongodb_logger_web +1 -2
  17. data/features/rails.feature +20 -8
  18. data/features/step_definitions/mongodb_logger_web_steps.rb +2 -3
  19. data/features/step_definitions/rails_application_steps.rb +84 -58
  20. data/features/step_definitions/rake_steps.rb +10 -0
  21. data/features/support/aruba.rb +5 -0
  22. data/features/support/env.rb +11 -5
  23. data/features/support/rails.rb +55 -67
  24. data/gemfiles/rails31.gemfile +8 -0
  25. data/gemfiles/rails32.gemfile +8 -0
  26. data/lib/mongodb_logger.rb +10 -3
  27. data/lib/mongodb_logger/adapters/base.rb +5 -1
  28. data/lib/mongodb_logger/adapters/mongo.rb +17 -13
  29. data/lib/mongodb_logger/adapters/moped.rb +17 -11
  30. data/lib/mongodb_logger/capistrano.rb +8 -0
  31. data/lib/mongodb_logger/logger.rb +13 -26
  32. data/lib/mongodb_logger/rack_middleware.rb +24 -0
  33. data/lib/mongodb_logger/railtie.rb +4 -4
  34. data/lib/mongodb_logger/server.rb +43 -68
  35. data/lib/mongodb_logger/server/helpers.rb +5 -0
  36. data/lib/mongodb_logger/server/{content_for.rb → helpers/content_for.rb} +0 -0
  37. data/lib/mongodb_logger/server/helpers/mustache_helpers.rb +66 -0
  38. data/lib/mongodb_logger/server/{partials.rb → helpers/partials.rb} +0 -0
  39. data/lib/mongodb_logger/server/{sprokets.rb → helpers/sprokets.rb} +4 -4
  40. data/lib/mongodb_logger/server/{view_helpers.rb → helpers/view_helpers.rb} +22 -38
  41. data/lib/mongodb_logger/server/model.rb +4 -0
  42. data/lib/mongodb_logger/server/model/additional_filter.rb +15 -23
  43. data/lib/mongodb_logger/server/model/analytic.rb +24 -32
  44. data/lib/mongodb_logger/server/model/base.rb +21 -0
  45. data/lib/mongodb_logger/server/model/filter.rb +12 -20
  46. data/lib/mongodb_logger/server/mustache/logs/info.rb +15 -0
  47. data/lib/mongodb_logger/server/templates/logs/info.mustache +25 -0
  48. data/lib/mongodb_logger/server/views/layout.erb +28 -26
  49. data/lib/mongodb_logger/server/views/shared/_log.erb +1 -1
  50. data/lib/mongodb_logger/server/views/shared/_tabs.erb +2 -2
  51. data/lib/mongodb_logger/server/views/shared/layout/_mustache.erb +6 -0
  52. data/lib/mongodb_logger/server/views/show_log.erb +2 -2
  53. data/lib/mongodb_logger/server_config.rb +4 -4
  54. data/lib/mongodb_logger/utils/migrate.rb +50 -0
  55. data/lib/mongodb_logger/utils/progressbar.rb +79 -0
  56. data/lib/mongodb_logger/version.rb +1 -1
  57. data/mongodb_logger.gemspec +15 -8
  58. data/{test/config/samples → spec/factories/config}/database.yml +0 -0
  59. data/{test/config/samples → spec/factories/config}/database_no_file_logging.yml +0 -0
  60. data/{test/config/samples → spec/factories/config}/database_replica_set.yml +0 -0
  61. data/{test/config/samples → spec/factories/config}/database_with_auth.yml +0 -0
  62. data/spec/factories/config/database_with_capsize.yml +9 -0
  63. data/{test/config/samples → spec/factories/config}/database_with_collection.yml +0 -0
  64. data/{test/config/samples → spec/factories/config}/database_with_url.yml +0 -0
  65. data/{test/config/samples → spec/factories/config}/mongodb_logger.yml +0 -0
  66. data/{test/config/samples → spec/factories/config}/mongoid.yml +0 -0
  67. data/{test/config/samples → spec/factories/config}/server_config.yml +0 -0
  68. data/spec/javascripts/support/jasmine.yml +1 -5
  69. data/spec/mongodb_logger_spec.rb +257 -0
  70. data/spec/rails_spec/controllers/tests_controller_spec_rails.rb +128 -0
  71. data/spec/rails_spec/spec_helper_rails.rb +13 -0
  72. data/spec/spec_helper.rb +17 -0
  73. data/{test/test_helper.rb → spec/support/mongodb_logger_helper.rb} +44 -63
  74. data/spec/support/mongodb_logger_macros.rb +22 -0
  75. data/spec/support/rails.rb +40 -0
  76. data/spec/utils/migrate_spec.rb +32 -0
  77. data/{lib/tasks → tasks}/mongodb_logger.rake +14 -6
  78. metadata +198 -78
  79. data/SUPPORTED_RAILS_VERSIONS +0 -16
  80. data/TESTING.md +0 -24
  81. data/app/assets/javascripts/vendors/jquery-1.8.3.min.js +0 -2
  82. data/features/support/terminal.rb +0 -95
  83. data/lib/mongodb_logger/server/views/shared/_log_info.erb +0 -27
  84. data/test/Gemfile_tests +0 -9
  85. data/test/active_record.rb +0 -13
  86. data/test/log/.gitkeep +0 -0
  87. data/test/rails.rb +0 -22
  88. data/test/rails/app/controllers/order_controller.rb +0 -23
  89. data/test/rails/test/functional/order_controller_test.rb +0 -116
  90. data/test/rails/test/test_helper.rb +0 -10
  91. data/test/shoulda_macros/log_macros.rb +0 -13
  92. data/test/test.sh +0 -7
  93. data/test/unit/mongodb_logger_replica_test.rb +0 -56
  94. data/test/unit/mongodb_logger_test.rb +0 -307
@@ -0,0 +1,4 @@
1
+ require 'mongodb_logger/server/model/base'
2
+ require 'mongodb_logger/server/model/additional_filter'
3
+ require 'mongodb_logger/server/model/filter'
4
+ require 'mongodb_logger/server/model/analytic'
@@ -2,66 +2,58 @@ require 'date'
2
2
 
3
3
  module MongodbLogger
4
4
  module ServerModel
5
- class AdditionalFilter
6
-
5
+ class AdditionalFilter < Base
6
+
7
7
  FORM_NAME = "more"
8
8
  FIXED_PARAMS_ON_FORM = ['type', 'key', 'condition', 'value']
9
-
9
+
10
10
  VAR_TYPES = ["integer", "string", "boolean", "date"]
11
-
11
+
12
12
  VAR_TYPE_CONDITIONS = [
13
13
  ["equals", "not equals", "regexes", "<", "<=", ">=", ">"],
14
14
  ["equals", "not equals", "regexes", "<", "<=", ">=", ">"],
15
15
  ["equals", "exists"],
16
16
  ["<", "<=", ">=", ">"]
17
17
  ]
18
-
18
+
19
19
  VAR_TYPE_VALUES = [
20
20
  [],
21
21
  [],
22
22
  ["true", "false"],
23
23
  []
24
24
  ]
25
-
25
+
26
26
  attr_reader :form_data, :filter_model
27
-
27
+
28
28
  def initialize(params, filter_model)
29
29
  @filter_model = filter_model
30
30
  @params = params
31
31
  FIXED_PARAMS_ON_FORM.each do |key|
32
32
  create_variable(key, nil)
33
33
  end
34
- @params.each do |k,v|
35
- self.send("#{k}=", v) if self.respond_to?(k) && v && !v.blank?
36
- end unless @params.blank?
37
- end
38
-
39
- def create_variable(k, v)
40
- self.instance_variable_set("@#{k}", v) ## create instance variable
41
- self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## method to return instance variable
42
- self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## method to set instance variable
34
+ set_params_to_methods
43
35
  end
44
-
36
+
45
37
  def self.get_type_index(type)
46
38
  type.nil? ? 0 : VAR_TYPES.index(type)
47
39
  end
48
-
40
+
49
41
  def get_type_index
50
42
  @type.nil? ? 0 : VAR_TYPES.index(@type)
51
43
  end
52
-
44
+
53
45
  def selected_values
54
46
  VAR_TYPE_VALUES[get_type_index]
55
47
  end
56
-
48
+
57
49
  def is_selected_values?
58
50
  !VAR_TYPE_VALUES[get_type_index].blank?
59
51
  end
60
-
52
+
61
53
  def form_name
62
54
  "#{filter_model.form_name}[#{FORM_NAME}][]"
63
55
  end
64
-
56
+
65
57
  def mongo_conditions
66
58
  data = Hash.new
67
59
  return data if self.key.blank?
@@ -98,7 +90,7 @@ module MongodbLogger
98
90
  end
99
91
  data
100
92
  end
101
-
93
+
102
94
  end
103
95
  end
104
96
  end
@@ -1,38 +1,30 @@
1
1
  module MongodbLogger
2
2
  module ServerModel
3
- class Analytic
4
-
3
+ class Analytic < Base
4
+
5
5
  FIXED_PARAMS_ON_FORM = ['type', 'unit', 'start_date', 'end_date']
6
6
  ANALYTIC_TYPES = [[0, "Count of requests"], [1, "Count of errors"]]
7
7
  ANALYTIC_UNITS = [[0, "Month"], [1, "Day"], [2, "Hour"]]
8
8
 
9
9
  attr_reader :params, :mongo_adapter
10
10
  FORM_NAME = "analytic"
11
-
11
+
12
12
  def initialize(mongo_adapter, params)
13
13
  FIXED_PARAMS_ON_FORM.each do |key|
14
14
  create_variable(key, nil)
15
15
  end
16
16
  @mongo_adapter = mongo_adapter
17
17
  @params = params
18
- @params.each do |k,v|
19
- self.send("#{k}=", v) if self.respond_to?(k) && v && !v.blank?
20
- end unless @params.blank?
18
+ set_params_to_methods
21
19
  # def values
22
20
  self.start_date ||= Time.now.strftime('%Y-%m-%d')
23
21
  self.end_date ||= Time.now.strftime('%Y-%m-%d')
24
22
  end
25
-
26
- def create_variable(k, v)
27
- self.instance_variable_set("@#{k}", v) ## create instance variable
28
- self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## method to return instance variable
29
- self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## method to set instance variable
30
- end
31
-
23
+
32
24
  def form_name
33
25
  FORM_NAME
34
26
  end
35
-
27
+
36
28
  def calculate_default_map_reduce(params = {})
37
29
  addinional_params = case self.unit.to_i
38
30
  when 1
@@ -43,21 +35,21 @@ module MongodbLogger
43
35
  ""
44
36
  end
45
37
  map = <<EOF
46
- function() {
47
- var key = {
48
- year: this.request_time.getFullYear(),
49
- month: this.request_time.getMonth() + 1,
38
+ function() {
39
+ var key = {
40
+ year: this.request_time.getFullYear(),
41
+ month: this.request_time.getMonth() + 1,
50
42
  #{addinional_params}
51
- };
43
+ };
52
44
  emit(key, {count: 1});
53
45
  }
54
46
  EOF
55
47
  reduce = <<EOF
56
- function(key, values) {
57
- var sum = 0;
58
- values.forEach(function(f) {
59
- sum += f.count;
60
- });
48
+ function(key, values) {
49
+ var sum = 0;
50
+ values.forEach(function(f) {
51
+ sum += f.count;
52
+ });
61
53
  return {count: sum};
62
54
  }
63
55
  EOF
@@ -67,25 +59,25 @@ EOF
67
59
  else
68
60
  # nothing
69
61
  end
70
-
62
+
71
63
  @mongo_adapter.calculate_mapreduce(map, reduce, {:conditions => params[:conditions]})
72
64
  end
73
-
65
+
74
66
  def get_data
75
67
  m_start= Date.parse(self.start_date) rescue Date.today
76
68
  m_end = Date.parse(self.end_date) rescue Date.today
77
-
69
+
78
70
  conditions = { :request_time => {
79
- '$gte' => Time.utc(m_start.year, m_start.month, m_start.day, 0, 0, 0),
71
+ '$gte' => Time.utc(m_start.year, m_start.month, m_start.day, 0, 0, 0),
80
72
  '$lte' => Time.utc(m_end.year, m_end.month, m_end.day, 23, 59, 59)
81
73
  }}
82
-
74
+
83
75
  all_data = calculate_default_map_reduce(
84
76
  :conditions => conditions
85
77
  )
86
-
78
+
87
79
  {
88
- :data => (all_data ? all_data.first.last : []),
80
+ :data => (all_data ? all_data.first.last : []),
89
81
  :headers => {
90
82
  :key => ["year", "month", "day", "hour"],
91
83
  :value => ["count"]
@@ -93,7 +85,7 @@ EOF
93
85
  unit: self.unit
94
86
  }
95
87
  end
96
-
88
+
97
89
  end
98
90
  end
99
91
  end
@@ -0,0 +1,21 @@
1
+ require 'date'
2
+
3
+ module MongodbLogger
4
+ module ServerModel
5
+ class Base
6
+
7
+ def set_params_to_methods
8
+ @params.each do |k,v|
9
+ self.send("#{k}=", v) if self.respond_to?(k) && v && !v.blank?
10
+ end unless @params.blank?
11
+ end
12
+
13
+ def create_variable(k, v)
14
+ self.instance_variable_set("@#{k}", v) ## create instance variable
15
+ self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## method to return instance variable
16
+ self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## method to set instance variable
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -2,23 +2,21 @@ require 'mongodb_logger/server/model/additional_filter'
2
2
 
3
3
  module MongodbLogger
4
4
  module ServerModel
5
- class Filter
6
-
5
+ class Filter < Base
6
+
7
7
  DEFAULT_LIMIT = 100
8
8
  FIXED_PARAMS_ON_FORM = ['action', 'controller', 'ip', 'application_name', 'is_exception', 'limit']
9
9
  attr_reader :params, :mongo_conditions
10
10
  # dynamic filters
11
11
  FORM_NAME = "filter"
12
12
  attr_accessor :more_filters
13
-
13
+
14
14
  def initialize(params)
15
15
  FIXED_PARAMS_ON_FORM.each do |key|
16
16
  create_variable(key, nil)
17
17
  end
18
18
  @params = params
19
- @params.each do |k,v|
20
- self.send("#{k}=", v) if self.respond_to?(k) && v && !v.blank?
21
- end unless @params.blank?
19
+ set_params_to_methods
22
20
  # limits
23
21
  self.limit = DEFAULT_LIMIT.to_s if self.limit.nil?
24
22
  # dynamic filters
@@ -26,20 +24,14 @@ module MongodbLogger
26
24
  # build mongo conditions
27
25
  build_mongo_conditions
28
26
  end
29
-
30
- def create_variable(k, v)
31
- self.instance_variable_set("@#{k}", v) ## create instance variable
32
- self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## method to return instance variable
33
- self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## method to set instance variable
34
- end
35
-
27
+
36
28
  def create_dynamic_filters
37
29
  self.more_filters = []
38
30
  @params[AdditionalFilter::FORM_NAME].each do |filter|
39
31
  self.more_filters << AdditionalFilter.new(filter, self)
40
32
  end if !@params.blank? && @params[AdditionalFilter::FORM_NAME] && !@params[AdditionalFilter::FORM_NAME].blank?
41
33
  end
42
-
34
+
43
35
  def build_mongo_conditions
44
36
  @mongo_conditions = Hash.new
45
37
  FIXED_PARAMS_ON_FORM.each do |param_key|
@@ -54,31 +46,31 @@ module MongodbLogger
54
46
  end
55
47
  @mongo_conditions[param_key.to_s] = mkey_val if !mkey_val.nil? && !mkey_val.blank?
56
48
  end
57
-
49
+
58
50
  self.more_filters.each do |m_filter|
59
51
  unless m_filter.mongo_conditions.blank?
60
52
  cond = m_filter.mongo_conditions
61
53
  if @mongo_conditions[m_filter.key] && @mongo_conditions[m_filter.key].is_a?(Hash)
62
54
  @mongo_conditions[m_filter.key].merge!(cond[m_filter.key])
63
55
  else
64
- @mongo_conditions.merge!(m_filter.mongo_conditions)
56
+ @mongo_conditions.merge!(m_filter.mongo_conditions)
65
57
  end
66
58
  end
67
59
  end unless self.more_filters.blank?
68
60
  end
69
-
61
+
70
62
  def get_mongo_conditions
71
63
  @mongo_conditions
72
64
  end
73
-
65
+
74
66
  def get_mongo_limit
75
67
  self.limit.to_i
76
68
  end
77
-
69
+
78
70
  def form_name
79
71
  FORM_NAME
80
72
  end
81
-
73
+
82
74
  end
83
75
  end
84
76
  end
@@ -0,0 +1,15 @@
1
+ require 'mongodb_logger/server/mustache_helpers'
2
+ module MongodbLogger
3
+ class Server
4
+ module Views
5
+ module Logs
6
+ class Info < Mustache
7
+ def log
8
+ #MongodbLogger::MustacheHelpersObj.log_data(@log)
9
+ @log
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ {{#log}}
2
+ <div class="pas">
3
+ <div class="unit-right">
4
+ <a href="{{web_url}}" data-pjax='true' class="button small grey">More Info</a>
5
+ </div> <!-- unit-right -->
6
+ <h2 class="phs mvs"><span class="{{is_exception_class}}">Message</span> {{_id}}</h2>
7
+ <div class="phs wrap_text">{{main_msg}}</div> <!-- phs -->
8
+ <h2 class="phs mtm mbs">URL (method: {{method}})</h2>
9
+ <div class="phs wrap_text">
10
+ <a href="{{url}}" target="_blank">{{url}}</a>
11
+ </div> <!-- phs -->
12
+ <h2 class="phs mtm mbs">Received</h2>
13
+ <div class="phs">{{request_time}}</div> <!-- phs -->
14
+ <h2 class="phs mtm mbs">IP</h2>
15
+ <div class="phs">
16
+ <a href="http://www.infosniper.net/index.php?ip_address={{ip}}&map_source=1&overview_map=1&lang=1&map_type=1&zoom_level=7" target="_blank">
17
+ {{ip}}
18
+ </a>
19
+ </div> <!-- phs -->
20
+ <h2 class="phs mtm mbs">Params</h2>
21
+ <div class="phs max-size-code">
22
+ <pre><code>{{params}}</code></pre>
23
+ </div> <!-- phs -->
24
+ </div> <!-- pas -->
25
+ {{/log}}
@@ -1,36 +1,38 @@
1
1
  <!DOCTYPE html>
2
- <html>
2
+ <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
3
+ <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
3
4
  <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width" />
4
7
  <title>MongoDB Logger</title>
5
8
  <link href="<%= asset_path('mongodb_logger.css') %>" media="screen" rel="stylesheet" type="text/css">
9
+ <script src="<%= asset_path('mongodb_logger.js') %>" type="text/javascript"></script>
6
10
  </head>
7
11
  <body>
8
- <div class="page">
9
- <div class="header">
10
- <div class="wrapper">
11
- <div class="unit-right stats">
12
- <div class="unit size2of3">
13
- <div class="ptxs pls"><strong>DB:</strong> <%=h @collection_stats[:db_name] %></div>
14
- <div class="pls"><strong>Collection:</strong> <%=h @collection_stats[:collection] %></div>
15
- </div> <!-- unit -->
16
- <div id="collection_stats">
17
- <%= partial(:"shared/collection_stats", :object => @collection_stats) %>
12
+ <div class="page">
13
+ <div class="header">
14
+ <div class="wrapper">
15
+ <div class="unit-right stats">
16
+ <div class="unit size2of3">
17
+ <div class="ptxs pls"><strong>DB:</strong> <%=h @collection_stats[:db_name] %></div>
18
+ <div class="pls"><strong>Collection:</strong> <%=h @collection_stats[:collection] %></div>
19
+ </div> <!-- unit -->
20
+ <div id="collection_stats">
21
+ <%= partial(:"shared/collection_stats", :object => @collection_stats) %>
22
+ </div>
18
23
  </div>
19
- </div>
20
- <a href="<%=h url_path("overview") %>" class="logo" data-pjax='#mainPjax'><img src="<%= asset_path 'logo.png' %>" alt="MongoDB Logger"></a>
21
- </div> <!-- wrapper -->
22
- </div> <!-- header -->
23
- <div class="content">
24
- <div class="wrapper">
25
- <div id="mainPjax" class="mainbox">
26
- <%= yield %>
27
- </div> <!-- mainbox -->
28
- </div> <!-- wrapper -->
29
- </div> <!-- content -->
30
- </div>
31
-
32
- <!-- scripts -->
33
- <script src="<%= asset_path('mongodb_logger.js') %>" type="text/javascript"></script>
24
+ <a href="<%=h url_path("overview") %>" class="logo"><img src="<%= asset_path 'logo.png' %>" alt="MongoDB Logger"></a>
25
+ </div> <!-- wrapper -->
26
+ </div> <!-- header -->
27
+ <div class="content">
28
+ <div class="wrapper">
29
+ <div id="mainPjax" class="mainbox">
30
+ <%= yield %>
31
+ </div> <!-- mainbox -->
32
+ </div> <!-- wrapper -->
33
+ </div> <!-- content -->
34
+ </div>
34
35
 
36
+ <%= partial(:"shared/layout/mustache") %>
35
37
  </body>
36
38
  </html>
@@ -1,4 +1,4 @@
1
- <tr class="log_info" data-url="<%=h url_path("log_info/#{log['_id']}") %>">
1
+ <tr class="log_info" data-url="<%=h url_path("log_info/#{log['_id']}") %>" data-info="<%=h log_data_json(log) %>">
2
2
  <td class="td-time"><span class="<%= log['is_exception'] ? "error" : "notice" %>"></span> <%=h log['request_time']%></td>
3
3
  <td class="td-controller"><%=h log['controller']%></td>
4
4
  <td class="td-action"><%=h log['action']%></td>
@@ -1,4 +1,4 @@
1
1
  <ul class="unit">
2
- <li <%= class_if_current(url_path("overview")) %>><a href="<%=h url_path("overview") %>" data-pjax='#mainPjax'>Logs</a></li>
3
- <li <%= class_if_current(url_path("analytics")) %>><a href="<%=h url_path("analytics") %>" data-pjax='#mainPjax'>Analytics</a></li>
2
+ <li <%= class_if_current(url_path("overview")) %>><a href="<%=h url_path("overview") %>">Logs</a></li>
3
+ <li <%= class_if_current(url_path("analytics")) %>><a href="<%=h url_path("analytics") %>">Analytics</a></li>
4
4
  </ul>