From ec30bdc92622572971f9688dc84ba5790e6e94d9 Mon Sep 17 00:00:00 2001 From: Peter Ramm Date: Fri, 15 Sep 2023 22:04:35 +0200 Subject: [PATCH] Bugfix: Increase logging after connect error (including internal errors) Dragnet: Add number of dependencies for unused tables --- app/controllers/application_controller.rb | 8 ++------ app/controllers/env_controller.rb | 3 +++ app/helpers/dragnet/unused_tables_helper.rb | 22 ++++++++++++++------- app/helpers/exception_helper.rb | 13 ++++++++---- config/application.rb | 16 ++++++++++++--- 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 02d90e09..4ef3af2a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/env_controller.rb b/app/controllers/env_controller.rb index 7204c7a4..1356b45a 100644 --- a/app/controllers/env_controller.rb +++ b/app/controllers/env_controller.rb @@ -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("#{ diff --git a/app/helpers/dragnet/unused_tables_helper.rb b/app/helpers/dragnet/unused_tables_helper.rb index 779b4379..3d0b6806 100644 --- a/app/helpers/dragnet/unused_tables_helper.rb +++ b/app/helpers/dragnet/unused_tables_helper.rb @@ -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", diff --git a/app/helpers/exception_helper.rb b/app/helpers/exception_helper.rb index da26d158..34b561b4 100644 --- a/app/helpers/exception_helper.rb +++ b/app/helpers/exception_helper.rb @@ -4,8 +4,13 @@ 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| @@ -13,7 +18,7 @@ def log_exception_backtrace(exception, line_number_limit=nil) 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 @@ -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]}") diff --git a/config/application.rb b/config/application.rb index cae55fab..79836a52 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 @@ -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