7575# of 40 seconds.
7676_HTTP_TIMEOUT_SECONDS = 100
7777
78+ # The map from the values of flags (breakpoint_enable_canary,
79+ # breakpoint_allow_canary_override) to canary mode.
80+ _CANARY_MODE_MAP = {
81+ (True , True ): 'CANARY_MODE_DEFAULT_ENABLED' ,
82+ (True , False ): 'CANARY_MODE_ALWAYS_ENABLED' ,
83+ (False , True ): 'CANARY_MODE_DEFAULT_DISABLED' ,
84+ (False , False ): 'CANARY_MODE_ALWAYS_DISABLED' ,
85+ }
86+
7887
7988class NoProjectIdError (Exception ):
8089 """Used to indicate the project id cannot be determined."""
@@ -101,6 +110,8 @@ def __init__(self):
101110 self ._debuggee_labels = {}
102111 self ._service_account_auth = False
103112 self ._debuggee_id = None
113+ self ._agent_id = None
114+ self ._canary_mode = None
104115 self ._wait_token = 'init'
105116 self ._breakpoints = []
106117 self ._main_thread = None
@@ -218,6 +229,21 @@ def SetupAuth(self,
218229 self ._project_id = project_id
219230 self ._project_number = project_number or project_id
220231
232+ def SetupCanaryMode (self , breakpoint_enable_canary ,
233+ breakpoint_allow_canary_override ):
234+ """Sets up canaryMode for the debuggee according to input parameters.
235+
236+ Args:
237+ breakpoint_enable_canary: str or bool, whether to enable breakpoint
238+ canary. Any string except 'True' is interpreted as False.
239+ breakpoint_allow_canary_override: str or bool, whether to allow the
240+ individually set breakpoint to override the canary behavior. Any
241+ string except 'True' is interpreted as False.
242+ """
243+ enable_canary = breakpoint_enable_canary in ('True' , True )
244+ allow_canary_override = breakpoint_allow_canary_override in ('True' , True )
245+ self ._canary_mode = _CANARY_MODE_MAP [enable_canary , allow_canary_override ]
246+
221247 def Start (self ):
222248 """Starts the worker thread."""
223249 self ._shutdown = False
@@ -327,8 +353,11 @@ def _RegisterDebuggee(self, service):
327353 self ._project_number = project_number or self ._project_number
328354
329355 self ._debuggee_id = response ['debuggee' ]['id' ]
330- native .LogInfo ('Debuggee registered successfully, ID: %s' % (
331- self ._debuggee_id ))
356+ self ._agent_id = response ['agentId' ]
357+ native .LogInfo (
358+ 'Debuggee registered successfully, ID: %s, agent ID: %s, '
359+ 'canary mode: %s' % (self ._debuggee_id , self ._agent_id ,
360+ response ['debuggee' ].get ('canaryMode' )))
332361 self .register_backoff .Succeeded ()
333362 return (False , 0 ) # Proceed immediately to list active breakpoints.
334363 except BaseException :
@@ -355,7 +384,9 @@ def _ListActiveBreakpoints(self, service):
355384 """
356385 try :
357386 response = service .debuggees ().breakpoints ().list (
358- debuggeeId = self ._debuggee_id , waitToken = self ._wait_token ,
387+ debuggeeId = self ._debuggee_id ,
388+ agentId = self ._agent_id ,
389+ waitToken = self ._wait_token ,
359390 successOnTimeout = True ).execute ()
360391 if not response .get ('waitExpired' ):
361392 self ._wait_token = response .get ('nextWaitToken' )
@@ -469,6 +500,7 @@ def _GetDebuggee(self):
469500 'description' : self ._GetDebuggeeDescription (),
470501 'labels' : self ._debuggee_labels ,
471502 'agentVersion' : agent_version ,
503+ 'canaryMode' : self ._canary_mode ,
472504 }
473505
474506 source_context = self ._ReadAppJsonFile ('source-context.json' )
0 commit comments