Create link to previous buildset span

Create a link to the previous buildset span on gate reset. To make this
work we'll start the buildset span when the buildset is created instead
of only when we set the configuration.

This change also adds the `is_remote` flag of the span context of
related links. This is required for creating a `SpanContext` in order to
deserialize the links.

Change-Id: If3a3a83739c1472659d71d05dcf67f84ddce4247
This commit is contained in:
Simon Westphahl
2022-09-19 14:05:43 +02:00
parent 937e25432f
commit 7d3b186b3d
3 changed files with 26 additions and 13 deletions

View File

@@ -62,6 +62,7 @@ def _formatAttributes(attrs):
def getSpanInfo(span, include_attributes=False):
"""Return a dict for use in serializing a Span."""
links = [{'context': _formatContext(l.context),
'is_remote': l.context.is_remote,
'attributes': _formatAttributes(l.attributes)}
for l in span.links]
attrs = _formatAttributes(span.attributes)
@@ -113,7 +114,8 @@ def restoreSpan(span_info, is_remote=True):
for link_info in span_info.get('links', []):
link_context = trace.SpanContext(
link_info['context']['trace_id'],
link_info['context']['span_id'])
link_info['context']['span_id'],
is_remote=link_info['is_remote'])
link = trace.Link(link_context, link_info['attributes'])
links.append(link)
attributes = span_info.get('attributes', {})

View File

@@ -1359,9 +1359,7 @@ class PipelineManager(metaclass=ABCMeta):
# isn't already set.
tpc = tenant.project_configs.get(item.change.project.canonical_name)
if not build_set.ref:
with trace.use_span(tracing.restoreSpan(item.span_info)):
span_info = tracing.startSavedSpan('BuildSet')
build_set.setConfiguration(self.current_context, span_info)
build_set.setConfiguration(self.current_context)
# Next, if a change ahead has a broken config, then so does
# this one. Record that and don't do anything else.

View File

@@ -4163,7 +4163,7 @@ class BuildSet(zkobject.ZKObject):
len(self.builds),
self.getStateName(self.merge_state))
def setConfiguration(self, context, span_info):
def setConfiguration(self, context):
with self.activeContext(context):
# The change isn't enqueued until after it's created
# so we don't know what the other changes ahead will be
@@ -4183,7 +4183,6 @@ class BuildSet(zkobject.ZKObject):
self.merger_items = [i.makeMergerItem() for i in items]
self.configured = True
self.configured_time = time.time()
self.span_info = span_info
def _toChangeDict(self, item):
# Inject bundle_id to dict if available, this can be used to decide
@@ -4385,8 +4384,12 @@ class QueueItem(zkobject.ZKObject):
obj._save(context, data, create=True)
files_state = (BuildSet.COMPLETE if obj.change.files is not None
else BuildSet.NEW)
obj.updateAttributes(context, current_build_set=BuildSet.new(
context, item=obj, files_state=files_state))
with trace.use_span(tracing.restoreSpan(obj.span_info)):
buildset_span_info = tracing.startSavedSpan("BuildSet")
obj.updateAttributes(context, current_build_set=BuildSet.new(
context, item=obj, files_state=files_state,
span_info=buildset_span_info))
return obj
def getPath(self):
@@ -4496,11 +4499,21 @@ class QueueItem(zkobject.ZKObject):
old_build_set = self.current_build_set
files_state = (BuildSet.COMPLETE if self.change.files is not None
else BuildSet.NEW)
self.updateAttributes(
context,
current_build_set=BuildSet.new(context, item=self,
files_state=files_state),
layout_uuid=None)
with trace.use_span(tracing.restoreSpan(self.span_info)):
old_buildset_span = tracing.restoreSpan(old_build_set.span_info)
link = trace.Link(
old_buildset_span.get_span_context(),
attributes={"previous_buildset": old_build_set.uuid})
buildset_span_info = tracing.startSavedSpan(
"BuildSet", links=[link])
self.updateAttributes(
context,
current_build_set=BuildSet.new(context, item=self,
files_state=files_state,
span_info=buildset_span_info),
layout_uuid=None)
old_build_set.delete(context)
def addBuild(self, build):