Skip to content

Commit

Permalink
Bugfix: Increase logging after connect error (including internal errors)
Browse files Browse the repository at this point in the history
Dragnet: Add number of dependencies for unused tables
  • Loading branch information
rammpeter committed Sep 15, 2023
1 parent de6d9f2 commit ec30bdc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
8 changes: 2 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ def global_exception_handler(exception)
@exception = exception # Sichtbarkeit im template
@request = request

Rails.logger.error('ApplicationController.global_exception_handler') { @exception.class.name }
if @request.parameters['controller']
Rails.logger.error('ApplicationController.global_exception_handler') { "#{@request.parameters['controller'].camelize}Controller#{"##{@request.parameters['action']}" if @request.parameters['action']}" }
end

Rails.logger.error('ApplicationController.global_exception_handler') { @exception.message }
location = @request.parameters['controller'] ? "#{@request.parameters['controller'].camelize}Controller#{"##{@request.parameters['action']}" if @request.parameters['action']} " : ''
Rails.logger.error('ApplicationController.global_exception_handler') { "#{location}#{@exception.class.name} : #{@exception.message}" }
log_exception_backtrace(@exception, Rails.env.test? ? nil : 40)

if performed? # Render already called in action?, Suppress DoubleRenderError
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/env_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ def set_database(called_from_set_database_by_params = false)
begin
PanoramaConnection.check_for_open_connection
rescue Exception => e
Rails.logger.debug('EnvController.set_database') { "Error connecting to database: #{e.class.name}: #{e.message}" }
log_exception_backtrace(e, 20, log_mode: :debug) # Don't log each wrong connection credentials as error

respond_to do |format|
format.js {render :js => "show_status_bar_message('#{
my_html_escape("#{
Expand Down
22 changes: 15 additions & 7 deletions app/helpers/dragnet/unused_tables_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,25 @@ def unused_tables
AND s.SQL_FullText NOT LIKE '%dbms_stats cursor_sharing_exact%' /* DBMS-Stats-Statement */
AND s.Command_Type = 3 /* SELECT */
)
)
SELECT /* DB-Tools Ramm not used tables */ o.*, sz.MBytes, ob.Created, ob.Last_DDL_Time, tm.Timestamp Last_DML_Timestamp, tm.Inserts, tm.Updates, tm.Deletes
),
Segment_Size AS (SELECT /*+ NO_MERGE MATERIALIZE */ Segment_Name, Owner, SUM(bytes)/(1024*1024) MBytes
FROM DBA_SEGMENTS
WHERE Owner NOT IN (#{system_schema_subselect})
GROUP BY Segment_Name, Owner
),
Dependencies AS (SELECT /*+ NO_MERGE MATERIALIZE */ Referenced_Owner, Referenced_Name, COUNT(*) Dependencies
FROM DBA_Dependencies
WHERE Referenced_Type = 'TABLE'
GROUP BY Referenced_Owner, Referenced_Name
)
SELECT /* DB-Tools Ramm not used tables */ o.*, sz.MBytes, ob.Created, ob.Last_DDL_Time, tm.Timestamp Last_DML_Timestamp, tm.Inserts, tm.Updates, tm.Deletes,
d.Dependencies
FROM Tabs_Inds o
LEFT OUTER JOIN used ON used.Object_Owner = o.Owner AND used.Object_Name = o.Object_Name
LEFT OUTER JOIN (SELECT /*+ NO_MERGE */ Segment_Name, Owner, SUM(bytes)/(1024*1024) MBytes
FROM DBA_SEGMENTS
WHERE Owner NOT IN (#{system_schema_subselect})
GROUP BY Segment_Name, Owner
) sz ON sz.SEGMENT_NAME = o.Object_Name AND sz.Owner = o.Owner
LEFT OUTER JOIN Segment_Size sz ON sz.SEGMENT_NAME = o.Object_Name AND sz.Owner = o.Owner
LEFT OUTER JOIN DBA_Objects ob ON ob.Owner = o.Owner AND ob.Object_Name = o.Object_Name AND ob.SubObject_Name IS NULL
LEFT OUTER JOIN Tab_Modifications tm ON tm.Table_Owner = o.Owner AND tm.Table_Name = o.Object_Name AND tm.Partition_Name IS NULL AND tm.SubPartition_Name IS NULL
LEFT OUTER JOIN Dependencies d ON d.Referenced_Owner = o.Owner AND d.Referenced_Name = o.Object_Name
WHERE used.Object_Owner IS NULL
AND used.Object_Name IS NULL
ORDER BY sz.MBytes DESC NULLS LAST",
Expand Down
13 changes: 9 additions & 4 deletions app/helpers/exception_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

module ExceptionHelper

def log_exception_backtrace(exception, line_number_limit=nil)
ExceptionHelper.log_memory_state(log_mode: :error)
# Log the stacktrace of an exception
# @param [Exception] exception: Exception to log
# @param [Integer] line_number_limit : Amount of lines to log, nil = all
# @param [Symbol] log_mode: mode for log outout, :debug, :info or :error
# @return [Integer] the number of characters logged
def log_exception_backtrace(exception, line_number_limit=nil, log_mode: :error)
ExceptionHelper.log_memory_state(log_mode: log_mode)
curr_line_no=0
output = ''
exception.backtrace.each do |bt|
output << "#{bt}\n" if line_number_limit.nil? || curr_line_no < line_number_limit # report First x lines of stacktrace in log
curr_line_no += 1
end

Rails.logger.error('ExceptionHelper.log_exception_backtrace') { "Stack-Trace for #{exception.class}:\n#{output}" }
Rails.logger.send(log_mode, 'ExceptionHelper.log_exception_backtrace') { "Stack-Trace for #{exception.class}:\n#{output}" }
end

# Raise an exception with original backtrace but extended message
Expand Down Expand Up @@ -44,7 +49,7 @@ def self.memory_info_hash
end

def self.log_memory_state(log_mode: :info)
raise "ExceptionHelper.log_memory_state: log_mode '#{log_mode}' is not supported" unless [:info, :error].include? log_mode
raise "ExceptionHelper.log_memory_state: log_mode '#{log_mode}' is not supported" unless [:debug, :info, :warn, :error].include? log_mode
Rails.logger.send(log_mode, "Memory resources:")
memory_info_hash.each do |key, value|
Rails.logger.send(log_mode, "#{value[:name].ljust(25)}: #{value[:value]}")
Expand Down
16 changes: 13 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

module Panorama
# VERSION and RELEASE_DATE should have fix syntax and positions because they are parsed from other sites
VERSION = '2.17.09'
RELEASE_DATE = Date.parse('2023-08-28')
VERSION = '2.17.10'
RELEASE_DATE = Date.parse('2023-09-15')

RELEASE_DAY = "%02d" % RELEASE_DATE.day
RELEASE_MONTH = "%02d" % RELEASE_DATE.month
Expand Down Expand Up @@ -56,7 +56,17 @@ class Application < Rails::Application
config.panorama_var_home = "#{Dir.tmpdir}/Panorama"
config.panorama_var_home_user_defined = false
end
Dir.mkdir config.panorama_var_home if !File.exist?(config.panorama_var_home) # Ensure that directory exists

unless File.exist?(config.panorama_var_home) # Ensure that directory exists
begin
Dir.mkdir config.panorama_var_home
raise "Directory #{config.panorama_var_home} does not exist and could not be created" unless File.exist?(config.panorama_var_home)
rescue Exception => e
logger.error('Panorama::Application') { "Error #{e.class}:#{e.message} while creating #{config.panorama_var_home}" }
exit! 1 # Ensure application terminates if initialization fails
end
end

logger.info "Panorama writes server side info to #{config.panorama_var_home}"

# Password for access on Admin menu, Panorama-Sampler config etc. : admin menu is activated if password is not empty
Expand Down

0 comments on commit ec30bdc

Please sign in to comment.