stackify-api-ruby 1.2.4 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6e7d47c5f5d7eba2a6326a4efdc6823d57aec456a946bc3eefd7694a29a8078
4
- data.tar.gz: d2b022c023a0593391e7e190ca1e5784cdb56c4afacd010fa73d40fa581f9189
3
+ metadata.gz: 9e13cf81984bdf8a8f010af5a741a3d98e56cb5aff747c8dbc934c0a47edf1a5
4
+ data.tar.gz: f4f69adfdde2a04c864440a8ca8dd3859529b4d397cbd26005dca9bd2aa1fea7
5
5
  SHA512:
6
- metadata.gz: 5d3ac89a398d1bf3192c6ed4a4cf8ab27e0523f67839ce17ff3d2fe41243bce977fe4d46a8dd8a23d684603aaf2dc6cc0ede38877ae16456c83b4d2693ce1af6
7
- data.tar.gz: 61f4ded1b2cef4c418333adcfe893b999b637acc7a055a08b0c3664f95637414b21510718bd9f3a86f9e037f8dec241eeb2fb9c5b8f32afb5a924aaf46dcaac4
6
+ metadata.gz: a27451afa0f62688c83977a9fb05f595689d0617d7c2d4f4e286c058d018e8eefe8051f03d4443dc27d3ebaaa35b0959ca281aa6205cf4e9dc777f259add3283
7
+ data.tar.gz: 2827a27560393bee018e43c0055b7ef2a32baeb569e7df45f84313fea6cd8aef5b75c1d1a9d8e4d3ad2af0a81f0b068b44f57ef1d7b73a83a9a6af4769a10007
@@ -1,3 +1,2 @@
1
1
  require 'json'
2
2
  require 'core_ext/object'
3
- require 'core_ext/fixnum'
@@ -2,8 +2,6 @@ require 'stackify/version'
2
2
  require 'stackify/utils/methods'
3
3
  require 'core_ext/core_ext' unless defined? Rails
4
4
 
5
- require 'google/protobuf'
6
- require 'proto/stackify-agent.rb'
7
5
 
8
6
  module Stackify
9
7
 
@@ -14,7 +12,6 @@ module Stackify
14
12
 
15
13
  autoload :Backtrace, 'stackify/utils/backtrace'
16
14
  autoload :MsgObject, 'stackify/utils/msg_object'
17
- autoload :ProtobufLogObject, 'stackify/utils/protobuf_log_object'
18
15
  autoload :Configuration, 'stackify/utils/configuration'
19
16
  autoload :HttpClient, 'stackify/http_client'
20
17
  autoload :Authorizable, 'stackify/authorization/authorizable'
@@ -1,5 +1,5 @@
1
1
  #
2
- # This class will handle the sending of protobuf message to agent
2
+ # This class will handle the sending of log group message to agent
3
3
  #
4
4
  module Stackify
5
5
  class AgentBaseSender < Worker
@@ -23,28 +23,27 @@ module Stackify
23
23
  def send_logs_task attempts = nil, msgs
24
24
  properties[:attempts] = attempts if attempts
25
25
  Stackify::ScheduleTask.new properties do
26
- data = create_log_group msgs
26
+ data = gather_and_pack_data(msgs).to_json
27
27
  send_request data
28
28
  end
29
29
  end
30
30
 
31
- # create_log_group() This function will create a log group protobuf object
32
- # @msgs {Object} Protobuf message
33
- # return {Object} Return an object
34
- def create_log_group msgs
35
- # @details {Object} it will return the properties based in Stackify.setup() configuration
36
- details = Stackify::Utils.get_app_settings
37
- log_group = Stackify::LogGroup.new
38
- msgs.each do |msg|
39
- log_group.logs << msg
40
- end
41
- log_group.environment = details['env'].to_s
42
- log_group.server_name = details['server_name'].to_s
43
- log_group.application_name = details['app_name'].to_s
44
- log_group.application_location = details['app_location'].to_s
45
- log_group.logger = 'Ruby logger'
46
- log_group.platform = 'ruby'
47
- log_group
31
+ def gather_and_pack_data msgs
32
+ details = Stackify::EnvDetails.instance.auth_info
33
+ {
34
+ 'CDID' => details['DeviceID'],
35
+ 'CDAppID' => details['DeviceAppID'],
36
+ 'Logger' => 'Rails logger',
37
+ 'AppName' => details['AppName'],
38
+ 'AppNameID' => details['AppNameID'],
39
+ 'Env' => details['Env'],
40
+ 'EnvID' => details['EnvID'],
41
+ 'AppEnvID' => details['AppEnvID'],
42
+ 'ServerName' => details['DeviceName'],
43
+ 'Msgs' => msgs,
44
+ 'AppLoc' => details['AppLocation'],
45
+ 'Platform' => 'Ruby'
46
+ }
48
47
  end
49
48
 
50
49
  def send_request log_group
