async def test_events_schema( monkeypatch: MonkeyPatch, default_agent: Agent, config_path: Text ): # this allows us to patch the printing part used in debug mode to collect the # reported events monkeypatch.setenv("RASA_TELEMETRY_DEBUG", "true") monkeypatch.setenv("RASA_TELEMETRY_ENABLED", "true") mock = Mock() monkeypatch.setattr(telemetry, "print_telemetry_event", mock) with open(TELEMETRY_EVENTS_JSON) as f: schemas = json.load(f)["events"] initial = asyncio.all_tasks() # Generate all known backend telemetry events, and then use events.json to # validate their schema. training_data = TrainingDataImporter.load_from_config(config_path) with telemetry.track_model_training(training_data, "rasa"): await asyncio.sleep(1) telemetry.track_telemetry_disabled() telemetry.track_data_split(0.5, "nlu") telemetry.track_validate_files(True) telemetry.track_data_convert("yaml", "nlu") telemetry.track_tracker_export(5, TrackerStore(domain=None), EventBroker()) telemetry.track_interactive_learning_start(True, False) telemetry.track_server_start([CmdlineInput()], None, None, 42, True) telemetry.track_project_init("tests/") telemetry.track_shell_started("nlu") telemetry.track_rasa_x_local() telemetry.track_visualization() telemetry.track_core_model_test(5, True, default_agent) telemetry.track_nlu_model_test(TrainingData()) pending = asyncio.all_tasks() - initial await asyncio.gather(*pending) assert mock.call_count == 15 for args, _ in mock.call_args_list: event = args[0] # `metrics_id` automatically gets added to all event but is # not part of the schema so we need to remove it before validation del event["properties"]["metrics_id"] jsonschema.validate( instance=event["properties"], schema=schemas[event["event"]] )
def export_trackers(args: argparse.Namespace) -> None: """Export events for a connected tracker store using an event broker. Args: args: Command-line arguments to process. """ _assert_max_timestamp_is_greater_than_min_timestamp(args) endpoints = rasa.core.utils.read_endpoints_from_path(args.endpoints) tracker_store = _get_tracker_store(endpoints) event_broker = _get_event_broker(endpoints) _prepare_event_broker(event_broker) requested_conversation_ids = _get_requested_conversation_ids( args.conversation_ids) from rasa.core.exporter import Exporter exporter = Exporter( tracker_store, event_broker, args.endpoints, requested_conversation_ids, args.minimum_timestamp, args.maximum_timestamp, ) try: published_events = exporter.publish_events() telemetry.track_tracker_export(published_events, tracker_store, event_broker) rasa.shared.utils.cli.print_success( f"Done! Successfully published {published_events} events 🎉") except PublishingError as e: command = _get_continuation_command(exporter, e.timestamp) rasa.shared.utils.cli.print_error_and_exit( f"Encountered error while publishing event with timestamp '{e}'. To " f"continue where I left off, run the following command:" f"\n\n\t{command}\n\nExiting.") except RasaException as e: rasa.shared.utils.cli.print_error_and_exit(str(e))