Module: StackifyRubyAPM::Util

Defined in:
lib/stackify_apm/util.rb,
lib/stackify_apm/util/inflector.rb,
lib/stackify_apm/util/inspector.rb,
lib/stackify_apm/util/lru_cache.rb,
lib/stackify_apm/util/trace_log_watcher.rb

Overview

rubocop:disable all

Defined Under Namespace

Modules: Inflector, TraceLogWatcher Classes: Inspector, LruCache

Constant Summary collapse

URL_ID_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^(\d+)$/
URL_GUID_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^(?i)(\b[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-F0-9]{12}\b)$/
URL_EMAIL_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^((([!#$%&'*+\-\/=?^_`{|}~\w])|([!#$%&'*+\-\/=?^_`{|}~\w][!#$%&'*+\-\/=?^_`{|}~\.\w]{0,}[!#$%&'*+\-\/=?^_`{|}~\w]))[@]\w+([-.]\w+)*\.\w+([-.]\w+)*)$/
URL_IP_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/

Class Method Summary collapse

Class Method Details

.checkOrCreateFolder(dir_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/stackify_apm/util.rb', line 99

def self.checkOrCreateFolder(dir_name)
  if (dir_name.to_s.empty?)
    return false
  end

  if (!fileExists?(dir_name))
    umask = File.umask
    File.umask(0)
    FileUtils.mkdir_p(dir_name)
    File.chmod(0777, dir_name)
    File.umask(umask)
  end

  if (!fileExists?(dir_name))
    puts "Util::Stackify Profiler unable to find [" + dir_name + "]"
    return false
  end

  if (!File.writable?(dir_name))
    puts "Util::Stackify Profiler unable to access/write [" + dir_name + "]"
    return false
  end

  return true
end

.fileExists?(dir_name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
# File 'lib/stackify_apm/util.rb', line 90

def self.fileExists?(dir_name)
  # Ruby 3.2 changed File.exists to File.exist.
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
    return File.exists?(dir_name)
  else
    return File.exist?(dir_name)
  end
end

.host_osObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stackify_apm/util.rb', line 11

def self.host_os
  host_os = RbConfig::CONFIG['host_os']
  case host_os
  when /cygwin|mswin|mingw|bccwin|wince|emx/i
    'WINDOWS'
  when /linux|arch/i
    'LINUX'
  when /sunos|solaris/i
    'SOLARIS'
  when /bsd/i
    'BSD'
  when /darwin/i
    'MAC OS X'
  else
    "UNKNOWN #{host_os}"
  end
end

.maskReportingUrl(url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/stackify_apm/util.rb', line 44

def self.maskReportingUrl(url)
  parts = url.split('/', -1)

  if (!parts.length)
    return '/'
  end

  maskedParts = []
  parts.each do |part|
    maskedParts.push(maskString(part))
  end

  maskedUrl = maskedParts.join('/')

  if (maskedUrl.length == 1)
    return maskedUrl
  end

  if maskedUrl.end_with?('/')
    trimmedUrl = maskedUrl.slice(0, maskedUrl.length-1)
    if (!trimmedUrl.length)
      return '/'
    end

    return trimmedUrl
  end

  maskedUrl
end

.maskString(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/stackify_apm/util.rb', line 74

def self.maskString(string)
  return '{id}' if string =~ URL_ID_REGEX
  return '{guid}' if string =~ URL_GUID_REGEX
  return '{email}' if string =~ URL_EMAIL_REGEX
  return '{ip}' if string =~ URL_IP_REGEX

  if string.include? ';'
    string_index = string.index(';');
    return '' if (string_index <= 0)
    return string[0..string.index(';')-1]  if (string_index)
  end

  # Default
  string
end

.micros(target = Time.now.utc) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



7
8
9
# File 'lib/stackify_apm/util.rb', line 7

def self.micros(target = Time.now.utc)
  target.to_i * 1_000_000 + target.usec
end

.pushToAryIndex(ary, idx, val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Push the element to existing array of object with incremented index(key/value pair) We get the prepared statement values [‘J.K. Rowling’, ‘Harry Potter’, …] and restructure it. Example structured: [‘J.K. Rowling’,‘Harry Potter’, …, ‘other data’]



32
33
34
35
36
37
# File 'lib/stackify_apm/util.rb', line 32

def self.pushToAryIndex(ary, idx, val)
  obj = {}
  i = idx + 1
  obj[i] = val.to_s
  ary.push(obj)
end