Merge branch 'remove_splunk'

This commit is contained in:
Maxwell Salzberg 2011-12-21 14:24:19 -08:00
commit c258755af5
20 changed files with 8 additions and 384 deletions

View file

@ -21,8 +21,8 @@ class CommentsController < ApplicationController
@comment = current_user.build_comment(:text => text, :post => target)
if @comment.save
Rails.logger.info(:event => :create, :type => :comment, :user => current_user.diaspora_handle,
:status => :success, :comment => @comment.id, :chars => params[:text].length)
Rails.logger.info("event => :create, :type => :comment, :user => #{current_user.diaspora_handle},
:status => :success, :comment => #{@comment.id}, :chars => #{params[:text].length}")
Postzord::Dispatcher.build(current_user, @comment).post
respond_to do |format|

View file

@ -40,7 +40,7 @@ class PostsController < ApplicationController
else
user_id = (user_signed_in? ? current_user : nil)
Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => user_id, :post_id => params[:id])
Rails.logger.info(":event => :link_to_nonexistent_post, :ref => #{request.env['HTTP_REFERER']}, :user_id => #{user_id}, :post_id => #{params[:id]}")
flash[:error] = I18n.t('posts.show.not_found')
redirect_to :back
end

View file

@ -57,7 +57,7 @@ module SocketsHelper
raise "#{object.inspect} with class #{object.class} is not actionhashable." unless object.is_a? Retraction
end
rescue Exception => e
Rails.logger.error(:event => :socket_render, :status => :fail, :user => user.diaspora_handle, :object=> object.id, :object_class => object.class, :error_message => e.message)
Rails.logger.error(":event => :socket_render, :status => :fail, :user => #{user.diaspora_handle}, :object=> #{object.id}, :object_class => #{object.class}, :error_message => #{e.message}")
raise e
end
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}

View file

@ -82,7 +82,7 @@ class SignedRetraction
self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user
self.target.destroy
end
Rails.logger.info(:event => :retraction, :status => :complete, :target_type => self.target_type, :guid => self.target_guid)
Rails.logger.info("event=retraction status =complete target_type=#{self.target_type} guid =#{self.target_guid}")
end
def receive(recipient, sender)

View file

@ -4,12 +4,6 @@ cron "user stats" do
command "cd /usr/local/app/diaspora && exec /usr/local/bin/ruby /usr/local/bin/bundle exec rake --trace statistics:users_splunk &> /usr/local/app/diaspora/log/stats.log"
end
cron "content stats" do
minute 42
hour 15
command "cd /usr/local/app/diaspora && exec /usr/local/bin/ruby /usr/local/bin/bundle exec rake --trace statistics:content_splunk &> /usr/local/app/diaspora/log/stats.log"
end
cron "backup mysql" do
minute 0
command "cd /usr/local/app/diaspora && exec /usr/local/bin/ruby /usr/local/bin/bundle exec rake --trace backup:mysql"

View file

@ -2,7 +2,6 @@ include_recipe "diaspora::image_magick"
include_recipe "diaspora::mysql"
include_recipe "diaspora::iptables"
include_recipe "diaspora::daemontools"
include_recipe "diaspora::splunk"
include_recipe "diaspora::backup"
include_recipe "diaspora::nginx"
include_recipe "diaspora::redis"

View file

@ -1,44 +0,0 @@
unless system "splunk status"
execute "Make Temp Dir" do
command "mkdir -p /tmp/install"
end
execute "Download splunk" do
command "cd /tmp/install && wget 'http://www.splunk.com/index.php/download_track?file=4.1.5/linux/splunk-4.1.5-85165-Linux-x86_64.tgz&ac=&wget=true&name=wget&typed=releases' -O splunk-4.1.5-85165-Linux-x86_64.tgz"
end
execute "Untar splunk" do
command "tar -xvf /tmp/install/splunk-4.1.5-85165-Linux-x86_64.tgz -C /opt/"
end
link "/usr/local/bin/splunk" do
to "/opt/splunk/bin/splunk"
end
end
execute "Start splunk" do
command "splunk start --accept-license || true"
end
execute "Put splunk into forwarding mode" do
command "splunk enable app SplunkLightForwarder -auth admin:changeme"
end
execute "Add forwarding server" do
command "splunk add forward-server splunk.joindiaspora.com:9997 -auth admin:changeme"
not_if "splunk list forward-server | grep splunk.joindiaspora.com:9997"
end
execute "Add monitor for diaspora" do
command "splunk add monitor /usr/local/app/diaspora/log"
not_if "splunk list monitor | grep diaspora"
end
execute "Add monitor for nginx" do
command "mkdir -p /usr/local/nginx/logs && splunk add monitor /usr/local/nginx/logs"
not_if "splunk list monitor | grep nginx"
end
execute 'Splunk Restart' do
command "splunk restart"
end

