virajjasani commented on a change in pull request #754: HBASE-22978 : Online slow response log URL: https://github.com/apache/hbase/pull/754#discussion_r378054411
########## File path: hbase-shell/src/main/ruby/hbase/admin.rb ########## @@ -1453,6 +1453,97 @@ def list_decommissioned_regionservers @admin.listDecommissionedRegionServers end + #---------------------------------------------------------------------------------------------- + # Retrieve SlowLog Responses from RegionServers + def get_slowlog_responses(server_names, args) + unless server_names.is_a?(Array) || server_names.is_a?(String) + raise(ArgumentError, + "#{server_names.class} of #{server_names.inspect} is not of Array/String type") + end + if server_names == '*' + server_names = getServerNames([], true) + else + server_names_list = get_server_names(server_names) + server_names = getServerNames(server_names_list, false) + end + slow_log_responses = @admin.getSlowLogResponses(server_names) + filtered_log_responses = filter_slow_responses(args, + slow_log_responses) + puts 'Retrieved SlowLog Responses from RegionServers.....' + if args.empty? + puts slow_log_responses.to_s + else + puts filtered_log_responses.to_s + end + end + + def filter_slow_responses(args, slow_log_responses) + filtered_log_responses = java.util.ArrayList.new + slow_log_responses.each do |slow_log| + if args.key? 'REGION_NAME' + region_name = args['REGION_NAME'] + unless region_name.nil? + if region_name.eql?(slow_log.getRegionName) + filtered_log_responses.add(slow_log) + next + end + end + end + if args.key? 'TABLE_NAME' + table_name = args['TABLE_NAME'] + unless table_name.nil? + if slow_log.getRegionName.start_with?(table_name) + filtered_log_responses.add(slow_log) + next + end + end + end + if args.key? 'CLIENT_IP' + client_ip = args['CLIENT_IP'] + unless client_ip.nil? + if client_ip.eql?(slow_log.getClientAddress) + filtered_log_responses.add(slow_log) + next + end + end + end + if args.key? 'USER' + user = args['USER'] + unless user.nil? + if user.eql?(slow_log.getUserName) + filtered_log_responses.add(slow_log) + next + end + end + end + end + filtered_log_responses + end + + #---------------------------------------------------------------------------------------------- + # Clears SlowLog Responses from RegionServers + def clear_slowlog_responses(server_names) + unless server_names.nil? || server_names.is_a?(Array) || server_names.is_a?(String) + raise(ArgumentError, + "#{server_names.class} of #{server_names.inspect} is not of correct type") + end + if server_names.nil? + server_names = getServerNames([], true) + else + server_names_list = get_server_names(server_names) + server_names = getServerNames(server_names_list, false) + end + clear_log_responses = @admin.clearSlowLogResponses(server_names) + clear_log_success_count = 0 + clear_log_responses.each do |response| + if response + clear_log_success_count += 1 + end + end + puts 'Cleared Slowlog responses from ' \ + "#{clear_log_success_count}/#{clear_log_responses.size} RegionServers" Review comment: Good question, this is bit tricky. If clear log responses didn't go through, may be client can retry but if it again keeps failing for some RS, it would be nice to display server names where it failed but again that is difficult to implement. Might fit well for a sub-task. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services