chillout 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (425) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +45 -9
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +8 -0
  6. data/README.md +43 -7
  7. data/Rakefile +17 -2
  8. data/chillout.gemspec +21 -10
  9. data/lib/chillout/client.rb +26 -5
  10. data/lib/chillout/config.rb +15 -0
  11. data/lib/chillout/creation_listener.rb +10 -5
  12. data/lib/chillout/custom_metric.rb +27 -0
  13. data/lib/chillout/integrations/sidekiq.rb +22 -0
  14. data/lib/chillout/job.rb +12 -0
  15. data/lib/chillout/listener_injector.rb +23 -0
  16. data/lib/chillout/middleware/creations_monitor.rb +1 -1
  17. data/lib/chillout/middleware/sidekiq.rb +21 -0
  18. data/lib/chillout/railtie.rb +12 -14
  19. data/lib/chillout/server_side/dispatcher.rb +1 -1
  20. data/lib/chillout/server_side/plain_http_client.rb +22 -2
  21. data/lib/chillout/version.rb +1 -1
  22. data/lib/chillout/worker.rb +5 -5
  23. data/lib/chillout.rb +11 -0
  24. data/test/acceptance/client_sends_metrics_test.rb +21 -0
  25. data/test/acceptance/sidekiq_workers_send_metrics_test.rb +22 -0
  26. data/test/config_test.rb +31 -1
  27. data/test/custom_metric_test.rb +15 -0
  28. data/test/event_data_builder_test.rb +47 -41
  29. data/test/integration/client_test.rb +78 -4
  30. data/test/integration/worker_test.rb +3 -2
  31. data/test/middleware/creations_monitor_test.rb +28 -29
  32. data/test/middleware/sidekiq_test.rb +45 -0
  33. data/test/plain_http_client_test.rb +13 -0
  34. data/test/support/rails_3_2_13/Gemfile +5 -0
  35. data/test/support/rails_3_2_13/Rakefile +7 -0
  36. data/test/support/rails_3_2_13/app/controllers/application_controller.rb +3 -0
  37. data/test/support/rails_3_2_13/app/controllers/entities_controller.rb +70 -0
  38. data/test/support/rails_3_2_13/app/helpers/application_helper.rb +2 -0
  39. data/test/support/rails_3_2_13/app/models/entity.rb +3 -0
  40. data/test/support/rails_3_2_13/app/views/entities/_form.html.erb +21 -0
  41. data/test/support/rails_3_2_13/app/views/entities/edit.html.erb +6 -0
  42. data/test/support/rails_3_2_13/app/views/entities/index.html.erb +23 -0
  43. data/test/support/rails_3_2_13/app/views/entities/new.html.erb +5 -0
  44. data/test/support/rails_3_2_13/app/views/entities/show.html.erb +10 -0
  45. data/test/support/rails_3_2_13/app/views/layouts/application.html.erb +14 -0
  46. data/test/support/rails_3_2_13/config/application.rb +63 -0
  47. data/test/support/rails_3_2_13/config/boot.rb +6 -0
  48. data/test/support/rails_3_2_13/config/database.yml +11 -0
  49. data/test/support/rails_3_2_13/config/environment.rb +5 -0
  50. data/test/support/rails_3_2_13/config/environments/development.rb +32 -0
  51. data/test/support/rails_3_2_13/config/environments/production.rb +56 -0
  52. data/test/support/rails_3_2_13/config/environments/test.rb +37 -0
  53. data/test/support/rails_3_2_13/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/support/rails_3_2_13/config/initializers/inflections.rb +15 -0
  55. data/test/support/rails_3_2_13/config/initializers/load_schema.rb +4 -0
  56. data/test/support/rails_3_2_13/config/initializers/mime_types.rb +5 -0
  57. data/test/support/rails_3_2_13/config/initializers/secret_token.rb +7 -0
  58. data/test/support/rails_3_2_13/config/initializers/session_store.rb +8 -0
  59. data/test/support/rails_3_2_13/config/initializers/wrap_parameters.rb +14 -0
  60. data/test/support/rails_3_2_13/config/locales/en.yml +5 -0
  61. data/test/support/rails_3_2_13/config/routes.rb +3 -0
  62. data/test/support/rails_3_2_13/config.ru +4 -0
  63. data/test/support/rails_3_2_13/db/schema.rb +22 -0
  64. data/test/support/rails_3_2_13/public/404.html +26 -0
  65. data/test/support/rails_3_2_13/public/422.html +26 -0
  66. data/test/support/rails_3_2_13/public/500.html +25 -0
  67. data/test/support/rails_3_2_13/public/favicon.ico +0 -0
  68. data/test/support/rails_3_2_13/public/robots.txt +5 -0
  69. data/test/support/rails_3_2_13/script/rails +6 -0
  70. data/test/support/rails_4_0_0/Gemfile +5 -0
  71. data/test/support/rails_4_0_0/Rakefile +6 -0
  72. data/test/support/rails_4_0_0/app/controllers/application_controller.rb +5 -0
  73. data/test/support/rails_4_0_0/app/controllers/concerns/.keep +0 -0
  74. data/test/support/rails_4_0_0/app/controllers/entities_controller.rb +70 -0
  75. data/test/support/rails_4_0_0/app/helpers/application_helper.rb +2 -0
  76. data/test/support/rails_4_0_0/app/models/.keep +0 -0
  77. data/test/support/rails_4_0_0/app/models/concerns/.keep +0 -0
  78. data/test/support/rails_4_0_0/app/models/entity.rb +2 -0
  79. data/test/support/rails_4_0_0/app/views/entities/_form.html.erb +21 -0
  80. data/test/support/rails_4_0_0/app/views/entities/edit.html.erb +6 -0
  81. data/test/support/rails_4_0_0/app/views/entities/index.html.erb +23 -0
  82. data/test/support/rails_4_0_0/app/views/entities/new.html.erb +5 -0
  83. data/test/support/rails_4_0_0/app/views/entities/show.html.erb +10 -0
  84. data/test/support/rails_4_0_0/app/views/layouts/application.html.erb +14 -0
  85. data/test/support/rails_4_0_0/config/application.rb +31 -0
  86. data/test/support/rails_4_0_0/config/boot.rb +4 -0
  87. data/test/support/rails_4_0_0/config/database.yml +11 -0
  88. data/test/support/rails_4_0_0/config/environment.rb +5 -0
  89. data/test/support/rails_4_0_0/config/environments/development.rb +25 -0
  90. data/test/support/rails_4_0_0/config/environments/production.rb +67 -0
  91. data/test/support/rails_4_0_0/config/environments/test.rb +36 -0
  92. data/test/support/rails_4_0_0/config/initializers/backtrace_silencers.rb +7 -0
  93. data/test/support/rails_4_0_0/config/initializers/filter_parameter_logging.rb +4 -0
  94. data/test/support/rails_4_0_0/config/initializers/inflections.rb +16 -0
  95. data/test/support/rails_4_0_0/config/initializers/load_schema.rb +4 -0
  96. data/test/support/rails_4_0_0/config/initializers/mime_types.rb +5 -0
  97. data/test/support/rails_4_0_0/config/initializers/secret_token.rb +12 -0
  98. data/test/support/rails_4_0_0/config/initializers/session_store.rb +3 -0
  99. data/test/support/rails_4_0_0/config/initializers/wrap_parameters.rb +14 -0
  100. data/test/support/rails_4_0_0/config/locales/en.yml +23 -0
  101. data/test/support/rails_4_0_0/config/routes.rb +3 -0
  102. data/test/support/rails_4_0_0/config.ru +4 -0
  103. data/test/support/rails_4_0_0/db/schema.rb +22 -0
  104. data/test/support/rails_4_0_0/lib/assets/.keep +0 -0
  105. data/test/support/rails_4_0_0/lib/tasks/.keep +0 -0
  106. data/test/support/rails_4_0_0/public/404.html +58 -0
  107. data/test/support/rails_4_0_0/public/422.html +58 -0
  108. data/test/support/rails_4_0_0/public/500.html +57 -0
  109. data/test/support/rails_4_0_0/public/favicon.ico +0 -0
  110. data/test/support/rails_4_0_0/public/robots.txt +5 -0
  111. data/test/support/rails_4_0_0/script/bundle +3 -0
  112. data/test/support/rails_4_0_0/script/rails +4 -0
  113. data/test/support/rails_4_0_0/script/rake +4 -0
  114. data/test/support/rails_4_0_13/Gemfile +5 -0
  115. data/test/support/rails_4_0_13/Rakefile +6 -0
  116. data/test/support/rails_4_0_13/app/controllers/application_controller.rb +5 -0
  117. data/test/support/rails_4_0_13/app/controllers/concerns/.keep +0 -0
  118. data/test/support/rails_4_0_13/app/controllers/entities_controller.rb +70 -0
  119. data/test/support/rails_4_0_13/app/helpers/application_helper.rb +2 -0
  120. data/test/support/rails_4_0_13/app/models/.keep +0 -0
  121. data/test/support/rails_4_0_13/app/models/concerns/.keep +0 -0
  122. data/test/support/rails_4_0_13/app/models/entity.rb +2 -0
  123. data/test/support/rails_4_0_13/app/views/entities/_form.html.erb +21 -0
  124. data/test/support/rails_4_0_13/app/views/entities/edit.html.erb +6 -0
  125. data/test/support/rails_4_0_13/app/views/entities/index.html.erb +23 -0
  126. data/test/support/rails_4_0_13/app/views/entities/new.html.erb +5 -0
  127. data/test/support/rails_4_0_13/app/views/entities/show.html.erb +10 -0
  128. data/test/support/rails_4_0_13/app/views/layouts/application.html.erb +14 -0
  129. data/test/support/rails_4_0_13/config/application.rb +31 -0
  130. data/test/support/rails_4_0_13/config/boot.rb +4 -0
  131. data/test/support/rails_4_0_13/config/database.yml +11 -0
  132. data/test/support/rails_4_0_13/config/environment.rb +5 -0
  133. data/test/support/rails_4_0_13/config/environments/development.rb +25 -0
  134. data/test/support/rails_4_0_13/config/environments/production.rb +67 -0
  135. data/test/support/rails_4_0_13/config/environments/test.rb +36 -0
  136. data/test/support/rails_4_0_13/config/initializers/backtrace_silencers.rb +7 -0
  137. data/test/support/rails_4_0_13/config/initializers/filter_parameter_logging.rb +4 -0
  138. data/test/support/rails_4_0_13/config/initializers/inflections.rb +16 -0
  139. data/test/support/rails_4_0_13/config/initializers/load_schema.rb +4 -0
  140. data/test/support/rails_4_0_13/config/initializers/mime_types.rb +5 -0
  141. data/test/support/rails_4_0_13/config/initializers/secret_token.rb +12 -0
  142. data/test/support/rails_4_0_13/config/initializers/session_store.rb +3 -0
  143. data/test/support/rails_4_0_13/config/initializers/wrap_parameters.rb +14 -0
  144. data/test/support/rails_4_0_13/config/locales/en.yml +23 -0
  145. data/test/support/rails_4_0_13/config/routes.rb +3 -0
  146. data/test/support/rails_4_0_13/config.ru +4 -0
  147. data/test/support/rails_4_0_13/db/schema.rb +22 -0
  148. data/test/support/rails_4_0_13/lib/assets/.keep +0 -0
  149. data/test/support/rails_4_0_13/lib/tasks/.keep +0 -0
  150. data/test/support/rails_4_0_13/public/404.html +58 -0
  151. data/test/support/rails_4_0_13/public/422.html +58 -0
  152. data/test/support/rails_4_0_13/public/500.html +57 -0
  153. data/test/support/rails_4_0_13/public/favicon.ico +0 -0
  154. data/test/support/rails_4_0_13/public/robots.txt +5 -0
  155. data/test/support/rails_4_0_13/script/bundle +3 -0
  156. data/test/support/rails_4_0_13/script/rails +4 -0
  157. data/test/support/rails_4_0_13/script/rake +4 -0
  158. data/test/support/rails_4_1_0/Gemfile +5 -0
  159. data/test/support/rails_4_1_0/Rakefile +6 -0
  160. data/test/support/rails_4_1_0/app/controllers/application_controller.rb +5 -0
  161. data/test/support/rails_4_1_0/app/controllers/concerns/.keep +0 -0
  162. data/test/support/rails_4_1_0/app/controllers/entities_controller.rb +70 -0
  163. data/test/support/rails_4_1_0/app/helpers/application_helper.rb +2 -0
  164. data/test/support/rails_4_1_0/app/models/.keep +0 -0
  165. data/test/support/rails_4_1_0/app/models/concerns/.keep +0 -0
  166. data/test/support/rails_4_1_0/app/models/entity.rb +2 -0
  167. data/test/support/rails_4_1_0/app/views/entities/_form.html.erb +21 -0
  168. data/test/support/rails_4_1_0/app/views/entities/edit.html.erb +6 -0
  169. data/test/support/rails_4_1_0/app/views/entities/index.html.erb +23 -0
  170. data/test/support/rails_4_1_0/app/views/entities/new.html.erb +5 -0
  171. data/test/support/rails_4_1_0/app/views/entities/show.html.erb +10 -0
  172. data/test/support/rails_4_1_0/app/views/layouts/application.html.erb +14 -0
  173. data/test/support/rails_4_1_0/config/application.rb +31 -0
  174. data/test/support/rails_4_1_0/config/boot.rb +4 -0
  175. data/test/support/rails_4_1_0/config/database.yml +11 -0
  176. data/test/support/rails_4_1_0/config/environment.rb +5 -0
  177. data/test/support/rails_4_1_0/config/environments/development.rb +25 -0
  178. data/test/support/rails_4_1_0/config/environments/production.rb +67 -0
  179. data/test/support/rails_4_1_0/config/environments/test.rb +36 -0
  180. data/test/support/rails_4_1_0/config/initializers/backtrace_silencers.rb +7 -0
  181. data/test/support/rails_4_1_0/config/initializers/filter_parameter_logging.rb +4 -0
  182. data/test/support/rails_4_1_0/config/initializers/inflections.rb +16 -0
  183. data/test/support/rails_4_1_0/config/initializers/load_schema.rb +4 -0
  184. data/test/support/rails_4_1_0/config/initializers/mime_types.rb +5 -0
  185. data/test/support/rails_4_1_0/config/initializers/secret_token.rb +12 -0
  186. data/test/support/rails_4_1_0/config/initializers/session_store.rb +3 -0
  187. data/test/support/rails_4_1_0/config/initializers/wrap_parameters.rb +14 -0
  188. data/test/support/rails_4_1_0/config/locales/en.yml +23 -0
  189. data/test/support/rails_4_1_0/config/routes.rb +3 -0
  190. data/test/support/rails_4_1_0/config.ru +4 -0
  191. data/test/support/rails_4_1_0/db/schema.rb +22 -0
  192. data/test/support/rails_4_1_0/lib/assets/.keep +0 -0
  193. data/test/support/rails_4_1_0/lib/tasks/.keep +0 -0
  194. data/test/support/rails_4_1_0/public/404.html +58 -0
  195. data/test/support/rails_4_1_0/public/422.html +58 -0
  196. data/test/support/rails_4_1_0/public/500.html +57 -0
  197. data/test/support/rails_4_1_0/public/favicon.ico +0 -0
  198. data/test/support/rails_4_1_0/public/robots.txt +5 -0
  199. data/test/support/rails_4_1_0/script/bundle +3 -0
  200. data/test/support/rails_4_1_0/script/rails +4 -0
  201. data/test/support/rails_4_1_0/script/rake +4 -0
  202. data/test/support/rails_4_1_16/Gemfile +5 -0
  203. data/test/support/rails_4_1_16/Rakefile +6 -0
  204. data/test/support/rails_4_1_16/app/controllers/application_controller.rb +5 -0
  205. data/test/support/rails_4_1_16/app/controllers/concerns/.keep +0 -0
  206. data/test/support/rails_4_1_16/app/controllers/entities_controller.rb +70 -0
  207. data/test/support/rails_4_1_16/app/helpers/application_helper.rb +2 -0
  208. data/test/support/rails_4_1_16/app/models/.keep +0 -0
  209. data/test/support/rails_4_1_16/app/models/concerns/.keep +0 -0
  210. data/test/support/rails_4_1_16/app/models/entity.rb +2 -0
  211. data/test/support/rails_4_1_16/app/views/entities/_form.html.erb +21 -0
  212. data/test/support/rails_4_1_16/app/views/entities/edit.html.erb +6 -0
  213. data/test/support/rails_4_1_16/app/views/entities/index.html.erb +23 -0
  214. data/test/support/rails_4_1_16/app/views/entities/new.html.erb +5 -0
  215. data/test/support/rails_4_1_16/app/views/entities/show.html.erb +10 -0
  216. data/test/support/rails_4_1_16/app/views/layouts/application.html.erb +14 -0
  217. data/test/support/rails_4_1_16/config/application.rb +31 -0
  218. data/test/support/rails_4_1_16/config/boot.rb +4 -0
  219. data/test/support/rails_4_1_16/config/database.yml +11 -0
  220. data/test/support/rails_4_1_16/config/environment.rb +5 -0
  221. data/test/support/rails_4_1_16/config/environments/development.rb +25 -0
  222. data/test/support/rails_4_1_16/config/environments/production.rb +67 -0
  223. data/test/support/rails_4_1_16/config/environments/test.rb +36 -0
  224. data/test/support/rails_4_1_16/config/initializers/backtrace_silencers.rb +7 -0
  225. data/test/support/rails_4_1_16/config/initializers/filter_parameter_logging.rb +4 -0
  226. data/test/support/rails_4_1_16/config/initializers/inflections.rb +16 -0
  227. data/test/support/rails_4_1_16/config/initializers/load_schema.rb +4 -0
  228. data/test/support/rails_4_1_16/config/initializers/mime_types.rb +5 -0
  229. data/test/support/rails_4_1_16/config/initializers/secret_token.rb +12 -0
  230. data/test/support/rails_4_1_16/config/initializers/session_store.rb +3 -0
  231. data/test/support/rails_4_1_16/config/initializers/wrap_parameters.rb +14 -0
  232. data/test/support/rails_4_1_16/config/locales/en.yml +23 -0
  233. data/test/support/rails_4_1_16/config/routes.rb +3 -0
  234. data/test/support/rails_4_1_16/config.ru +4 -0
  235. data/test/support/rails_4_1_16/db/schema.rb +22 -0
  236. data/test/support/rails_4_1_16/lib/assets/.keep +0 -0
  237. data/test/support/rails_4_1_16/lib/tasks/.keep +0 -0
  238. data/test/support/rails_4_1_16/public/404.html +58 -0
  239. data/test/support/rails_4_1_16/public/422.html +58 -0
  240. data/test/support/rails_4_1_16/public/500.html +57 -0
  241. data/test/support/rails_4_1_16/public/favicon.ico +0 -0
  242. data/test/support/rails_4_1_16/public/robots.txt +5 -0
  243. data/test/support/rails_4_1_16/script/bundle +3 -0
  244. data/test/support/rails_4_1_16/script/rails +4 -0
  245. data/test/support/rails_4_1_16/script/rake +4 -0
  246. data/test/support/rails_4_2_0/Gemfile +5 -0
  247. data/test/support/rails_4_2_0/Rakefile +6 -0
  248. data/test/support/rails_4_2_0/app/controllers/application_controller.rb +5 -0
  249. data/test/support/rails_4_2_0/app/controllers/concerns/.keep +0 -0
  250. data/test/support/rails_4_2_0/app/controllers/entities_controller.rb +70 -0
  251. data/test/support/rails_4_2_0/app/helpers/application_helper.rb +2 -0
  252. data/test/support/rails_4_2_0/app/models/.keep +0 -0
  253. data/test/support/rails_4_2_0/app/models/concerns/.keep +0 -0
  254. data/test/support/rails_4_2_0/app/models/entity.rb +2 -0
  255. data/test/support/rails_4_2_0/app/views/entities/_form.html.erb +21 -0
  256. data/test/support/rails_4_2_0/app/views/entities/edit.html.erb +6 -0
  257. data/test/support/rails_4_2_0/app/views/entities/index.html.erb +23 -0
  258. data/test/support/rails_4_2_0/app/views/entities/new.html.erb +5 -0
  259. data/test/support/rails_4_2_0/app/views/entities/show.html.erb +10 -0
  260. data/test/support/rails_4_2_0/app/views/layouts/application.html.erb +14 -0
  261. data/test/support/rails_4_2_0/config/application.rb +31 -0
  262. data/test/support/rails_4_2_0/config/boot.rb +4 -0
  263. data/test/support/rails_4_2_0/config/database.yml +11 -0
  264. data/test/support/rails_4_2_0/config/environment.rb +5 -0
  265. data/test/support/rails_4_2_0/config/environments/development.rb +25 -0
  266. data/test/support/rails_4_2_0/config/environments/production.rb +67 -0
  267. data/test/support/rails_4_2_0/config/environments/test.rb +36 -0
  268. data/test/support/rails_4_2_0/config/initializers/backtrace_silencers.rb +7 -0
  269. data/test/support/rails_4_2_0/config/initializers/filter_parameter_logging.rb +4 -0
  270. data/test/support/rails_4_2_0/config/initializers/inflections.rb +16 -0
  271. data/test/support/rails_4_2_0/config/initializers/load_schema.rb +4 -0
  272. data/test/support/rails_4_2_0/config/initializers/mime_types.rb +5 -0
  273. data/test/support/rails_4_2_0/config/initializers/secret_token.rb +12 -0
  274. data/test/support/rails_4_2_0/config/initializers/session_store.rb +3 -0
  275. data/test/support/rails_4_2_0/config/initializers/wrap_parameters.rb +14 -0
  276. data/test/support/rails_4_2_0/config/locales/en.yml +23 -0
  277. data/test/support/rails_4_2_0/config/routes.rb +3 -0
  278. data/test/support/rails_4_2_0/config.ru +4 -0
  279. data/test/support/rails_4_2_0/db/schema.rb +22 -0
  280. data/test/support/rails_4_2_0/lib/assets/.keep +0 -0
  281. data/test/support/rails_4_2_0/lib/tasks/.keep +0 -0
  282. data/test/support/rails_4_2_0/public/404.html +58 -0
  283. data/test/support/rails_4_2_0/public/422.html +58 -0
  284. data/test/support/rails_4_2_0/public/500.html +57 -0
  285. data/test/support/rails_4_2_0/public/favicon.ico +0 -0
  286. data/test/support/rails_4_2_0/public/robots.txt +5 -0
  287. data/test/support/rails_4_2_0/script/bundle +3 -0
  288. data/test/support/rails_4_2_0/script/rails +4 -0
  289. data/test/support/rails_4_2_0/script/rake +4 -0
  290. data/test/support/rails_4_2_8/Gemfile +5 -0
  291. data/test/support/rails_4_2_8/Rakefile +6 -0
  292. data/test/support/rails_4_2_8/app/controllers/application_controller.rb +5 -0
  293. data/test/support/rails_4_2_8/app/controllers/concerns/.keep +0 -0
  294. data/test/support/rails_4_2_8/app/controllers/entities_controller.rb +70 -0
  295. data/test/support/rails_4_2_8/app/helpers/application_helper.rb +2 -0
  296. data/test/support/rails_4_2_8/app/models/.keep +0 -0
  297. data/test/support/rails_4_2_8/app/models/concerns/.keep +0 -0
  298. data/test/support/rails_4_2_8/app/models/entity.rb +2 -0
  299. data/test/support/rails_4_2_8/app/views/entities/_form.html.erb +21 -0
  300. data/test/support/rails_4_2_8/app/views/entities/edit.html.erb +6 -0
  301. data/test/support/rails_4_2_8/app/views/entities/index.html.erb +23 -0
  302. data/test/support/rails_4_2_8/app/views/entities/new.html.erb +5 -0
  303. data/test/support/rails_4_2_8/app/views/entities/show.html.erb +10 -0
  304. data/test/support/rails_4_2_8/app/views/layouts/application.html.erb +14 -0
  305. data/test/support/rails_4_2_8/config/application.rb +34 -0
  306. data/test/support/rails_4_2_8/config/boot.rb +4 -0
  307. data/test/support/rails_4_2_8/config/database.yml +11 -0
  308. data/test/support/rails_4_2_8/config/environment.rb +5 -0
  309. data/test/support/rails_4_2_8/config/environments/development.rb +25 -0
  310. data/test/support/rails_4_2_8/config/environments/production.rb +73 -0
  311. data/test/support/rails_4_2_8/config/environments/test.rb +36 -0
  312. data/test/support/rails_4_2_8/config/initializers/backtrace_silencers.rb +7 -0
  313. data/test/support/rails_4_2_8/config/initializers/filter_parameter_logging.rb +4 -0
  314. data/test/support/rails_4_2_8/config/initializers/inflections.rb +16 -0
  315. data/test/support/rails_4_2_8/config/initializers/load_schema.rb +4 -0
  316. data/test/support/rails_4_2_8/config/initializers/mime_types.rb +5 -0
  317. data/test/support/rails_4_2_8/config/initializers/secret_token.rb +12 -0
  318. data/test/support/rails_4_2_8/config/initializers/session_store.rb +3 -0
  319. data/test/support/rails_4_2_8/config/initializers/wrap_parameters.rb +14 -0
  320. data/test/support/rails_4_2_8/config/locales/en.yml +23 -0
  321. data/test/support/rails_4_2_8/config/routes.rb +3 -0
  322. data/test/support/rails_4_2_8/config.ru +4 -0
  323. data/test/support/rails_4_2_8/db/schema.rb +22 -0
  324. data/test/support/rails_4_2_8/lib/assets/.keep +0 -0
  325. data/test/support/rails_4_2_8/lib/tasks/.keep +0 -0
  326. data/test/support/rails_4_2_8/public/404.html +58 -0
  327. data/test/support/rails_4_2_8/public/422.html +58 -0
  328. data/test/support/rails_4_2_8/public/500.html +57 -0
  329. data/test/support/rails_4_2_8/public/favicon.ico +0 -0
  330. data/test/support/rails_4_2_8/public/robots.txt +5 -0
  331. data/test/support/rails_4_2_8/script/bundle +3 -0
  332. data/test/support/rails_4_2_8/script/rails +4 -0
  333. data/test/support/rails_4_2_8/script/rake +4 -0
  334. data/test/support/rails_5_0_3/Gemfile +5 -0
  335. data/test/support/rails_5_0_3/Rakefile +6 -0
  336. data/test/support/rails_5_0_3/app/controllers/application_controller.rb +5 -0
  337. data/test/support/rails_5_0_3/app/controllers/concerns/.keep +0 -0
  338. data/test/support/rails_5_0_3/app/controllers/entities_controller.rb +70 -0
  339. data/test/support/rails_5_0_3/app/helpers/application_helper.rb +2 -0
  340. data/test/support/rails_5_0_3/app/models/.keep +0 -0
  341. data/test/support/rails_5_0_3/app/models/concerns/.keep +0 -0
  342. data/test/support/rails_5_0_3/app/models/entity.rb +2 -0
  343. data/test/support/rails_5_0_3/app/views/entities/_form.html.erb +21 -0
  344. data/test/support/rails_5_0_3/app/views/entities/edit.html.erb +6 -0
  345. data/test/support/rails_5_0_3/app/views/entities/index.html.erb +23 -0
  346. data/test/support/rails_5_0_3/app/views/entities/new.html.erb +5 -0
  347. data/test/support/rails_5_0_3/app/views/entities/show.html.erb +10 -0
  348. data/test/support/rails_5_0_3/app/views/layouts/application.html.erb +14 -0
  349. data/test/support/rails_5_0_3/config/application.rb +30 -0
  350. data/test/support/rails_5_0_3/config/boot.rb +4 -0
  351. data/test/support/rails_5_0_3/config/database.yml +11 -0
  352. data/test/support/rails_5_0_3/config/environment.rb +5 -0
  353. data/test/support/rails_5_0_3/config/environments/development.rb +25 -0
  354. data/test/support/rails_5_0_3/config/environments/production.rb +73 -0
  355. data/test/support/rails_5_0_3/config/environments/test.rb +36 -0
  356. data/test/support/rails_5_0_3/config/initializers/backtrace_silencers.rb +7 -0
  357. data/test/support/rails_5_0_3/config/initializers/filter_parameter_logging.rb +4 -0
  358. data/test/support/rails_5_0_3/config/initializers/inflections.rb +16 -0
  359. data/test/support/rails_5_0_3/config/initializers/load_schema.rb +4 -0
  360. data/test/support/rails_5_0_3/config/initializers/mime_types.rb +5 -0
  361. data/test/support/rails_5_0_3/config/initializers/secret_token.rb +12 -0
  362. data/test/support/rails_5_0_3/config/initializers/session_store.rb +3 -0
  363. data/test/support/rails_5_0_3/config/initializers/wrap_parameters.rb +14 -0
  364. data/test/support/rails_5_0_3/config/locales/en.yml +23 -0
  365. data/test/support/rails_5_0_3/config/routes.rb +3 -0
  366. data/test/support/rails_5_0_3/config.ru +4 -0
  367. data/test/support/rails_5_0_3/db/schema.rb +22 -0
  368. data/test/support/rails_5_0_3/lib/assets/.keep +0 -0
  369. data/test/support/rails_5_0_3/lib/tasks/.keep +0 -0
  370. data/test/support/rails_5_0_3/public/404.html +58 -0
  371. data/test/support/rails_5_0_3/public/422.html +58 -0
  372. data/test/support/rails_5_0_3/public/500.html +57 -0
  373. data/test/support/rails_5_0_3/public/favicon.ico +0 -0
  374. data/test/support/rails_5_0_3/public/robots.txt +5 -0
  375. data/test/support/rails_5_0_3/script/bundle +3 -0
  376. data/test/support/rails_5_0_3/script/rails +4 -0
  377. data/test/support/rails_5_0_3/script/rake +4 -0
  378. data/test/support/rails_5_1_1/Gemfile +6 -0
  379. data/test/support/rails_5_1_1/Rakefile +6 -0
  380. data/test/support/rails_5_1_1/app/controllers/application_controller.rb +5 -0
  381. data/test/support/rails_5_1_1/app/controllers/concerns/.keep +0 -0
  382. data/test/support/rails_5_1_1/app/controllers/entities_controller.rb +70 -0
  383. data/test/support/rails_5_1_1/app/helpers/application_helper.rb +2 -0
  384. data/test/support/rails_5_1_1/app/jobs/create_entity_job.rb +6 -0
  385. data/test/support/rails_5_1_1/app/models/.keep +0 -0
  386. data/test/support/rails_5_1_1/app/models/concerns/.keep +0 -0
  387. data/test/support/rails_5_1_1/app/models/entity.rb +2 -0
  388. data/test/support/rails_5_1_1/app/views/entities/_form.html.erb +21 -0
  389. data/test/support/rails_5_1_1/app/views/entities/edit.html.erb +6 -0
  390. data/test/support/rails_5_1_1/app/views/entities/index.html.erb +23 -0
  391. data/test/support/rails_5_1_1/app/views/entities/new.html.erb +5 -0
  392. data/test/support/rails_5_1_1/app/views/entities/show.html.erb +10 -0
  393. data/test/support/rails_5_1_1/app/views/layouts/application.html.erb +14 -0
  394. data/test/support/rails_5_1_1/config/application.rb +30 -0
  395. data/test/support/rails_5_1_1/config/boot.rb +4 -0
  396. data/test/support/rails_5_1_1/config/database.yml +11 -0
  397. data/test/support/rails_5_1_1/config/environment.rb +5 -0
  398. data/test/support/rails_5_1_1/config/environments/development.rb +25 -0
  399. data/test/support/rails_5_1_1/config/environments/production.rb +73 -0
  400. data/test/support/rails_5_1_1/config/environments/test.rb +36 -0
  401. data/test/support/rails_5_1_1/config/initializers/backtrace_silencers.rb +7 -0
  402. data/test/support/rails_5_1_1/config/initializers/filter_parameter_logging.rb +4 -0
  403. data/test/support/rails_5_1_1/config/initializers/inflections.rb +16 -0
  404. data/test/support/rails_5_1_1/config/initializers/load_schema.rb +4 -0
  405. data/test/support/rails_5_1_1/config/initializers/mime_types.rb +5 -0
  406. data/test/support/rails_5_1_1/config/initializers/secret_token.rb +12 -0
  407. data/test/support/rails_5_1_1/config/initializers/session_store.rb +3 -0
  408. data/test/support/rails_5_1_1/config/initializers/wrap_parameters.rb +14 -0
  409. data/test/support/rails_5_1_1/config/locales/en.yml +23 -0
  410. data/test/support/rails_5_1_1/config/routes.rb +3 -0
  411. data/test/support/rails_5_1_1/config.ru +4 -0
  412. data/test/support/rails_5_1_1/db/schema.rb +22 -0
  413. data/test/support/rails_5_1_1/lib/assets/.keep +0 -0
  414. data/test/support/rails_5_1_1/lib/tasks/.keep +0 -0
  415. data/test/support/rails_5_1_1/public/404.html +58 -0
  416. data/test/support/rails_5_1_1/public/422.html +58 -0
  417. data/test/support/rails_5_1_1/public/500.html +57 -0
  418. data/test/support/rails_5_1_1/public/favicon.ico +0 -0
  419. data/test/support/rails_5_1_1/public/robots.txt +5 -0
  420. data/test/support/rails_5_1_1/script/bundle +3 -0
  421. data/test/support/rails_5_1_1/script/rails +4 -0
  422. data/test/support/rails_5_1_1/script/rake +4 -0
  423. data/test/test_helper.rb +149 -11
  424. data/test/worker_test.rb +1 -1
  425. metadata +974 -143
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 197e690562925f6ce9309e2545460a42280ca5d9
4
+ data.tar.gz: d130742ff61be6f59e38a2f389bc424f66feeeac
5
+ SHA512:
6
+ metadata.gz: 1929db6e6dcc8816f58cd33760443bda3b3c201f10f207808ceb26cc4307919e67c73d7cb3d1852e05eae6f41366563f1fdaf3f3b0db568c3fc6e409e9b3630a
7
+ data.tar.gz: ca1ba2c6c1e335394f303e506636a8d2bfb0126e81b366145eec930780746ad464fe3fbc67491197267e79b0d61952cafeb7ece3bbfd3c1dd94562d5949b8d5a
data/.gitignore CHANGED
@@ -16,3 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rbx
19
+ database.db
20
+ log/
21
+ tmp/
data/.travis.yml CHANGED
@@ -1,11 +1,47 @@
1
+ before_script: bundle exec rake bundle
2
+ script: bundle exec rake test
1
3
  language: ruby
