diff options
author | Simon Westphahl <simon.westphahl@bmw.de> | 2022-09-19 14:05:43 +0200 |
---|---|---|
committer | Simon Westphahl <simon.westphahl@bmw.de> | 2022-09-19 14:52:26 +0200 |
commit | 7d3b186b3d71e3f311bb70cb4cff12785ccca412 (patch) | |
tree | 905e6f24e6ae8e9cb6ce9b465554b2983f2592d2 | |
parent | 937e25432fa19eff4c2728133568a6831dd7927e (diff) | |
download | zuul-7d3b186b3d71e3f311bb70cb4cff12785ccca412.tar.gz |
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
-rw-r--r-- | zuul/lib/tracing.py | 4 | ||||
-rw-r--r-- | zuul/manager/__init__.py | 4 | ||||
-rw-r--r-- | zuul/model.py | 31 |
3 files changed, 26 insertions, 13 deletions
diff --git a/zuul/lib/tracing.py b/zuul/lib/tracing.py index 42b2681f3..94a78c5ad 100644 --- a/zuul/lib/tracing.py +++ b/zuul/lib/tracing.py @@ -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', {}) diff --git a/zuul/manager/__init__.py b/zuul/manager/__init__.py index cc7735728..ab83afc3d 100644 --- a/zuul/manager/__init__.py +++ b/zuul/manager/__init__.py @@ -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. diff --git a/zuul/model.py b/zuul/model.py index c0d5e4e0c..9b4496ece 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -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): |