View file

@ -85,9 +85,6 @@ defaults: &defaults
# Enable extensive logging to log/{development,test,production}.log
debug: false
# If you want normal Rails logs, set this to false in the appropriate environment.
# It is false by default in development and test.
enable_splunk_logging: true
# Enable extensive logging to websocket server.
socket_debug : false
@ -215,7 +212,6 @@ defaults: &defaults
development:
<<: *defaults
enable_splunk_logging: false
production:
<<: *defaults
@ -228,15 +224,12 @@ test:
<<: *defaults
pod_url: "http://localhost:9887"
socket_port: 8081
enable_splunk_logging: false
open_invitations: true
integration_1:
<<: *defaults
pod_url: "http://localhost:45789"
enable_splunk_logging: false
integration_2:
<<: *defaults
pod_url: "http://localhost:34658"
enable_splunk_logging: false

View file

@ -1,5 +0,0 @@
if AppConfig[:enable_splunk_logging]
require File.expand_path('../../../lib/log_overrider', __FILE__)
end
Rails.logger.class.send(:include, SplunkLogging)

View file

@ -314,8 +314,8 @@ ActiveRecord::Schema.define(:version => 20111217042006) do
t.integer "likes_count", :default => 0
t.integer "comments_count", :default => 0
t.integer "o_embed_cache_id"
t.integer "reshares_count", :default => 0
t.integer "photos_count", :default => 0
t.integer "reshares_count", :default => 0
end
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true

View file

@ -1,88 +0,0 @@
class ActionView::LogSubscriber
# In order to be more friendly to Splunk, which we use for log analysis,
# we override a few logging methods. There are not overriden if enable_splunk_logging is set to false in config/application.yml
def render_template(event)
count = event.payload[:count] || 1
hash = {:event => :render,
:template => from_rails_root(event.payload[:identifier]),
:total_ms => event.duration,
:count => count,
:ms => event.duration / count}
hash.merge(:layout => event.payload[:layout]) if event.payload[:layout]
Rails.logger.info(hash)
end
alias :render_partial :render_template
alias :render_collection :render_template
end
module ActionDispatch
class ShowExceptions
private
# This override logs in a format Splunk can more easily understand.
# @see ActionView::LogSubscriber#render_template
def log_error(exception)
return unless logger
ActiveSupport::Deprecation.silence do
message = "event=error error_class=#{exception.class} error_message='#{exception.message}' "
message << "gc_ms=#{GC.time/1000} gc_collections=#{GC.collections} gc_bytes=#{GC.growth} " if GC.respond_to?(:enable_stats)
message << "orig_error_message='#{exception.original_exception.message}'" if exception.respond_to?(:original_exception)
message << "annotated_source='#{exception.annoted_source_code.to_s}' " if exception.respond_to?(:annoted_source_code)
message << "app_backtrace='#{application_trace(exception).join(";")}'"
logger.fatal("\n\n#{message}\n\n")
end
end
end
end
class ActionController::LogSubscriber
require "#{File.dirname(__FILE__)}/active_record_instantiation_logs.rb"
include Oink::InstanceTypeCounter
def start_processing(event)
#noop
end
# This override logs in a format Splunk can more easily understand.
# @see ActionView::LogSubscriber#render_template
def process_action(event)
payload = event.payload
additions = ActionController::Base.log_process_action(payload)
params = payload[:params].except(*INTERNAL_PARAMS)
log_hash = {:event => :request_completed,
:status => payload[:status],
:controller => payload[:controller],
:action => payload[:action],
:format => payload[:formats].first.to_s.upcase,
:ms => ("%.0f" % event.duration).to_i,
:params => params.inspect}
log_hash.merge!({
:gc_ms => GC.time/1000,
:gc_collections => GC.collections,
:gc_bytes=> GC.growth}) if GC.respond_to?(:enable_stats)
log_hash.merge!({:view_ms => payload[:view_runtime],
:db_ms => payload[:db_runtime]}) unless additions.blank?
log_hash.merge!(report_hash!)
Rails.logger.info(log_hash)
end
end
module Rails
module Rack
class Logger
# This override logs in a format Splunk can more easily understand.
# @see ActionView::LogSubscriber#render_template
def before_dispatch(env)
request = ActionDispatch::Request.new(env)
path = request.fullpath
Rails.logger.info("event=request_started verb=#{env["REQUEST_METHOD"]} path=#{path} ip=#{request.ip} ")
end
end
end
end