2
4
  rvm:
3
- - 2.0.0-p0
4
- - 1.9.3
5
- - 1.9.2
6
- - 1.8.7
7
- - ree
8
- - jruby-18mode
9
- - jruby-19mode
10
- - rbx-18mode
11
- - rbx-19mode
5
+ - 2.4.1
6
+ - 2.3.4
7
+ - 2.2.7
8
+ - 2.1.10
9
+ env:
10
+ - SAMPLE_APP=rails_4_0_0
11
+ - SAMPLE_APP=rails_4_0_13
12
+ - SAMPLE_APP=rails_4_1_0
13
+ - SAMPLE_APP=rails_4_1_16
14
+ - SAMPLE_APP=rails_4_2_0
15
+ - SAMPLE_APP=rails_4_2_8
16
+ - SAMPLE_APP=rails_5_0_3
17
+ - SAMPLE_APP=rails_5_1_1 SIDEKIQ_SUPPORTED=true
18
+ matrix:
19
+ exclude:
20
+ - rvm: 2.4.1
21
+ env: SAMPLE_APP=rails_4_0_0
22
+ - rvm: 2.4.1
23
+ env: SAMPLE_APP=rails_4_0_13
24
+ - rvm: 2.4.1
25
+ env: SAMPLE_APP=rails_4_1_0
26
+ - rvm: 2.4.1
27
+ env: SAMPLE_APP=rails_4_1_16
28
+ - rvm: 2.4.1
29
+ env: SAMPLE_APP=rails_4_2_0
30
+ - rvm: 2.1.10
31
+ env: SAMPLE_APP=rails_4_2_8
32
+ - rvm: 2.1.10
33
+ env: SAMPLE_APP=rails_5_0_3
34
+ - rvm: 2.1.10
35
+ env: SAMPLE_APP=rails_5_1_1 SIDEKIQ_SUPPORTED=true
36
+ include:
37
+ - rvm: 2.4.1
38
+ env: SAMPLE_APP=rails_4_2_8 STRATEGY=active_job
39
+ - rvm: 2.4.1
40
+ env: SAMPLE_APP=rails_5_0_3 STRATEGY=active_job
41
+ - rvm: 2.4.1
42
+ env: SAMPLE_APP=rails_5_1_1 STRATEGY=active_job SIDEKIQ_SUPPORTED=true
43
+ notifications:
44
+ slack:
45
+ secure: 6IAlvKplFv94Vaf0LES197FFIgt5cs1fUFA9820mmeoTGLDQcN+4Hpv+2/NRRqrfb2k+V+uFKmsuY8azHBoKHLIzH6d1T0NS82j54Ti+tm0iFZaKLHVp8TxuIge0/e0Niamod5mMziLTg6KcM+zNBYcoxS3th1mQNWQ2mtD9JZ8=
46
+ services:
47
+ - redis-server
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # chillout gem changes
2
+
3
+ 0.8.0
4
+ -----
5
+
6
+ - Introduce `active_job` strategy for sending metrics to chillout servers
7
+ - Add `sidekiq` integration. Metrics collected when processing sidekiq jobs are sent to the server
8
+ - Support for Mongoid removed.
9
+
10
+ 0.7.0 (never released)
11
+ ----------------------
12
+
13
+ - Support for custom metrics
14
+ - Support for Mongoid
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "bbq-spawn", git: 'https://github.com/drugpl/bbq-spawn.git'
4
+
3
5
  # Specify your gem's dependencies in chillout.gemspec
