diff --git a/Gemfile b/Gemfile index 6914ac4..d0df896 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'http://rubygems.org' gem 'rails', '3.2.13' -gem 'mongoid', '~> 2.7.1' +gem 'mongoid', '~> 3.1.4' # Mongoid rails migration > 0.0.14 is not compatible to Mongoid 2.x gem 'mongoid_rails_migrations', '~> 0.0.14' @@ -75,13 +75,6 @@ gem 'flowdock' # GitHub OAuth gem 'omniauth-github' - -platform :ruby do - gem 'mongo' - gem 'bson' - gem 'bson_ext' -end - gem 'ri_cal' gem 'yajl-ruby', :require => "yajl" diff --git a/Gemfile.lock b/Gemfile.lock index 9c42fd2..bebfe4c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/NARKOZ/gitlab.git - revision: 53d7a8a86dfed63e56eeb16ea496bb7a82de337e + revision: 7a00d38c53335010d2fb8a233247fe2c97338903 specs: gitlab (2.2.0) httparty @@ -41,8 +41,7 @@ GEM i18n (= 0.6.1) multi_json (~> 1.0) addressable (2.3.5) - airbrake (3.1.12) - activesupport + airbrake (3.1.13) builder json arel (3.0.2) @@ -59,9 +58,6 @@ GEM multi_json (~> 1.3) nokogiri (~> 1.5.2) simple_oauth - bson (1.8.6) - bson_ext (1.8.6) - bson (~> 1.8.6) builder (3.0.4) callsite (0.0.11) campy (0.1.3) @@ -104,7 +100,7 @@ GEM debugger-linecache (1.2.0) debugger-ruby_core_source (1.2.3) decent_exposure (2.2.1) - devise (2.2.6) + devise (2.2.7) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) railties (~> 3.1) @@ -137,7 +133,7 @@ GEM hashie (1.2.0) highline (1.6.19) hike (1.2.3) - hipchat (0.10.0) + hipchat (0.11.0) httparty hoi (0.0.6) httparty (> 0.6.0) @@ -168,8 +164,8 @@ GEM kgio (2.8.0) launchy (2.3.0) addressable (~> 2.3) - libv8 (3.11.8.17) - libxml-ruby (2.6.0) + libv8 (3.16.14.3) + libxml-ruby (2.7.0) lighthouse-api (2.0) activeresource (>= 3.0.0) activesupport (>= 3.0.0) @@ -178,24 +174,24 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) - meta_request (0.2.7) + meta_request (0.2.8) callsite rack-contrib railties method_source (0.8.2) - mime-types (1.23) - mongo (1.8.6) - bson (~> 1.8.6) - mongoid (2.7.1) - activemodel (~> 3.1) - mongo (~> 1.8) + mime-types (1.24) + mongoid (3.1.4) + activemodel (~> 3.2) + moped (~> 1.4) + origin (~> 1.0) tzinfo (~> 0.3.22) mongoid_rails_migrations (0.0.14) activesupport (>= 3.0.0) bundler (>= 1.0.0) rails (>= 3.0.0) railties (>= 3.0.0) - multi_json (1.7.8) + moped (1.5.1) + multi_json (1.7.9) multi_xml (0.5.5) multipart-post (1.2.0) net-scp (1.1.2) @@ -230,19 +226,18 @@ GEM omniauth-oauth2 (1.1.1) oauth2 (~> 0.8.0) omniauth (~> 1.0) + origin (1.1.0) orm_adapter (0.4.0) oruen_redmine_client (0.0.1) activeresource (>= 2.3.0) pivotal-tracker (0.5.10) builder - builder crack happymapper (>= 0.3.2) nokogiri (>= 1.4.3) nokogiri (>= 1.5.5) nokogiri-happymapper (>= 0.5.4) rest-client (~> 1.6.0) - rest-client (~> 1.6.0) pjax_rails (0.3.4) jquery-rails polyglot (0.3.3) @@ -293,8 +288,8 @@ GEM rest-client (1.6.7) mime-types (>= 1.16) ri_cal (0.8.8) - rspec-core (2.14.4) - rspec-expectations (2.14.1) + rspec-core (2.14.5) + rspec-expectations (2.14.2) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.14.3) rspec-rails (2.14.0) @@ -316,7 +311,7 @@ GEM json rest-client safe_yaml (0.9.5) - selenium-webdriver (2.34.0) + selenium-webdriver (2.35.0) childprocess (>= 0.2.5) multi_json (~> 1.0) rubyzip @@ -343,8 +338,8 @@ GEM taskmapper-unfuddle (0.7.0) addressable (~> 2.2) taskmapper (~> 0.8) - therubyracer (0.11.4) - libv8 (~> 3.11.8.12) + therubyracer (0.12.0) + libv8 (~> 3.16.14.0) ref thin (1.5.1) daemons (>= 1.0.9) @@ -353,10 +348,10 @@ GEM thor (0.18.1) tilt (1.4.1) timecop (0.6.1) - treetop (1.4.14) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) - turbo-sprockets-rails3 (0.3.6) + turbo-sprockets-rails3 (0.3.9) railties (> 3.2.8, < 4.0.0) sprockets (>= 2.0.0) tzinfo (0.3.37) @@ -390,8 +385,6 @@ DEPENDENCIES better_errors binding_of_caller bitbucket_rest_api - bson - bson_ext campy (= 0.1.3) capistrano capybara (~> 2.0.1) @@ -418,8 +411,7 @@ DEPENDENCIES launchy lighthouse-api meta_request - mongo - mongoid (~> 2.7.1) + mongoid (~> 3.1.4) mongoid_rails_migrations (~> 0.0.14) octokit omniauth-github diff --git a/app/controllers/api/v1/notices_controller.rb b/app/controllers/api/v1/notices_controller.rb index d86865d..21489be 100644 --- a/app/controllers/api/v1/notices_controller.rb +++ b/app/controllers/api/v1/notices_controller.rb @@ -11,7 +11,9 @@ class Api::V1::NoticesController < ApplicationController query = {:created_at => {"$lte" => end_date, "$gte" => start_date}} end - results = benchmark("[api/v1/notices_controller] query time") { Mongoid.master["notices"].find(query, :fields => fields).to_a } + results = benchmark("[api/v1/notices_controller] query time") do + Notice.where(query).with(:consistency => :strong).only(fields).to_a + end respond_to do |format| format.html { render :json => Yajl.dump(results) } # render JSON if no extension specified on path diff --git a/app/controllers/api/v1/problems_controller.rb b/app/controllers/api/v1/problems_controller.rb index ffb0a1f..48f35d7 100644 --- a/app/controllers/api/v1/problems_controller.rb +++ b/app/controllers/api/v1/problems_controller.rb @@ -1,23 +1,25 @@ class Api::V1::ProblemsController < ApplicationController respond_to :json, :xml - + def index query = {} fields = %w{app_id app_name environment message where first_notice_at last_notice_at resolved resolved_at notices_count} - + if params.key?(:start_date) && params.key?(:end_date) start_date = Time.parse(params[:start_date]).utc end_date = Time.parse(params[:end_date]).utc query = {:first_notice_at=>{"$lte"=>end_date}, "$or"=>[{:resolved_at=>nil}, {:resolved_at=>{"$gte"=>start_date}}]} end - - results = benchmark("[api/v1/problems_controller] query time") { Mongoid.master["problems"].find(query, :fields => fields).to_a } - + + results = benchmark("[api/v1/problems_controller] query time") do + Problem.where(query).with(:consistency => :strong).only(fields).to_a + end + respond_to do |format| format.html { render :json => Yajl.dump(results) } # render JSON if no extension specified on path format.json { render :json => Yajl.dump(results) } format.xml { render :xml => results } end end - + end diff --git a/app/interactors/problem_destroy.rb b/app/interactors/problem_destroy.rb index 6516dc5..2f89415 100644 --- a/app/interactors/problem_destroy.rb +++ b/app/interactors/problem_destroy.rb @@ -37,12 +37,12 @@ class ProblemDestroy end def delete_errs - Notice.collection.remove(:err_id => { '$in' => errs_id }) - Err.collection.remove(:_id => { '$in' => errs_id }) + Notice.delete_all(:err_id => { '$in' => errs_id }) + Err.delete_all(:_id => { '$in' => errs_id }) end def delete_comments - Comment.collection.remove(:_id => { '$in' => comments_id }) + Comment.delete_all(:_id => { '$in' => comments_id }) end end diff --git a/app/interactors/resolved_problem_clearer.rb b/app/interactors/resolved_problem_clearer.rb index d4cd785..f6945ce 100644 --- a/app/interactors/resolved_problem_clearer.rb +++ b/app/interactors/resolved_problem_clearer.rb @@ -27,6 +27,6 @@ class ResolvedProblemClearer end def repair_database - Mongoid.config.master.command(:repairDatabase => 1) + Mongoid.default_session.command :repairDatabase => 1 end end diff --git a/app/models/app.rb b/app/models/app.rb index 02ff09b..857a43e 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -15,9 +15,6 @@ class App field :notify_on_deploys, :type => Boolean, :default => false field :email_at_notices, :type => Array, :default => Errbit::Config.email_at_notices - # Some legacy apps may have string as key instead of BSON::ObjectID - identity :type => String - embeds_many :watchers embeds_many :deploys embeds_one :issue_tracker @@ -61,7 +58,7 @@ class App end def self.find_by_api_key!(key) - where(:api_key => key).first || raise(Mongoid::Errors::DocumentNotFound.new(self,key)) + find_by(:api_key => key) end def last_deploy_at diff --git a/app/models/backtrace.rb b/app/models/backtrace.rb index 089bd21..b417aa1 100644 --- a/app/models/backtrace.rb +++ b/app/models/backtrace.rb @@ -3,7 +3,7 @@ class Backtrace include Mongoid::Timestamps field :fingerprint - index :fingerprint + index :fingerprint => 1 has_many :notices has_one :notice @@ -19,7 +19,7 @@ class Backtrace end def similar - Backtrace.first(:conditions => { :fingerprint => fingerprint } ) + Backtrace.find_by(:fingerprint => fingerprint) rescue nil end def raw=(raw) diff --git a/app/models/comment.rb b/app/models/comment.rb index a202fd5..b32a7e2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -6,7 +6,7 @@ class Comment before_destroy :decrease_counter_cache field :body, :type => String - index :user_id + index(:user_id => 1) belongs_to :err, :class_name => "Problem" belongs_to :user diff --git a/app/models/deploy.rb b/app/models/deploy.rb index 3828ecc..88565bc 100644 --- a/app/models/deploy.rb +++ b/app/models/deploy.rb @@ -8,7 +8,7 @@ class Deploy field :revision field :message - index :created_at, Mongo::DESCENDING + index(:created_at => -1) embedded_in :app, :inverse_of => :deploys diff --git a/app/models/err.rb b/app/models/err.rb index 712fa98..1df99cd 100644 --- a/app/models/err.rb +++ b/app/models/err.rb @@ -8,8 +8,8 @@ class Err field :fingerprint - index :problem_id - index :fingerprint + index problem_id: 1 + index fingerprint: 1 belongs_to :problem has_many :notices, :inverse_of => :err, :dependent => :destroy diff --git a/app/models/notice.rb b/app/models/notice.rb index cd76d01..2bd6ead 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -16,14 +16,9 @@ class Notice belongs_to :err belongs_to :backtrace, :index => true - index :created_at - index( - [ - [ :err_id, Mongo::ASCENDING ], - [ :created_at, Mongo::ASCENDING ], - [ :_id, Mongo::ASCENDING ] - ] - ) + + index(:created_at => 1) + index(:err_id => 1, :created_at => 1, :_id => 1) after_create :cache_attributes_on_problem, :unresolve_problem before_save :sanitize diff --git a/app/models/problem.rb b/app/models/problem.rb index d4755fc..e8a324b 100644 --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -26,14 +26,14 @@ class Problem field :hosts, :type => Hash, :default => {} field :comments_count, :type => Integer, :default => 0 - index :app_id - index :app_name - index :message - index :last_notice_at - index :first_notice_at - index :last_deploy_at - index :resolved_at - index :notices_count + index :app_id => 1 + index :app_name => 1 + index :message => 1 + index :last_notice_at => 1 + index :first_notice_at => 1 + index :last_deploy_at => 1 + index :resolved_at => 1 + index :notices_count => 1 belongs_to :app has_many :errs, :inverse_of => :problem, :dependent => :destroy @@ -51,9 +51,9 @@ class Problem validates_presence_of :last_notice_at, :first_notice_at - def self.all_else_unresolved all - if all - find(:all) + def self.all_else_unresolved(fetch_all) + if fetch_all + all else where(:resolved => false) end @@ -132,8 +132,8 @@ class Problem self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last) last_deploy.created_at.utc end - collection.update({'_id' => self.id}, - {'$set' => {'app_name' => self.app_name, + collection.find('_id' => self.id) + .update({'$set' => {'app_name' => self.app_name, 'last_deploy_at' => self.last_deploy_at.try(:utc)}}) end end @@ -153,7 +153,7 @@ class Problem end def self.search(value) - where.or(:error_class => /#{value}/i).or(:where => /#{value}/i).or(:message => /#{value}/i).or(:app_name => /#{value}/i).or(:environment => /#{value}/i) + any_of({:error_class => /#{value}/i}, {:message => /#{value}/i}, {:app_name => /#{value}/i}, {:environment => /#{value}/i}) end private diff --git a/config/mongoid.example.yml b/config/mongoid.example.yml index 79e0219..6aeb890 100644 --- a/config/mongoid.example.yml +++ b/config/mongoid.example.yml @@ -7,29 +7,34 @@ # `cap deploy:setup` is ran the first time. Be sure # to place production specific settings there -defaults: &defaults - host: localhost - identity_map_enabled: true - - # slaves: - # - host: slave1.local - # port: 27018 - # - host: slave2.local - # port: 27019 - development: - <<: *defaults - database: errbit_development + sessions: + default: + database: errbit_development + hosts: + - localhost:27017 + options: + identity_map_enabled: true + use_utc: true test: - <<: *defaults - database: errbit_test + sessions: + default: + hosts: + - localhost:27017 + database: errbit_test + options: + identity_map_enabled: true + use_utc: true # set these environment variables on your prod server production: - <<: *defaults - host: <%= ENV['MONGOID_HOST'] %> - port: <%= ENV['MONGOID_PORT'] %> - username: <%= ENV['MONGOID_USERNAME'] %> - password: <%= ENV['MONGOID_PASSWORD'] %> - database: <%= ENV['MONGOID_DATABASE'] %> + sessions: + default: + database: <%= ENV['MONGOID_DATABASE'] %> + hosts: + - <%=ENV["MONGOID_HOST"]%><%=ENV["MONGOID_PORT"]%> + username: <%= ENV['MONGOID_USERNAME'] %> + password: <%= ENV['MONGOID_PASSWORD'] %> + options: + identity_map_enabled: true diff --git a/db/seeds.rb b/db/seeds.rb index 30bd3af..e109a69 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -12,12 +12,11 @@ puts "-- email: #{admin_email}" puts "-- password: #{admin_pass}" puts "" puts "Be sure to change these credentials ASAP!" -user = User.where(:email => admin_email).first || User.new({ - :name => 'Errbit Admin', - :email => admin_email, - :password => admin_pass, - :password_confirmation => admin_pass -}) +user = User.find_or_initialize_by(:email => admin_email) do |u| + u.name = 'Errbit Admin' + u.password = admin_pass + u.password_confirmation = admin_pass +end user.username = admin_username if Errbit::Config.user_has_username user.admin = true diff --git a/spec/controllers/api/v1/notices_controller_spec.rb b/spec/controllers/api/v1/notices_controller_spec.rb index 0bd91c7..0bf38d0 100644 --- a/spec/controllers/api/v1/notices_controller_spec.rb +++ b/spec/controllers/api/v1/notices_controller_spec.rb @@ -9,10 +9,10 @@ describe Api::V1::NoticesController do describe "GET /api/v1/notices" do before do - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 01)) - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 01)) - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 21)) - Fabricate(:notice, :created_at => DateTime.new(2012, 8, 30)) + Fabricate(:notice, :created_at => Time.new(2012, 8, 01)) + Fabricate(:notice, :created_at => Time.new(2012, 8, 01)) + Fabricate(:notice, :created_at => Time.new(2012, 8, 21)) + Fabricate(:notice, :created_at => Time.new(2012, 8, 30)) end it "should return JSON if JSON is requested" do diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index cabda4b..165067a 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -11,7 +11,7 @@ describe AppsController do sign_in Fabricate(:admin) 3.times { Fabricate(:app) } get :index - controller.apps.should == App.all.sort.entries + controller.apps.entries.should == App.all.sort.entries end end diff --git a/spec/controllers/problems_controller_spec.rb b/spec/controllers/problems_controller_spec.rb index b4e40fb..8663777 100644 --- a/spec/controllers/problems_controller_spec.rb +++ b/spec/controllers/problems_controller_spec.rb @@ -195,13 +195,13 @@ describe ProblemsController do sign_in Fabricate(:admin) @problem = Fabricate(:err) - App.stub(:find).with(@problem.app.id).and_return(@problem.app) + App.stub(:find).with(@problem.app.id.to_s).and_return(@problem.app) @problem.app.problems.stub(:find).and_return(@problem.problem) @problem.problem.stub(:resolve!) end it 'finds the app and the problem' do - App.should_receive(:find).with(@problem.app.id).and_return(@problem.app) + App.should_receive(:find).with(@problem.app.id.to_s).and_return(@problem.app) @problem.app.problems.should_receive(:find).and_return(@problem.problem) put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id controller.app.should == @problem.app diff --git a/spec/interactors/problem_destroy_spec.rb b/spec/interactors/problem_destroy_spec.rb index b43ace1..3e7459e 100644 --- a/spec/interactors/problem_destroy_spec.rb +++ b/spec/interactors/problem_destroy_spec.rb @@ -32,17 +32,17 @@ describe ProblemDestroy do end it 'delete all errs associate' do - Err.collection.should_receive(:remove).with(:_id => { '$in' => [err_1.id, err_2.id] }) + Err.should_receive(:delete_all).with(:_id => { '$in' => [err_1.id, err_2.id] }) problem_destroy.execute end it 'delete all comments associate' do - Comment.collection.should_receive(:remove).with(:_id => { '$in' => [comment_1.id, comment_2.id] }) + Comment.should_receive(:delete_all).with(:_id => { '$in' => [comment_1.id, comment_2.id] }) problem_destroy.execute end it 'delete all notice of associate to this errs' do - Notice.collection.should_receive(:remove).with({:err_id => { '$in' => [err_1.id, err_2.id] }}) + Notice.should_receive(:delete_all).with({:err_id => { '$in' => [err_1.id, err_2.id] }}) problem_destroy.execute end end diff --git a/spec/interactors/problem_merge_spec.rb b/spec/interactors/problem_merge_spec.rb index 38c2bc6..d8183e0 100644 --- a/spec/interactors/problem_merge_spec.rb +++ b/spec/interactors/problem_merge_spec.rb @@ -38,7 +38,7 @@ describe ProblemMerge do it 'move all err in one problem' do problem_merge.merge - problem.reload.errs.should eq (first_errs | merged_errs) + expect(problem.reload.errs.map(&:id).sort).to eq (first_errs | merged_errs).map(&:id).sort end it 'update problem cache' do diff --git a/spec/interactors/problem_updater_cache_spec.rb b/spec/interactors/problem_updater_cache_spec.rb index 2afbf3f..74796ba 100644 --- a/spec/interactors/problem_updater_cache_spec.rb +++ b/spec/interactors/problem_updater_cache_spec.rb @@ -31,11 +31,11 @@ describe ProblemUpdaterCache do end it 'update first_notice_at' do - expect(problem.first_notice_at).to eq notice.created_at + expect(problem.first_notice_at).to eq notice.reload.created_at end it 'update last_notice_at' do - expect(problem.last_notice_at).to eq notice.created_at + expect(problem.last_notice_at).to eq notice.reload.created_at end it 'update stats messages' do diff --git a/spec/interactors/resolved_problem_clearer_spec.rb b/spec/interactors/resolved_problem_clearer_spec.rb index 259c998..fdc1670 100644 --- a/spec/interactors/resolved_problem_clearer_spec.rb +++ b/spec/interactors/resolved_problem_clearer_spec.rb @@ -21,16 +21,16 @@ describe ResolvedProblemClearer do } end it 'not repair database' do - Mongoid.config.master.should_receive(:command).and_call_original - Mongoid.config.master.should_not_receive(:command).with({:repairDatabase => 1}) + Mongoid.default_session.stub(:command).and_call_original + Mongoid.default_session.should_not_receive(:command).with({:repairDatabase => 1}) resolved_problem_clearer.execute end end context "with problem resolve" do before do - Mongoid.config.master.stub(:command).and_call_original - Mongoid.config.master.stub(:command).with({:repairDatabase => 1}) + Mongoid.default_session.stub(:command).and_call_original + Mongoid.default_session.stub(:command).with({:repairDatabase => 1}) problems.first.resolve! problems.second.resolve! end @@ -46,8 +46,8 @@ describe ResolvedProblemClearer do end it 'repair database' do - Mongoid.config.master.should_receive(:command).and_call_original - Mongoid.config.master.should_receive(:command).with({:repairDatabase => 1}) + Mongoid.default_session.stub(:command).and_call_original + Mongoid.default_session.should_receive(:command).with({:repairDatabase => 1}) resolved_problem_clearer.execute end end -- libgit2 0.21.2