View file

@ -30,7 +30,7 @@ HEADER
begin
super
rescue OpenSSL::PKey::RSAError => e
Rails.logger.info(:event => :invalid_rsa_key, :identifier => person.diaspora_handle)
Rails.logger.info("event => :invalid_rsa_key, :identifier => #{person.diaspora_handle}")
false
end
end

View file

@ -1,32 +0,0 @@
module SplunkLogging
def self.included(base)
base.class_eval do
alias_method_chain :add, :splunk
end
end
def add_with_splunk(arg1, log_hash = nil, arg3 = nil, &block)
if log_hash
string = format_hash(log_hash).dup
string << " pid=#{Process.pid} "
string << " time=#{Time.now.to_i} "
else
string = log_hash
end
add_without_splunk(arg1, string, arg3, &block)
end
def format_hash(hash)
if hash.respond_to?(:keys)
string = ''
hash.each_pair do |key, value|
if [Symbol, Fixnum, Float, Class].include?(value.class)
string << "#{key}=#{value} "
else
string << "#{key}=\"#{value.to_s.gsub('"', '\"')}\" "
end
end
string
else
hash
end
end
end

View file

@ -41,7 +41,7 @@ class WebfingerProfile
pubkey = text_of_attribute( doc.at('Link[rel=diaspora-public-key]'), 'href')
@public_key = Base64.decode64 pubkey
rescue Exception => e
Rails.logger.info(:event => :invalid_profile, :identifier => @account)
Rails.logger.info("event => :invalid_profile, :identifier => #{@account}")
end
end
end

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file.
require 'spec_helper'
require File.join(Rails.root, "spec", "shared_behaviors", "log_override")
describe AspectsController do
before do
@ -17,35 +16,6 @@ describe AspectsController do
request.env["HTTP_REFERER"] = 'http://' + request.host
end
describe "custom logging on success" do
before do
@action = :index
end
it_should_behave_like "it overrides the logs on success"
end
describe "custom logging on error" do
class FakeError < RuntimeError;
attr_accessor :original_exception;
end
before do
@action = :index
@desired_error_message = "I love errors"
@error = FakeError.new(@desired_error_message)
@orig_error_message = "I loooooove nested errors!"
@error.original_exception = NoMethodError.new(@orig_error_message)
@controller.stub(:index).and_raise(@error)
end
it_should_behave_like "it overrides the logs on error"
end
describe "custom logging on redirect" do
before do
@action = :show
@action_params = {'id' => @alices_aspect_1.id.to_s}
end
it_should_behave_like "it overrides the logs on redirect"
end
describe "#new" do
it "renders a remote form if remote is true" do

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file.
require 'spec_helper'
require File.join(Rails.root, "spec", "shared_behaviors", "log_override")
describe HomeController do
describe '#show' do
@ -17,24 +16,5 @@ describe HomeController do
get :show, :home => true
response.should redirect_to(multi_path)
end
describe "custom logging on success" do
before do
@action = :show
@action_params = {"lasers" => "green"}
end
it_should_behave_like "it overrides the logs on success"
end
describe "custom logging on redirect" do
before do
sign_in :user, bob
@action = :show
@action_params = {"lasers" => "green"}
end
it_should_behave_like "it overrides the logs on redirect"
end
end
end

View file

@ -37,7 +37,6 @@ describe Diaspora::OstatusBuilder do
messages.each{ |message| atom2.should include message }
end
include Oink::InstanceTypeCounter
it 'does not query the db for the author of every post' do
alice.person #Preload user.person
ActiveRecord::Base.reset_instance_type_count

