Skip to content

Commit da3bb14

Browse files
jasonborgcopybara-github
authored andcommitted
Updated the python agent to not override any pre existing labels in the breakpoint if there was a conflict with a label it wanted to add.
Expected agent behaviour with respect to pre existing breakpoint labels is that they are not removed or overriden by the agent. PiperOrigin-RevId: 242004674 Change-Id: I218c615b715ae74ea958f1e8d509a7e07668378f
1 parent 2f30fe8 commit da3bb14

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/googleclouddebugger/capture_collector.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def _CaptureEnvironmentLabels(self):
642642

643643
if callable(breakpoint_labels_collector):
644644
for (key, value) in six.iteritems(breakpoint_labels_collector()):
645-
self.breakpoint['labels'][key] = value
645+
self._StoreLabel(key, value)
646646

647647
def _CaptureRequestLogId(self):
648648
"""Captures the request log id if possible.
@@ -654,15 +654,28 @@ def _CaptureRequestLogId(self):
654654
request_log_id = request_log_id_collector()
655655
if request_log_id:
656656
# We have a request_log_id, save it into the breakpoint labels
657-
self.breakpoint['labels'][
658-
labels.Breakpoint.REQUEST_LOG_ID] = request_log_id
657+
self._StoreLabel(labels.Breakpoint.REQUEST_LOG_ID, request_log_id)
659658

660659
def _CaptureUserId(self):
661660
"""Captures the user id of the end user, if possible."""
662661
user_kind, user_id = user_id_collector()
663662
if user_kind and user_id:
664663
self.breakpoint['evaluatedUserId'] = {'kind': user_kind, 'id': user_id}
665664

665+
def _StoreLabel(self, name, value):
666+
"""Stores the specified label in the breakpoint's labels.
667+
668+
In the event of a duplicate label, favour the pre-existing labels. This
669+
generally should not be an issue as the pre-existing client label names are
670+
chosen with care and there should be no conflicts.
671+
672+
Args:
673+
name: The name of the label to be stored.
674+
value: The value of the label to be stored.
675+
"""
676+
if name not in self.breakpoint['labels']:
677+
self.breakpoint['labels'][name] = value
678+
666679

667680
class LogCollector(object):
668681
"""Captures minimal application snapshot and logs it to application log.

0 commit comments

Comments
 (0)