forked from twitter/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for trace propagation from Pants callers (pantsbuild#7177)
Follow up for pantsbuild#7125: Add flags "--reporting-zipkin-trace-id", "--reporting-zipkin-parent-id" to propagate a trace from systems that invoke Pants.
- Loading branch information
1 parent
5a6ac93
commit f65734e
Showing
5 changed files
with
213 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# coding=utf-8 | ||
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from pants.goal.run_tracker import RunTracker | ||
from pants.reporting.reporting import Reporting | ||
from pants_test.test_base import TestBase | ||
|
||
|
||
class ReportingTest(TestBase): | ||
|
||
# Options for Zipkin tracing | ||
trace_id = "aaaaaaaaaaaaaaaa" | ||
parent_id = "ffffffffffffffff" | ||
zipkin_endpoint = 'http://localhost:9411/api/v1/spans' | ||
|
||
def test_raise_no_zipkin_endpoint_set(self): | ||
|
||
options = {'reporting': {'zipkin_trace_id': self.trace_id, 'zipkin_parent_id': self.parent_id}} | ||
context = self.context(for_subsystems=[RunTracker, Reporting], options=options) | ||
run_tracker = RunTracker.global_instance() | ||
reporting = Reporting.global_instance() | ||
|
||
with self.assertRaises(ValueError) as result: | ||
reporting.initialize(run_tracker, context.options) | ||
|
||
self.assertTrue( | ||
"The zipkin-endpoint flag must be set if zipkin-trace-id and zipkin-parent-id flags are given." | ||
in str(result.exception) | ||
) | ||
|
||
def test_raise_no_parent_id_set(self): | ||
|
||
options = {'reporting': {'zipkin_trace_id': self.trace_id, 'zipkin_endpoint': self.zipkin_endpoint}} | ||
context = self.context(for_subsystems=[RunTracker, Reporting], options=options) | ||
|
||
run_tracker = RunTracker.global_instance() | ||
reporting = Reporting.global_instance() | ||
|
||
with self.assertRaises(ValueError) as result: | ||
reporting.initialize(run_tracker, context.options) | ||
|
||
self.assertTrue( | ||
"Flags zipkin-trace-id and zipkin-parent-id must both either be set or not set." | ||
in str(result.exception) | ||
) | ||
|
||
def test_raise_no_trace_id_set(self): | ||
|
||
options = {'reporting': {'zipkin_parent_id': self.parent_id, 'zipkin_endpoint': self.zipkin_endpoint}} | ||
context = self.context(for_subsystems=[RunTracker, Reporting], options=options) | ||
|
||
run_tracker = RunTracker.global_instance() | ||
reporting = Reporting.global_instance() | ||
|
||
with self.assertRaises(ValueError) as result: | ||
reporting.initialize(run_tracker, context.options) | ||
|
||
self.assertTrue( | ||
"Flags zipkin-trace-id and zipkin-parent-id must both either be set or not set." | ||
in str(result.exception) | ||
) | ||
|
||
def test_raise_if_no_trace_id_and_zipkin_endpoint_set(self): | ||
|
||
options = {'reporting': {'zipkin_parent_id': self.parent_id}} | ||
context = self.context(for_subsystems=[RunTracker, Reporting], options=options) | ||
|
||
run_tracker = RunTracker.global_instance() | ||
reporting = Reporting.global_instance() | ||
|
||
with self.assertRaises(ValueError) as result: | ||
reporting.initialize(run_tracker, context.options) | ||
|
||
self.assertTrue( | ||
"Flags zipkin-trace-id and zipkin-parent-id must both either be set or not set." | ||
in str(result.exception) | ||
) | ||
|
||
def test_raise_if_no_parent_id_and_zipkin_endpoint_set(self): | ||
|
||
options = {'reporting': {'zipkin_trace_id': self.trace_id}} | ||
context = self.context(for_subsystems=[RunTracker, Reporting], options=options) | ||
|
||
run_tracker = RunTracker.global_instance() | ||
reporting = Reporting.global_instance() | ||
|
||
with self.assertRaises(ValueError) as result: | ||
reporting.initialize(run_tracker, context.options) | ||
|
||
self.assertTrue( | ||
"Flags zipkin-trace-id and zipkin-parent-id must both either be set or not set." | ||
in str(result.exception) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters