55The Instana agent (for GCR) that manages
66monitoring state and reporting that data.
77"""
8- import time
8+
99from instana .options import GCROptions
1010from instana .collector .google_cloud_run import GCRCollector
1111from instana .log import logger
1515
1616
1717class GCRAgent (BaseAgent ):
18- """ In-process agent for Google Cloud Run """
18+ """In-process agent for Google Cloud Run"""
1919
2020 def __init__ (self , service , configuration , revision ):
2121 super (GCRAgent , self ).__init__ ()
@@ -28,15 +28,20 @@ def __init__(self, service, configuration, revision):
2828 # Update log level (if INSTANA_LOG_LEVEL was set)
2929 self .update_log_level ()
3030
31- logger .info ("Stan is on the AWS Fargate scene. Starting Instana instrumentation version: %s" , VERSION )
31+ logger .info (
32+ "Stan is on the AWS Fargate scene. Starting Instana instrumentation version: %s" ,
33+ VERSION ,
34+ )
3235
3336 if self ._validate_options ():
3437 self ._can_send = True
3538 self .collector = GCRCollector (self , service , configuration , revision )
3639 self .collector .start ()
3740 else :
38- logger .warning ("Required INSTANA_AGENT_KEY and/or INSTANA_ENDPOINT_URL environment variables not set. "
39- "We will not be able monitor this GCR cluster." )
41+ logger .warning (
42+ "Required INSTANA_AGENT_KEY and/or INSTANA_ENDPOINT_URL environment variables not set. "
43+ "We will not be able monitor this GCR cluster."
44+ )
4045
4146 def can_send (self ):
4247 """
@@ -50,7 +55,7 @@ def get_from_structure(self):
5055 Retrieves the From data that is reported alongside monitoring data.
5156 @return: dict()
5257 """
53- return {'hl' : True , 'cp' : ' gcp' , 'e' : self .collector .get_instance_id ()}
58+ return {"hl" : True , "cp" : " gcp" , "e" : self .collector .get_instance_id ()}
5459
5560 def report_data_payload (self , payload ):
5661 """
@@ -63,19 +68,25 @@ def report_data_payload(self, payload):
6368 self .report_headers = {
6469 "Content-Type" : "application/json" ,
6570 "X-Instana-Host" : "gcp:cloud-run:revision:{revision}" .format (
66- revision = self .collector .revision ),
67- "X-Instana-Key" : self .options .agent_key
71+ revision = self .collector .revision
72+ ),
73+ "X-Instana-Key" : self .options .agent_key ,
6874 }
6975
70- response = self .client .post (self .__data_bundle_url (),
71- data = to_json (payload ),
72- headers = self .report_headers ,
73- timeout = self .options .timeout ,
74- verify = self .options .ssl_verify ,
75- proxies = self .options .endpoint_proxy )
76+ response = self .client .post (
77+ self .__data_bundle_url (),
78+ data = to_json (payload ),
79+ headers = self .report_headers ,
80+ timeout = self .options .timeout ,
81+ verify = self .options .ssl_verify ,
82+ proxies = self .options .endpoint_proxy ,
83+ )
7684
7785 if response .status_code >= 400 :
78- logger .info ("report_data_payload: Instana responded with status code %s" , response .status_code )
86+ logger .info (
87+ "report_data_payload: Instana responded with status code %s" ,
88+ response .status_code ,
89+ )
7990 except Exception as exc :
8091 logger .debug ("report_data_payload: connection error (%s)" , type (exc ))
8192 return response
@@ -84,7 +95,9 @@ def _validate_options(self):
8495 """
8596 Validate that the options used by this Agent are valid. e.g. can we report data?
8697 """
87- return self .options .endpoint_url is not None and self .options .agent_key is not None
98+ return (
99+ self .options .endpoint_url is not None and self .options .agent_key is not None
100+ )
88101
89102 def __data_bundle_url (self ):
90103 """
0 commit comments