def setUp(self): configurator = Configurator() configurator.add_route("example", "/example", request_method="GET") configurator.add_route("trace_context", "/trace_context", request_method="GET") configurator.add_view(example_application, route_name="example", renderer="json") configurator.add_view(local_tracing_within_context, route_name="trace_context", renderer="json") self.observer = mock.Mock(spec=BaseplateObserver) self.server_observer = mock.Mock(spec=ServerSpanObserver) def _register_mock(context, server_span): server_span.register(self.server_observer) self.observer.on_server_span_created.side_effect = _register_mock self.baseplate = Baseplate() self.baseplate.register(self.observer) self.baseplate_configurator = BaseplateConfigurator( self.baseplate, trust_trace_headers=True, ) configurator.include(self.baseplate_configurator.includeme) app = configurator.make_wsgi_app() self.test_app = webtest.TestApp(app)
def make_wsgi_app(app_config): cfg = config.parse_config(app_config) signer = MessageSigner(cfg.ads_tracking.click_secret) metrics_client = make_metrics_client(app_config) baseplate = Baseplate() baseplate.configure_logging() baseplate.configure_metrics(metrics_client) baseplate.add_to_context("events", events.EventQueue("production")) baseplate.add_to_context("events_test", events.EventQueue("test")) configurator = Configurator(settings=app_config) baseplate_configurator = BaseplateConfigurator(baseplate) configurator.include(baseplate_configurator.includeme) controller = TrackingService(signer=signer, ) configurator.add_route("health", "/health", request_method="GET") configurator.add_view(controller.is_healthy, route_name="health", renderer="json") configurator.add_route("click", "/click", request_method="GET") configurator.add_view(controller.track_click, route_name="click", renderer="json") return configurator.make_wsgi_app()
def setUp(self): thread_patch = mock.patch("threading.Thread", autospec=True) thread_patch.start() self.addCleanup(thread_patch.stop) configurator = Configurator() configurator.add_route("example", "/example", request_method="GET") configurator.add_view(example_application, route_name="example", renderer="json") configurator.add_route("local_test", "/local_test", request_method="GET") configurator.add_view(local_parent_trace_within_context, route_name="local_test", renderer="json") self.client = make_client("test-service") self.observer = TraceBaseplateObserver(self.client) self.baseplate = Baseplate() self.baseplate.register(self.observer) self.baseplate_configurator = BaseplateConfigurator( self.baseplate, trust_trace_headers=True) configurator.include(self.baseplate_configurator.includeme) app = configurator.make_wsgi_app() self.local_span_ids = [] self.local_span_observers = [] self.test_app = webtest.TestApp(app)
def setUp(self): configurator = Configurator() configurator.add_route("example", "/example", request_method="GET") configurator.add_route("trace_context", "/trace_context", request_method="GET") configurator.add_view( example_application, route_name="example", renderer="json") configurator.add_view( local_tracing_within_context, route_name="trace_context", renderer="json") configurator.add_view( render_exception_view, context=ControlFlowException, renderer="json", ) configurator.add_view( render_bad_exception_view, context=ControlFlowException2, renderer="json", ) mock_filewatcher = mock.Mock(spec=FileWatcher) mock_filewatcher.get_data.return_value = { "secrets": { "jwt/authentication/secret": { "type": "simple", "value": self.TOKEN_SECRET, }, }, "vault": { "token": "test", "url": "http://vault.example.com:8200/", } } secrets = store.SecretsStore("/secrets") secrets._filewatcher = mock_filewatcher self.observer = mock.Mock(spec=BaseplateObserver) self.server_observer = mock.Mock(spec=ServerSpanObserver) def _register_mock(context, server_span): server_span.register(self.server_observer) self.observer.on_server_span_created.side_effect = _register_mock self.baseplate = Baseplate() self.baseplate.register(self.observer) self.baseplate_configurator = BaseplateConfigurator( self.baseplate, trust_trace_headers=True, auth_factory=AuthenticationContextFactory(secrets), ) configurator.include(self.baseplate_configurator.includeme) self.context_init_event_subscriber = mock.Mock() configurator.add_subscriber(self.context_init_event_subscriber, ServerSpanInitialized) app = configurator.make_wsgi_app() self.test_app = webtest.TestApp(app)
def make_wsgi_app(app_config): cfg = config.parse_config( app_config, { "activity": { "endpoint": config.Endpoint, }, "tracing": { "endpoint": config.Optional(config.Endpoint), "service_name": config.String, }, }) metrics_client = make_metrics_client(app_config) pool = ThriftConnectionPool(cfg.activity.endpoint) baseplate = Baseplate() baseplate.configure_logging() baseplate.configure_metrics(metrics_client) baseplate.configure_tracing( cfg.tracing.service_name, cfg.tracing.endpoint, ) baseplate.add_to_context( "activity", ThriftContextFactory(pool, ActivityService.Client)) configurator = Configurator(settings=app_config) baseplate_configurator = BaseplateConfigurator(baseplate) configurator.include(baseplate_configurator.includeme) controller = ActivityGateway() configurator.add_route("health", "/health", request_method="GET") configurator.add_view(controller.is_healthy, route_name="health", renderer="json") configurator.add_route("pixel", "/{context_id:[A-Za-z0-9_]{,40}}.png", request_method="GET") configurator.add_view(controller.pixel, route_name="pixel") return configurator.make_wsgi_app()
def setUp(self): configurator = Configurator() configurator.add_route("example", "/example", request_method="GET") configurator.add_view(example_application, route_name="example", renderer="json") self.observer = TraceBaseplateObserver('test-service') self.baseplate = Baseplate() self.baseplate.register(self.observer) self.baseplate_configurator = BaseplateConfigurator( self.baseplate, trust_trace_headers=True, ) configurator.include(self.baseplate_configurator.includeme) app = configurator.make_wsgi_app() self.test_app = webtest.TestApp(app)
def make_wsgi_app(app_config): cfg = config.parse_config(app_config, { # TODO: add your config spec here }) metrics_client = make_metrics_client(app_config) baseplate = Baseplate() baseplate.configure_logging() baseplate.configure_metrics(metrics_client) configurator = Configurator(settings=app_config) baseplate_configurator = BaseplateConfigurator(baseplate) configurator.include(baseplate_configurator.includeme) controller = {{ cookiecutter.service_name }}() configurator.add_route("health", "/health", request_method="GET") configurator.add_view( controller.is_healthy, route_name="health", renderer="json") # TODO: add more routes and views here return configurator.make_wsgi_app()