11import logging
22
3- from stackify .constants import LOG_SAVE_URL
4- from stackify .constants import SOCKET_LOG_URL
3+ from stackify .constants import TRANSPORT_TYPE_AGENT_HTTP
54from stackify .constants import TRANSPORT_TYPE_AGENT_SOCKET
65from stackify .constants import TRANSPORT_TYPE_DEFAULT
7- from stackify .transport .agent import AgentSocket
8- from stackify .transport .agent .message import Log
9- from stackify .transport .agent .message import LogGroup
6+ from stackify .transport .agent import AgentSocketTransport
7+ from stackify .transport .agent import AgentHTTPTransport
108from stackify .transport .application import get_configuration
119from stackify .transport .application import EnvironmentDetail
12- from stackify .transport .default import HTTPClient
13- from stackify .transport .default .log import LogMsg
14- from stackify .transport .default .log import LogMsgGroup
10+ from stackify .transport .default import DefaultTransport
11+
1512
1613internal_logger = logging .getLogger (__name__ )
1714
@@ -24,93 +21,34 @@ class TransportTypes(object):
2421 Types:
2522 * DEFAULT - HTTP transport that will directly send logs to the Platform
2623 * AGENT_SOCKET - HTTP warapped Unix Socket Domain that will send logs to the StackifyAgent
24+ * AGENT_HTTP - HTTP transport that will send logs to the Agent using HTTP requests
2725 """
2826
2927 DEFAULT = TRANSPORT_TYPE_DEFAULT
3028 AGENT_SOCKET = TRANSPORT_TYPE_AGENT_SOCKET
29+ AGENT_HTTP = TRANSPORT_TYPE_AGENT_HTTP
3130
3231 @classmethod
3332 def get_transport (self , api_config = None , env_details = None ):
3433 # determine which transport to use depening on users config
3534 if api_config .transport == self .AGENT_SOCKET :
3635 internal_logger .debug ('Setting Agent Socket Transport.' )
37- api_config .transport = self .AGENT_SOCKET
38- return AgentSocket ()
36+ return AgentSocketTransport (api_config , env_details )
37+
38+ if api_config .transport == self .AGENT_HTTP :
39+ internal_logger .debug ('Setting Agent HTTP Transport.' )
40+ return AgentHTTPTransport (api_config , env_details )
3941
4042 internal_logger .debug ('Setting Default Transport.' )
4143 api_config .transport = self .DEFAULT
42- return HTTPClient (api_config , env_details )
43-
44- @classmethod
45- def create_message (self , record , api_config , env_details ):
46- # create message depending on which transport
47- if api_config .transport == self .AGENT_SOCKET :
48- return Log (record , api_config , env_details ).get_object ()
49-
50- msg = LogMsg ()
51- msg .from_record (record )
52- return msg
53-
54- @classmethod
55- def create_group_message (self , messages , api_config , env_details ):
56- # create group message depending on which transport
57- if api_config .transport == self .AGENT_SOCKET :
58- return LogGroup (messages , api_config , env_details ).get_object ()
59-
60- return LogMsgGroup (messages )
61-
62- @classmethod
63- def get_log_url (self , api_config ):
64- # return log url depending on which transport
65- if api_config .transport == self .AGENT_SOCKET :
66- return api_config .socket_url + SOCKET_LOG_URL
67-
68- return LOG_SAVE_URL
69-
70- @classmethod
71- def prepare_message (self , api_config , message ):
72- # convert message depending on which transport
73- if api_config .transport == self .AGENT_SOCKET :
74- return message .SerializeToString ()
75-
76- return message
77-
78-
79- class Transport (object ):
80- """
81- Transport base class
82- """
83-
84- def __init__ (self , config = None , ** kwargs ):
85- self .api_config = config or get_configuration (** kwargs )
86- self .env_details = EnvironmentDetail (self .api_config )
87- self ._transport = TransportTypes .get_transport (
88- self .api_config ,
89- self .env_details ,
90- )
91-
92- def create_message (self , record ):
93- # create message from record
94- return TransportTypes .create_message (
95- record ,
96- self .api_config ,
97- self .env_details ,
98- )
44+ return DefaultTransport (api_config , env_details )
9945
100- def create_group_message (self , messages ):
101- # create group message from list of records
102- return TransportTypes .create_group_message (
103- messages ,
104- self .api_config ,
105- self .env_details ,
106- )
10746
108- def send (self , group_message ):
109- # send group message
110- try :
111- self ._transport .send (
112- TransportTypes .get_log_url (self .api_config ),
113- TransportTypes .prepare_message (self .api_config , group_message ),
114- )
115- except Exception as e :
116- internal_logger .error ('Request error: {}' .format (e ))
47+ def configure_transport (config = None , ** kwargs ):
48+ # return which transport to use depending on users input
49+ api_config = config or get_configuration (** kwargs )
50+ env_details = EnvironmentDetail (api_config )
51+ return TransportTypes .get_transport (
52+ api_config ,
53+ env_details ,
54+ )
0 commit comments