Skip to content

Commit 50832eb

Browse files
jaygel179Elpedio Adoptante Jr
andauthored
Ruby API - Remove protobuf from ruby api - use jsoni (#32)
* Ruby API - Remove protobuf from ruby api - use jsoni Changes: - remove protobuf - use json instead * fix issue with checking error and getting of time Co-authored-by: Elpedio Adoptante Jr <eadoptante@stackify.com>
1 parent a04320b commit 50832eb

File tree

6 files changed

+31
-40
lines changed

6 files changed

+31
-40
lines changed

lib/stackify-api-ruby.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
require 'stackify/utils/methods'
33
require 'core_ext/core_ext' unless defined? Rails
44

5-
require 'google/protobuf'
6-
require 'proto/stackify-agent.rb'
75

86
module Stackify
97

@@ -14,7 +12,6 @@ module Stackify
1412

1513
autoload :Backtrace, 'stackify/utils/backtrace'
1614
autoload :MsgObject, 'stackify/utils/msg_object'
17-
autoload :ProtobufLogObject, 'stackify/utils/protobuf_log_object'
1815
autoload :Configuration, 'stackify/utils/configuration'
1916
autoload :HttpClient, 'stackify/http_client'
2017
autoload :Authorizable, 'stackify/authorization/authorizable'

lib/stackify/agent_base_sender.rb

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
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
33
#
44
module Stackify
55
class AgentBaseSender < Worker
@@ -23,28 +23,27 @@ def properties
2323
def send_logs_task attempts = nil, msgs
2424
properties[:attempts] = attempts if attempts
2525
Stackify::ScheduleTask.new properties do
26-
data = create_log_group msgs
26+
data = gather_and_pack_data(msgs).to_json
2727
send_request data
2828
end
2929
end
3030

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+
}
4847
end
4948

5049
def send_request log_group

lib/stackify/agent_client.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def log_exception level= :error, ex, task
3636
end
3737

3838
def has_error msg
39-
!msg.error.nil?
39+
!msg['Ex'].nil?
4040
end
4141

4242
def get_epoch msg
43-
msg.date_millis
43+
msg['EpochMs']
4444
end
4545

4646
def send_logs msgs, attempts = 3
@@ -59,16 +59,16 @@ def log_message_task level, msg, call_trace, trans_id=nil, log_uuid=nil
5959
e
6060
end
6161
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
6363
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
6565
end
6666
end
6767
end
6868

6969
def log_exception_task level, ex, trans_id=nil, log_uuid=nil
7070
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
7272
end
7373
end
7474

lib/stackify/agent_http_sender.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,25 @@
33
require 'ostruct'
44

55
#
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
77
#
88
module Stackify
99
class AgentHTTPSender < AgentBaseSender
1010

1111
HEADERS = {
12-
'Content-Type' => 'application/x-protobuf'
12+
'Content-Type' => 'application/json'
1313
}
1414

1515
# send_request() This function will post an http request
16-
# @msgs {Object} Protobuf message
16+
# @msgs {Object} log group message
1717
# return {Object} Return an object {status, message}
1818
def send_request log_group
1919
begin
20-
# Convert data into binary and send it to agent
21-
message = Stackify::LogGroup.encode(log_group)
2220
conn = Faraday.new(proxy: Stackify.configuration.proxy, ssl: { verify: false })
2321
@response = conn.post do |req|
2422
req.url URI(Stackify.configuration.http_endpoint + Stackify.configuration.agent_log_url)
2523
req.headers = HEADERS
26-
req.body = message
24+
req.body = log_group
2725
end
2826
if @response.try(:status) == 200
2927
Stackify.internal_log :debug, "[AgentHTTPSender]: Successfully send message via http request."

lib/stackify/unix_socket_sender.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
require 'ostruct'
33

44
#
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
66
#
77
module Stackify
88
class UnixSocketSender < AgentBaseSender
99

1010
# send_request() This function will send http request via unix domain socket
11-
# @msgs {Object} Protobuf message
11+
# @msgs {Object} log group message
1212
# return {Object} Return an object {status, message}
1313
def send_request log_group
1414
begin
15-
# Convert data into binary and send it to unix domain socket
16-
message = Stackify::LogGroup.encode(log_group)
1715
client = NetX::HTTPUnix.new('unix://' + Stackify.configuration.unix_socket_path)
1816
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
2119
response = client.request(req)
2220
Stackify.internal_log :debug, "[UnixSocketSender] status_code = #{response.code}"
2321
if response.code.to_i == 200

stackify-api-ruby.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
2222
spec.add_development_dependency 'bundler', '~> 1.6'
2323
spec.add_development_dependency 'rake', '~> 0'
2424
spec.add_runtime_dependency 'faraday', '~> 0.8'
25-
spec.add_runtime_dependency 'google-protobuf', '~> 3.0'
2625
spec.add_runtime_dependency 'net_http_unix', '~> 0.2'
2726
end

0 commit comments

Comments
 (0)