View file

@ -17,19 +17,6 @@ describe ResqueJobLogging do
Rails.unstub!(:logger)
end
# http://bugs.joindiaspora.com/issues/741
it "should enumerate arguments" do
Rails.logger.should_receive(:info).with(/arg1="foo" arg2="bar" arg3="baz"/)
## pass a nil block, so we can test the .info() output
ResqueJobLoggingDummy.around_perform_log_job("foo", "bar", "baz") {}
end
it 'logs stack traces on failure' do
Rails.logger.should_receive(:info).with(/app_backtrace=/)
error = RuntimeError.new("GRAAAAAAAAAGH")
proc {
ResqueJobLoggingDummy.around_perform_log_job("stuff"){raise error}
}.should raise_error(Regexp.new(error.message))
end
it 'notifies hoptoad if the hoptoad api key is set' do
Rails.logger.should_receive(:info)

View file

@ -1,30 +0,0 @@
require 'spec_helper'
describe SplunkLogging do
def add
end
include SplunkLogging
describe '#format_hash' do
it 'does not quote keys' do
format_hash({:key => 'value'}).should =~ /key=/
end
it 'quotes strings' do
format_hash({:key => 'value'}).should =~ /="value"/
end
it 'does not quote symbols' do
format_hash({:key => :value}).should =~ /=value/
end
it 'does not quote numbers' do
format_hash({:key => 500 }).should =~ /=500/
end
it 'does not quote floats' do
format_hash({:key => 2.324}).should =~ /=2.324/
end
it 'does not quote classes' do
format_hash({:key => Class}).should =~ /=Class/
end
it 'escapes double quotes in strings' do
format_hash({:key => 'whaaa " quotes'}).should =~ /="whaaa \\\" quotes"/
end
end
end

View file

@ -1,99 +0,0 @@
require File.expand_path('../../../lib/log_overrider', __FILE__)
class FakeLogger
attr_accessor :infos
attr_accessor :lines
attr_accessor :fatals
def initialize
self.infos = []
self.fatals = []
self.lines = []
end
def add(arg1, line, targ_arr, &block)
self.lines << line
targ_arr << line
end
def info line
self.add(nil, line, self.infos)
end
def fatal line
self.add(nil, line, self.fatals)
end
include SplunkLogging
end
shared_examples_for 'it overrides the logs on success' do
before do
Rails.stub(:logger).and_return(FakeLogger.new)
end
context 'rendering' do
it 'logs renders' do
get @action, @action_params
@lines = Rails.logger.infos.select { |l| l.include?("event=render") }
@lines.length.should > 0
end
end
context 'completion' do
context 'ok' do
before do
get @action, @action_params
@line = Rails.logger.infos.last
end
it 'logs the completion of a request' do
@line.include?("event=request_completed").should be_true
end
it 'logs an ok' do
@line.include?("status=200").should be_true
end
it 'logs the controller' do
@line.include?("controller=\"#{controller.class.name}\"").should be_true
end
it 'logs the action' do
@line.include?("action=\"#{@action}\"").should be_true
end
it 'logs params' do
if @action_params
@line.include?("params=\"#{@action_params.inspect.gsub(" ", "").gsub("\"", "\\\"")}\"").should be_true
end
end
it 'logs the view rendering time addition' do
@line.include?("view_ms=").should be_true
end
end
end
end
shared_examples_for 'it overrides the logs on error' do
before do
Rails.stub(:logger).and_return(FakeLogger.new)
begin
get @action, @action_params
rescue Exception => e
ActionDispatch::ShowExceptions.new(nil).send(:log_error,e)
end
@line = Rails.logger.lines.last
end
it 'logs the backtrace' do
@line.should =~ /app_backtrace=/
end
it 'logs the error message' do
@line.should =~ /error_message='#{@desired_error_message}'/
end
it 'logs the original error message, if it exists' do
@line.should =~ /orig_error_message='#{@orig_error_message}'/ if @orig_error_message
end
end
shared_examples_for 'it overrides the logs on redirect' do
before do
Rails.stub(:logger).and_return(FakeLogger.new)
get @action, @action_params
@line = Rails.logger.infos.last
end
it 'logs a redirect' do
@line.include?("status=302").should be_true
end
end