@@ -36,11 +36,11 @@ module Stackify
36
36
  end
37
37
 
38
38
  def has_error msg
39
- !msg.error.nil?
39
+ !msg['Ex'].nil?
40
40
  end
41
41
 
42
42
  def get_epoch msg
43
- msg.date_millis
43
+ msg['EpochMs']
44
44
  end
45
45
 
46
46
  def send_logs msgs, attempts = 3
@@ -59,16 +59,16 @@ module Stackify
59
59
  e
60
60
  end
61
61
  ex = StackifiedError.new(ex, binding())
62
- Stackify.msgs_queue << Stackify::ProtobufLogObject.new(level, ex.message, caller[0], trans_id, log_uuid, ex).to_obj
62
+ Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], trans_id, log_uuid, ex).to_h
63
63
  else
64
- Stackify.msgs_queue << Stackify::ProtobufLogObject.new(level, msg, caller[0], trans_id, log_uuid).to_obj
64
+ Stackify.msgs_queue << Stackify::MsgObject.new(level, msg, caller[0], trans_id, log_uuid).to_h
65
65
  end
66
66
  end
67
67
  end
68
68
 
69
69
  def log_exception_task level, ex, trans_id=nil, log_uuid=nil
70
70
  Stackify::ScheduleTask.new ({limit: 1}) do
71
- Stackify.msgs_queue << Stackify::ProtobufLogObject.new(level, ex.message, caller[0], trans_id, log_uuid, ex).to_obj
71
+ Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], trans_id, log_uuid, ex).to_h
72
72
  end
73
73
  end
74
74
 
@@ -3,27 +3,25 @@ require 'faraday'
3
3
  require 'ostruct'
4
4
 
5
5
  #
6
- # This class will handle the sending of protobuf message to agent using http request
6
+ # This class will handle the sending of log messages to agent using http request
7
7
  #
8
8
  module Stackify
9
9
  class AgentHTTPSender < AgentBaseSender
10
10
 
11
11
  HEADERS = {
12
- 'Content-Type' => 'application/x-protobuf'
12
+ 'Content-Type' => 'application/json'
13
13
  }
14
14
 
15
15
  # send_request() This function will post an http request
16
- # @msgs {Object} Protobuf message
16
+ # @msgs {Object} log group message
17
17
  # return {Object} Return an object {status, message}
18
18
  def send_request log_group
19
19
  begin
20
- # Convert data into binary and send it to agent
21
- message = Stackify::LogGroup.encode(log_group)
22
20
  conn = Faraday.new(proxy: Stackify.configuration.proxy, ssl: { verify: false })
23
21
  @response = conn.post do |req|
24
22
  req.url URI(Stackify.configuration.http_endpoint + Stackify.configuration.agent_log_url)
25
23
  req.headers = HEADERS
26
- req.body = message
24
+ req.body = log_group
27
25
  end
28
26
  if @response.try(:status) == 200
29
27
  Stackify.internal_log :debug, "[AgentHTTPSender]: Successfully send message via http request."
@@ -40,7 +40,7 @@ module Stackify
40
40
 
41
41
  def to_h
42
42
  env = Stackify::EnvDetails.instance