4
6
  gemspec
7
+
8
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
9
+ gem "rack", "1.6"
10
+ gem "activejob", "= 4.2.8"
11
+ gem "sidekiq", "~> 4.2"
12
+ end
data/README.md CHANGED
@@ -4,9 +4,11 @@
4
4
  [![Code Climate](https://codeclimate.com/github/chilloutio/chillout.png)](https://codeclimate.com/github/chilloutio/chillout)
5
5
  [![Gem Version](https://badge.fury.io/rb/chillout.png)](http://badge.fury.io/rb/chillout)
6
6
 
7
+ Chillout gem tracks your ActiveRecord models statistics. You can see the metrics for your application in a grafana dashboard. Please visit [get.chillout.io](http://get.chillout.io/) for more details.
8
+
7
9
  ## Installation
8
10
 
9
- Add this line to your Rails application's Gemfile:
11
+ Add this line to your Rails application's `Gemfile`:
10
12
 
11
13
  gem 'chillout'
12
14
 
@@ -14,14 +16,48 @@ And then execute:
14
16
 
15
17
  $ bundle
16
18
 
17
- And run Rails generator:
19
+ And add following line to `config/environments/production.rb` with your own `SECRET_KEY`:
20
+
21
+ config.chillout = { secret: 'SECRET_KEY' }
22
+
23
+ And that's all!
24
+
25
+ ## Usage
26
+
27
+ chillout gem is automatically tracking your model creations. Remember you have to be in `production` environment - otherwise chillout gem will NOT track your metrics.
28
+
29
+ ### Custom metrics
30
+
31
+ You can use `Chillout::Metric.track('custom_name')` to track a custom, phony metric. It's quite useful when you want to track a certain business process, like:
32
+
33
+ ```
34
+ # in 'new':
35
+ Chillout::Metric.track('RegistrationStarted')
36
+
37
+ # in 'create':
38
+ Chillout::Metric.track('RegistrationCompleted')
39
+ ```
40
+
41
+ We encourage you to ship your own class (Adapter) which encapsulates this global constant and it's closer to your application's domain.
42
+
43
+ ## Different strategy
44
+
45
+ By default chillout uses a background thread to send metrics in a non-blocking way. However, if you prefer it can use `active_job` and the adapter you configured for it ie. sidekiq, resque, delayed_job, etc.
46
+
47
+ ```ruby
48
+ config.chillout = {secret: 'secret', strategy: :active_job}
49
+ ```
50
+
51
+ This feature is available since Rails 4.2
18
52
 
19
- $ rails g chillout:install EMAIL EMAIL2...
53
+ ## Compatibility
20
54
 
21
- And that's all! You can find whole configuration in config/environments/production.rb under ```chillout``` key.
55
+ Chillout gem is tested using Travis CI. You can [check it](https://travis-ci.org/chilloutio/chillout) to get insight about which versions of Rails and Rubies are actually supported. We provide listeners for ActiveRecord.
22
56
 
23
- Check if everything is ok:
57
+ ## Development
24
58
 
25
- $ RAILS_ENV=production rake chillout:check
59
+ Running complete test suite:
26
60
 
27
- You'll see "Chillout API available" if everything is ok. Otherwise you'll be informed about problem with authorization (maybe you've put wrong secret?) or not known problems, like invalid values in configuration.
61
+ bundle install
62
+ bundle exec rake bundle
63
+ bundle exec rake test
data/Rakefile CHANGED
@@ -1,10 +1,25 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
- task :default => :test
5
4
 
6
- desc 'Run chillout unit tests.'
5
+ SAMPLE_APPS = Dir.glob(File.join(File.dirname(__FILE__), 'test/support/rails_*'))
6
+
7
+ desc 'Install test dependencies.'
8
+ task :bundle do
9
+ sample_apps = if sample_app = ENV['SAMPLE_APP']
10
+ [ File.join(File.dirname(__FILE__), "test/support/#{sample_app}") ]
11
+ else
12
+ SAMPLE_APPS
13
+ end
14
+ sample_apps.each do |path|
15
+ Bundler.clean_system "bundle install --quiet --gemfile #{File.join(path, 'Gemfile')}"
16
+ end
17
+ end
18
+
19
+ desc 'Run chillout tests.'
7
20
  Rake::TestTask.new(:test) do |t|
8
21
  t.libs = %w(lib test)
9
22
  t.pattern = 'test/**/*_test.rb'
10
23
  end
24
+
25
+ task :default => :test
data/chillout.gemspec CHANGED
@@ -6,11 +6,17 @@ require 'chillout/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "chillout"
8
8
  gem.version = Chillout::VERSION
9
- gem.authors = ["Michał Łomnicki", "Jan Filipowski", "Paweł Pacana"]
10
- gem.email = ["michal.lomnicki@gmail.com", "jachuf@gmail.com", "pawel.pacana@gmail.com", "dev@arkency.com"]
11
- gem.description = "Chillout.io Ruby client"
9
+ gem.authors = ["Michał Łomnicki", "Jan Filipowski", "Paweł Pacana", "Robert Pankowecki"]
10
+ gem.email = [
11
+ "michal.lomnicki@gmail.com",
12
+ "jachuf@gmail.com",
13
+ "pawel.pacana@gmail.com",
14
+ "dev@arkency.com",
15
+ "robert.pankowecki@gmail.com"
16
+ ]
17
+ gem.description = "Chillout gem tracks your ActiveRecord models statistics."
12
18
  gem.summary = "Chillout.io Ruby client"
13
- gem.homepage = "http://chillout.io/"
19
+ gem.homepage = "http://get.chillout.io/"
14
20
 
15
21
  gem.files = `git ls-files`.split($/)
16
22
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -19,10 +25,15 @@ Gem::Specification.new do |gem|
19
25
 
20
26
  gem.add_dependency 'multi_json', '~> 1.4'
21
27
 
22
- gem.add_development_dependency "minitest", "~>3.2.0"
23
- gem.add_development_dependency "rake", "~> 0.9.2"
24
- gem.add_development_dependency "mocha", "0.12.8"
25
- gem.add_development_dependency "contest", "~> 0.1.3"
26
- gem.add_development_dependency "rack-test", "~> 0.6.2"
27
- gem.add_development_dependency "webmock", "~> 1.8.11"
28
+ gem.add_development_dependency "rake"
29
+ gem.add_development_dependency "minitest", "~> 5.1"
30
+ gem.add_development_dependency "mocha", "~> 0.14"
31
+ gem.add_development_dependency "rack-test", "~> 0.6"
32
+ gem.add_development_dependency "rack", ">= 1.6"
33
+ gem.add_development_dependency "webmock", "~> 2.3"
34
+ gem.add_development_dependency "bbq-spawn", "= 0.0.3"
35
+ gem.add_development_dependency "childprocess", "= 0.3.6"
36
+ gem.add_development_dependency "minitest-stub-const", "~> 0.6"
37
+ gem.add_development_dependency "activejob", ">= 4.2"
38
+ gem.add_development_dependency "sidekiq"
28
39
  end
@@ -30,14 +30,35 @@ module Chillout
30
30
  @event_data_builder = EventDataBuilder.new(@config).freeze
31
31
  @server_side = ServerSide.new(@event_data_builder, @http_client).freeze
32
32
  @dispatcher = Dispatcher.new(@server_side).freeze
33
- @queue = Queue.new
34
- @worker_mutex = Mutex.new
33
+ case @config.strategy
34
+ when :thread
35
+ @queue = Queue.new
36
+ @worker_mutex = Mutex.new
37
+ @worker_thread = nil
38
+ when :active_job
39
+ require 'chillout/job'
40
+ Chillout::Job.dispatcher = @dispatcher
41
+ end
42
+ end
43
+
44
+ def start
45
+ case @config.strategy
46
+ when :thread
47
+ start_worker
48
+ when :active_job
49
+ end
35
50
  end
36
51
 
37
52
  def enqueue(creations)
38
- start_worker
39
- @logger.info "Creations were enqueued."
40
- @queue << creations
53
+ case @config.strategy
54
+ when :thread
55
+ start_worker
56
+ @logger.debug "Creations were enqueued."
57
+ @queue << creations
58
+ when :active_job
59
+ @logger.debug "Creations were enqueued."
60
+ Chillout::Job.perform_later(YAML.dump(creations))
61
+ end
41
62
  end
42
63
 
43
64
  def worker_running?
@@ -22,6 +22,7 @@ module Chillout
22
22
  attr_writer :authentication_password
23
23
  attr_accessor :logger
24
24
  attr_accessor :ssl
25
+ attr_reader :strategy
25
26
 
26
27
  def initialize(api_key = nil)
27
28
  @api_key = api_key
@@ -32,6 +33,10 @@ module Chillout
32
33
  @version = VERSION
33
34
  @logger = Logger.new(STDOUT)
34
35
  @ssl = true
36
+ @strategy = :thread
37
+
38
+ @authentication_user = nil
39
+ @authentication_password = nil
35
40
  end
36
41
 
37
42
  def update(options)
@@ -40,6 +45,16 @@ module Chillout
40
45
  end
41
46
  end
42
47
 
48
+ def strategy=(name)
49
+ name = name.to_sym
50
+ precondition = {
51
+ active_job: -> { defined?(ActiveJob) or raise ArgumentError, "ActiveJob is not enabled" },
52
+ thread: -> {},
53
+ }.fetch(name, -> { raise ArgumentError, "unknown strategy" })
54
+ precondition.call
55
+ @strategy = name
56
+ end
57
+
43
58
  def authentication_user
44
59
  @authentication_user || api_key
45
60
  end
@@ -1,16 +1,21 @@
1
1
  require 'chillout/creations_container'
2
2
 
3
3
  module Chillout
4
- module CreationListener
4
+ module ActiveRecordCreationListener
5
5
  def inherited(subclass)
6
6
  super
7
- class_name = subclass.name
8
- subclass.after_commit :on => :create do
9
- Rails.logger.info "[Chillout] Model created: #{class_name}"
7
+ listen(subclass)
8
+ end
9
+
10
+ private
11
+ def listen(monitored_class)
12
+ class_name = monitored_class.name
13
+ monitored_class.after_commit :on => :create do
14
+ Rails.logger.debug "[Chillout] Model created: #{class_name}"
10
15
  Thread.current[:creations] ||= CreationsContainer.new
11
16
  creations = Thread.current[:creations]
12
17
  creations.increment!(class_name)
13
18
  end
14
19
  end
15
20
  end
16
- end
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'chillout/creations_container'
2
+
3
+ module Chillout
4
+ class CustomMetric
5
+ def initialize(creations_container = nil)
6
+ @creations_container = creations_container
7
+ end
8
+
9
+ def track(name)
10
+ creations_container.increment!(name)
11
+ end
12
+
13
+ private
14
+ def creations_container
15
+ if container_not_initialized?
16
+ Thread.current[:creations] ||= CreationsContainer.new
17
+ @creations_container = Thread.current[:creations]
18
+ else
19
+ @creations_container
20
+ end
21
+ end
22
+
23
+ def container_not_initialized?
24
+ @creations_container.nil?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ module Chillout
2
+ module Integrations
3
+
4
+ class Sidekiq
5
+ def available?
6
+ defined?(::Sidekiq) && ::Sidekiq.server?
7
+ end
8
+
9
+ def enable(client, a_module = ::Sidekiq)
10
+ require 'chillout/middleware/sidekiq'
11
+ @module = a_module
12
+ @module.server_middleware.add Middleware::SidekiqCreationsMonitor,
13
+ client: client
14
+ end
15
+
16
+ def disable
17
+ @module.server_middleware.clear
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ class Chillout::Job < ActiveJob::Base
2
+ queue_as :chillout
3
+
4
+ class << self
5
+ attr_accessor :dispatcher
6
+ end
7
+
8
+ def perform(serialized_metrics)
9
+ metrics = YAML.load(serialized_metrics)
10
+ self.class.dispatcher.send_creations(metrics)
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module Chillout
2
+ class ListenerInjector
3
+ attr_accessor :logger
4
+
5
+ LISTENERS = [:active_record]
6
+
7
+ def inject!
8
+ LISTENERS.each do |listener|
9
+ listener_injection = send("#{listener}_injector")
10
+ logger.info "[Chillout] Injected #{listener} listener" if listener_injection == true
11
+ end
12
+ end
13
+
14
+ def active_record_injector
15
+ if defined?(ActiveRecord)
16
+ ActiveRecord::Base.extend(ActiveRecordCreationListener)
17
+ return true
18
+ end
19
+
20
+ return false
21
+ end
22
+ end
23
+ end
@@ -15,7 +15,7 @@ module Chillout
15
15
  return status, headers, body
16
16
  ensure
17
17
  if Thread.current[:creations]
18
- @client.logger.info "Non-empty creations container found"
18
+ @client.logger.debug "Non-empty creations container found"
19
19
  @client.enqueue(Thread.current[:creations])
20
20
  Thread.current[:creations] = nil
21
21
  end
@@ -0,0 +1,21 @@
1
+ module Chillout
2
+ module Middleware
3
+
4
+ class SidekiqCreationsMonitor
5
+ def initialize(options)
6
+ @client = options.fetch(:client)
7
+ end
8
+
9
+ def call(_worker, _job, _queue)
10
+ yield
11
+ ensure
12
+ if Chillout.creations
13
+ creations = Chillout.creations
14
+ Chillout.creations = nil
15
+ @client.enqueue(creations)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -1,12 +1,15 @@
1
1
  require 'chillout/creation_listener'
2
+ require 'chillout/listener_injector'
2
3
 
3
4
  module Chillout
4
5
  class Railtie < Rails::Railtie
5
6
  config.chillout = ActiveSupport::OrderedOptions.new
6
7
  initializer "chillout.creations_listener_initialization" do |rails_app|
7
8
  chillout_config = rails_app.config.chillout
8
- if !chillout_config.empty?
9
+ if chillout_config.present?
9
10
  RailsInitializer.new(rails_app, chillout_config, Rails.logger).start
11
+ else
12
+ Rails.logger.debug "[Chillout] Not enabled for #{Rails.env}"
10
13
  end
11
14
  end
12
15
 
@@ -27,26 +30,21 @@ module Chillout
27
30
  @rails_logger = rails_logger
28
31
  end
29
32
 
30
- def start
33
+ def start(listeners_injector = ListenerInjector.new)
34
+ listeners_injector.logger = @rails_logger
35
+
31
36
  @rails_logger.info "[Chillout] Railtie initializing"
32
37
  client = Client.new(@chillout_config[:secret], options)
33
- ActiveRecord::Base.extend(CreationListener)
34
- @rails_logger.info "[Chillout] Creation listener attached"
38
+ listeners_injector.inject!
35
39
  @rails_app.middleware.use Middleware::CreationsMonitor, client
36
40
  @rails_logger.info "[Chillout] Creation monitor enabled"
37
- client.start_worker
41
+ sidekiq = Integrations::Sidekiq.new
42
+ sidekiq.enable(client) if sidekiq.available?
43
+ client.start
38
44
  end
39
45
 
40
46
  def options
41
- Hash[options_list].merge(:logger => @rails_logger)
42
- end
43
-
44
- def options_list
45
- existing_option_keys.map{|key| [key, @chillout_config[key]]}
46
- end
47
-
48
- def existing_option_keys
49
- [:port, :hostname, :ssl].select{|key| @chillout_config.has_key?(key)}
47
+ {logger: @rails_logger}.merge(@chillout_config).except(:secret)
50
48
  end
51
49
 
52
50
  end
@@ -22,7 +22,7 @@ module Chillout
22
22
 
23
23
  def send_startup_message
24
24
  @server_side.send_startup_message
25
- rescue HttpClient::NotReceived => e
25
+ rescue HttpClient::NotReceived
26
26
  end
27
27
  end
28
28
  end
@@ -22,12 +22,32 @@ module Chillout
22
22
  end
23
23
  end
24
24
 
25
+ attr_reader :host, :port, :ssl
26
+
27
+ def initialize
28
+ @host = if ENV['CHILLOUT_CLIENT_HOST']
29
+ ENV['CHILLOUT_CLIENT_HOST']
30
+ else
31
+ "api.chillout.io"
32
+ end
33
+ @port = if ENV['CHILLOUT_CLIENT_PORT']
34
+ ENV['CHILLOUT_CLIENT_PORT'].to_i
35
+ else
36
+ 443
37
+ end
38
+ @ssl = if ENV['CHILLOUT_CLIENT_SSL']
39
+ ENV['CHILLOUT_CLIENT_SSL'] == 'true'
40
+ else
41
+ true
42
+ end
43
+ end
44
+
25
45
  MEDIA_TYPE = "application/vnd.chillout.v1+json"
26
46
 
27
47
  def post(path, data)
28
48
  begin
29
- http = Net::HTTP.new("api.chillout.io", 443)
30
- http.use_ssl = true
49
+ http = Net::HTTP.new(host, port)
50
+ http.use_ssl = ssl
31
51
  request_spec = Net::HTTP::Post.new(path)
32
52
  request_spec.body = MultiJson.dump(data)
33
53
  request_spec.content_type = MEDIA_TYPE
@@ -1,3 +1,3 @@
1
1
  module Chillout
2
- VERSION = "0.6.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -10,9 +10,9 @@ module Chillout
10
10
  end
11
11
 
12
12
  def get_all_containers_to_process
13
- logger.info "Waiting for at least one container."
13
+ logger.debug "Waiting for at least one container."
14
14
  all_containers = [queue.pop]
15
- logger.info "Received at least one container."
15
+ logger.debug "Received at least one container."
16
16
  loop do
17
17
  begin
18
18
  all_containers << queue.pop(true)
@@ -20,7 +20,7 @@ module Chillout
20
20
  break
21
21
  end
22
22
  end
23
- logger.info "Received containers to process: #{all_containers.count}"
23
+ logger.debug "Received containers to process: #{all_containers.count}"
24
24
  all_containers
25
25
  end
26
26
 
@@ -33,7 +33,7 @@ module Chillout
33
33
  end
34
34
 
35
35
  def send_creations(creations_container)
36
- logger.info "Trying to send creations"
36
+ logger.debug "Trying to send creations"
37
37
  dispatcher.send_creations(creations_container)
38
38
  logger.info "Metrics sent"
39
39
  rescue Dispatcher::SendCreationsFailed
@@ -43,7 +43,7 @@ module Chillout
43
43
 
44
44
  def send_startup_message
45
45
  dispatcher.send_startup_message
46
- logger.info "Sending startup message"
46
+ logger.debug "Sending startup message"
47
47
  end
48
48
 
49
49
  def run
data/lib/chillout.rb CHANGED
@@ -1,12 +1,23 @@
1
1
  require "chillout/version"
2
2
  require "chillout/config"
3
3
  require "chillout/middleware/creations_monitor"
4
+ require "chillout/integrations/sidekiq"
4
5
  require "chillout/server_side/dispatcher"
5
6
  require "chillout/server_side/server_side"
6
7
  require "chillout/server_side/http_client"
8
+ require "chillout/custom_metric"
7
9
  require "chillout/client"
8
10
 
9
11
  module Chillout
12
+ Metric = CustomMetric.new
13
+
14
+ def self.creations
15
+ Thread.current[:creations]
16
+ end
17
+
18
+ def self.creations=(val)
19
+ Thread.current[:creations] = val
20
+ end
10
21
  end
11
22
 
12
23
  require 'chillout/railtie' if defined?(Rails)
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class ClientSendsMetricsTest < AcceptanceTestCase
4
+
5
+ def test_client_sends_metrics
6
+ test_app = TestApp.new
7
+ test_endpoint = TestEndpoint.new
8
+ test_user = TestUser.new
9
+
10
+ test_endpoint.listen
11
+ test_app.boot
12
+ if ENV['STRATEGY'] != 'active_job'
13
+ assert test_endpoint.has_received_information_about_startup
14
+ end
15
+ test_user.create_entity('Myrmecophagidae')
16
+ assert test_endpoint.has_one_creation_for_entity_resource
17
+ ensure
18
+ test_app.shutdown if test_app
19
+ end
20
+
21
+ end