Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect Zipkin spans for v2 engine #7342

Add integration test

  • Loading branch information...
cattibrie committed Mar 15, 2019
commit 070d4990ef98c49b0606062578e622067124c2d5
@@ -151,8 +151,8 @@ def executing(self):
metrics = self._scheduler.metrics()
if self._scheduler.metrics_have_engine_workunits():
engine_workunits = self._scheduler.engine_workunits()
engine_workunits = self._scheduler.engine_workunits()
if engine_workunits:

@@ -174,8 +174,9 @@ def prefork(self, options, options_bootstrapper):
if graph_len > 0:
self._logger.debug('graph len was {}, waiting for initial watchman event'.format(graph_len))

session = self._graph_helper.new_session(options.for_global_scope().v2_ui)
v2_ui = options.for_global_scope().v2_ui
zipkin_trace_v2 = options.for_scope('reporting').zipkin_trace_v2
session = self._graph_helper.new_session(zipkin_trace_v2, v2_ui)
if options.for_global_scope().loop:
return session, self._prefork_loop(session, options, options_bootstrapper)
@@ -63,7 +63,7 @@ def mk_scheduler(self,
return scheduler.new_session()
return scheduler.new_session(zipkin_trace_v2=False)

def context_with_scheduler(self, scheduler, *args, **kwargs):
return self.context(*args, scheduler=scheduler, **kwargs)
@@ -214,9 +214,27 @@ def test_get_type_match_failure(self):
self.scheduler.product_request(A, [Params(TypeCheckFailWrapper(A()))])

def test_trace_includes_rule_exception_traceback(self):
<<<<<<< Updated upstream
This conversation was marked as resolved by Eric-Arellano

This comment has been minimized.

Copy link

cosmicexplorer Mar 15, 2019


You'll probably want to remove these conflict markers! Does there need to be any change here?

This comment has been minimized.

Copy link

cattibrie Mar 18, 2019

Author Contributor

Danny, thank you! This is not my change.

# Execute a request that will trigger the nested raise, and then directly inspect its trace.
request = self.scheduler.execution_request([A], [B()])
rules = [

scheduler = create_scheduler(rules)
request = scheduler._native.new_execution_request()
subject = B()
scheduler.add_root_selection(request, subject, A)
session = scheduler.new_session(zipkin_trace_v2=False)
scheduler._run_and_return_roots(session._session, request)

trace = '\n'.join(scheduler.graph_trace(request))
# NB removing location info to make trace repeatable
trace = remove_locations_from_traceback(trace)
>>>>>>> Stashed changes

trace = remove_locations_from_traceback('\n'.join(self.scheduler.trace(request)))
assert_equal_with_printing(self, dedent('''
@@ -237,6 +237,27 @@ def test_zipkin_reporter_with_zero_sample_rate(self):
num_of_traces = len(ZipkinHandler.traces)
self.assertEqual(num_of_traces, 0)

def test_zipkin_reporter_for_v2_engine(self):
ZipkinHandler = zipkin_handler()
with http_server(ZipkinHandler) as port:
endpoint = "http://localhost:{}".format(port)
command = [

pants_run = self.run_pants(command)

num_of_traces = len(ZipkinHandler.traces)
self.assertEqual(num_of_traces, 1)

This comment has been minimized.

Copy link

cosmicexplorer Mar 19, 2019


There's a method assert_single_element() I added a while ago for cases like this:

def assert_single_element(iterable):
"""Get the single element of `iterable`, or raise an error.

Here, you could write:

from pants.util.collections import assert_single_element
# ...
   trace = assert_single_element(ZipkinHandler.traces)

which would raise an exception if there was not exactly 1 trace.

You do not need to use it at all, I have just found it useful to make it more clear what is being tested.

trace = ZipkinHandler.traces[-1]
self.assertTrue(any("Scandir" in span['name'] for span in trace),
"There is no span that contains 'Scandir' in it's name. The trace: {}".format(trace))

def find_spans_by_name(trace, name):
return [span for span in trace if span['name'] == name]
@@ -399,7 +399,7 @@ def _init_engine(cls):
cls._scheduler = graph_session.scheduler_session
cls._build_graph, cls._address_mapper = graph_session.create_build_graph(
TargetRoots([]), cls._build_root()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.