43
- {
43
+ data = {
44
44
  'OccurredEpochMillis' => Time.now.to_f*1000,
45
45
  'Error' => {
46
46
  'InnerError' => @exception.try(:cause),
@@ -52,11 +52,20 @@ module Stackify
52
52
  'SourceMethod' => source_method,
53
53
  },
54
54
  'EnvironmentDetail' => env.auth_info,
55
- 'WebRequestDetail' => env.request_details.try{ |d| d.fetch('webrequest_details', '') },
56
- 'ServerVariables' => env.request_details.try{ |d| d.fetch('server_variables', '') },
57
55
  'CustomerName' => 'Customer',
58
56
  'UserName' => @context.fetch('user', '')
59
57
  }
58
+ web_request_details = env.request_details.try{ |d| d.fetch('webrequest_details', '') }
59
+ if web_request_details.nil?
60
+ data['WebRequestDetail'] = web_request_details
61
+ end
62
+
63
+ server_variables = env.request_details.try{ |d| d.fetch('server_variables', '') }
64
+ if server_variables.nil?
65
+ data['ServerVariables'] = server_variables
66
+ end
67
+
68
+ data
60
69
  end
61
70
 
62
71
  end
@@ -1,6 +1,6 @@
1
1
  module Stackify::Metrics
2
2
  class MetricsClient
3
-
3
+ TEN_MINUTES = 600
4
4
  attr_reader :metrics_queue
5
5
 
6
6
  def initialize
@@ -57,7 +57,7 @@ module Stackify::Metrics
57
57
 
58
58
  def start_upload_metrics
59
59
  current_time = Stackify::Utils.rounded_current_time
60
- purge_older_than = current_time - 10.minutes
60
+ purge_older_than = current_time - TEN_MINUTES
61
61
  #read everything up to the start of the current minute
62
62
  read_queued_metrics_batch current_time
63
63
  handle_zero_reports current_time
@@ -67,7 +67,7 @@ module Stackify::Metrics
67
67
  if first_50_metrics.length > 0
68
68
  #only getting metrics less than 10 minutes old to drop old data in case we get backed up
69
69
  #they are removed from the @aggregated_metrics in the upload function upon success
70
- upload_aggregates(first_50_metrics.select { |_key, aggr| aggr.occurred_utc > current_time - 10.minutes })
70
+ upload_aggregates(first_50_metrics.select { |_key, aggr| aggr.occurred_utc > current_time - TEN_MINUTES })
71
71
  end
72
72
  @aggregate_metrics.delete_if { |_key, aggr| aggr.occurred_utc < purge_older_than }
73
73
  end
@@ -2,22 +2,20 @@ require 'net_http_unix'
2
2
  require 'ostruct'
3
3
 
4
4
  #
5
- # This class will handle the sending of protobuf message to unix domain socket
5
+ # This class will handle the sending of log messages to unix domain socket
6
6
  #
7
7
  module Stackify
8
8
  class UnixSocketSender < AgentBaseSender
9
9
 
10
10
  # send_request() This function will send http request via unix domain socket
11
- # @msgs {Object} Protobuf message
11
+ # @msgs {Object} log group message
12
12
  # return {Object} Return an object {status, message}
13
13
  def send_request log_group
14
14
  begin
15
- # Convert data into binary and send it to unix domain socket
16
- message = Stackify::LogGroup.encode(log_group)
17
15
  client = NetX::HTTPUnix.new('unix://' + Stackify.configuration.unix_socket_path)
18
16
  req = Net::HTTP::Post.new(Stackify.configuration.agent_log_url)
19
- req.set_content_type('application/x-protobuf')
20
- req.body = message
17
+ req.set_content_type('application/json')
18
+ req.body = log_group
21
19
  response = client.request(req)
22
20
  Stackify.internal_log :debug, "[UnixSocketSender] status_code = #{response.code}"
23
21
  if response.code.to_i == 200
@@ -3,6 +3,7 @@ module Stackify::Backtrace
3
3
  ALL_TEXT_FROM_START_TO_FIRST_COLON_REGEXP = /\A([^:]+)/
4
4
  NUMBER_BETWEEN_TWO_COLONS_REGEXP = /:(\d+):/
5
5
  TEXT_AFTER_IN_BEFORE_END_REGEXP = /in\s`(\S+)'\z/
6
+ TEXT_AFTER_IN_BEFORE_END_REGEXP_ = /in\s(\S+)'\z/
6
7
 
7
8
  def self.line_number backtrace_str
8
9
  backtrace_str[NUMBER_BETWEEN_TWO_COLONS_REGEXP, 1]
@@ -10,7 +11,7 @@ module Stackify::Backtrace
10
11
 
11
12
  def self.method_name backtrace_str
12
13
  return nil unless backtrace_str
13
- backtrace_str[TEXT_AFTER_IN_BEFORE_END_REGEXP, 1]
14
+ backtrace_str[TEXT_AFTER_IN_BEFORE_END_REGEXP, 1] || backtrace_str[TEXT_AFTER_IN_BEFORE_END_REGEXP_, 1]
14
15
  end
15
16
 
16
17
  def self.file_name backtrace_str
@@ -1,3 +1,3 @@
1
1
  module Stackify
2
- VERSION = '1.2.4'
2
+ VERSION = '1.2.7'
3
3
  end
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'bundler', '~> 1.6'
23
23
  spec.add_development_dependency 'rake', '~> 0'
24
24
  spec.add_runtime_dependency 'faraday', '~> 0.8'
25
- spec.add_runtime_dependency 'google-protobuf', '~> 3.0'
26
25
  spec.add_runtime_dependency 'net_http_unix', '~> 0.2'
27
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-03 00:00:00.000000000 Z
11
+ date: 2020-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.8'
55
- - !ruby/object:Gem::Dependency
56
- name: google-protobuf
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: net_http_unix
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +81,6 @@ files:
95
81
  - README.md
96
82
  - Rakefile
97
83
  - lib/core_ext/core_ext.rb
98
- - lib/core_ext/fixnum.rb
99
84
  - lib/core_ext/object.rb
100
85
  - lib/generators/stackify/stackify_generator.rb
101
86
  - lib/generators/stackify/templates/stackify.rb
@@ -1,17 +0,0 @@
1
- class Fixnum
2
- SECONDS_IN_MINUTE = 60
3
- SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE
4
- SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR
5
-
6
- def days
7
- self * SECONDS_IN_DAY
8
- end
9
-
10
- def minutes
11
- self * SECONDS_IN_MINUTE
12
- end
13
-
14
- def ago
15
- Time.now - self
16
- end
17
- end