class Rookout::ComWs::Information

Attributes

agent_id[RW]
labels[RW]

Public Class Methods

new(labels, k8s_file_path = "/var/run/secrets/kubernetes.io/serviceaccount/namespace") click to toggle source
# File lib/rookout/com_ws/information.rb, line 14
def initialize labels, k8s_file_path = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
  @agent_id = nil
  @labels = labels.clone
  @labels["rookout_debug"] = "on" if Config.debug

  k8_namespace = create_cluster_namespace k8s_file_path
  unless k8_namespace == ""
    @labels["k8s_namespace"] = k8_namespace
  end

  @ip_addr = local_ip

  @scm_info = create_scm_information
end

Public Instance Methods

pack() click to toggle source
# File lib/rookout/com_ws/information.rb, line 29
def pack
  version_info = Com::Rookout::VersionInformation.new version: Config.rookout_version,
                                                      commit: Config.rookout_commit

  network_info = Com::Rookout::NetworkInformation.new ip_addr: @ip_addr

  system_info = Com::Rookout::SystemInformation.new hostname: Socket.gethostname,
                                                    os: RUBY_PLATFORM,
                                                    os_version: "",
                                                    distro: "",
                                                    arch: ""

  platform_info = Com::Rookout::PlatformInformation.new platform: "ruby",
                                                        version: RUBY_VERSION,
                                                        variant: RUBY_ENGINE

  Com::Rookout::AgentInformation.new agent_id: @agent_id,
                                     version: version_info,
                                     network: network_info,
                                     system: system_info,
                                     platform: platform_info,
                                     executable: $PROGRAM_NAME,
                                     command_arguments: ARGV,
                                     process_id: Process.pid,
                                     labels: @labels,
                                     scm: @scm_info
end

Private Instance Methods

create_cluster_namespace(k8s_file_path) click to toggle source

rubocop:enable Style/ParallelAssignment

# File lib/rookout/com_ws/information.rb, line 73
def create_cluster_namespace k8s_file_path
  return_value = ""

  # No Kubernetes is valid
  if File.file? k8s_file_path
    # Read the file contents and return it as result
    return_value = File.read k8s_file_path
  end

  return_value
end
create_scm_information() click to toggle source
# File lib/rookout/com_ws/information.rb, line 85
def create_scm_information
  user_git_origin = Config.user_git_origin || ENV["ROOKOUT_REMOTE_ORIGIN"]
  user_git_commit = Config.user_git_commit || ENV["ROOKOUT_COMMIT"]

  if user_git_origin.nil? && user_git_commit.nil?
    search_path = File.dirname File.absolute_path($PROGRAM_NAME)
    git_root = find_root search_path
    if git_root
      user_git_origin = remote_origin git_root
      user_git_commit = revision git_root
    end
  end

  Com::Rookout::SCMInformation.new origin: user_git_origin, commit: user_git_commit
end
local_ip() click to toggle source

rubocop:disable Style/ParallelAssignment

# File lib/rookout/com_ws/information.rb, line 62
def local_ip
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
  UDPSocket.open do |s|
    s.connect "10.255.255.255", 1
    s.addr.last
  end
ensure
  Socket.do_not_reverse_lookup = orig
end