mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-04 22:02:18 +08:00
New log lines are added Kubernetes client logging was not consistent with the Plugins logging and was using logger.debug. In order to make the logging experience coherent, all loggings are now using the .info method. Kwargs is also logged while running commands which would help debugging issues and tracking the flow
37 lines
1 KiB
Ruby
37 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "open3"
|
|
require "securerandom"
|
|
|
|
module Csi
|
|
module ServiceHelper
|
|
def log_with_id(req_id, message)
|
|
@logger.info("[req_id=#{req_id}] #{message}")
|
|
end
|
|
|
|
def log_request_response(req, type)
|
|
raise GRPC::InvalidArgument.new("Request cannot be nil", GRPC::Core::StatusCodes::INVALID_ARGUMENT) unless req
|
|
req_id = SecureRandom.uuid
|
|
log_with_id(req_id, "#{type} request: #{req.inspect}")
|
|
resp = yield(req_id)
|
|
log_with_id(req_id, "#{type} response: #{resp.inspect}")
|
|
resp
|
|
end
|
|
|
|
def log_run_cmd(req_id, cmd, **kwargs)
|
|
log_with_id(req_id, "Running command: #{cmd.join(" ")} with #{kwargs}")
|
|
yield
|
|
end
|
|
|
|
def run_cmd(*cmd, req_id:, **kwargs)
|
|
log_run_cmd(req_id, cmd, **kwargs) do
|
|
Open3.capture2e(*cmd, **kwargs)
|
|
end
|
|
end
|
|
|
|
def log_and_raise(req_id, exception)
|
|
log_with_id(req_id, "#{exception.class}: #{exception.message}\n#{exception.backtrace.join("\n")}")
|
|
raise GRPC::Internal.new(exception.message)
|
|
end
|
|
end
|
|
end
|