def test_logging_endpoint(self): # TODO: remove True with SERVER-48156. if not config.EVERGREEN_TASK_ID or True: print( "Testing jasper logging endpoint should only be tested in Evergreen, skipping..." ) return import grpc from google.protobuf import empty_pb2 runner = run.TestRunner("") curator_path = runner._get_jasper_reqs() import jasper.jasper_pb2 as pb import jasper.jasper_pb2_grpc as rpc jasper_port = 8000 jasper_conn_str = "localhost:%d" % jasper_port jasper_command = [ curator_path, "jasper", "service", "run", "rpc", "--port", str(jasper_port) ] jasper_service = subprocess.Popen(jasper_command) time.sleep(1) stub = rpc.JasperProcessManagerStub( grpc.insecure_channel(jasper_conn_str)) level = pb.LogLevel(threshold=30, default=30) buildlogger_info = pb.BuildloggerV3Info( project=config.EVERGREEN_PROJECT_NAME, version=config.EVERGREEN_VERSION_ID, variant=config.EVERGREEN_VARIANT_NAME, task_name=config.EVERGREEN_TASK_NAME, task_id=config.EVERGREEN_TASK_ID, test_name="test-jasper-proto", execution=config.EVERGREEN_EXECUTION, base_address="cedar.mongodb.com", rpc_port="7070", username=os.getenv("CEDAR_USER"), api_key=os.getenv("CEDAR_API_KEY")) buildlogger_options = pb.BuildloggerV3Options( buildloggerv3=buildlogger_info, level=level) logger_config = pb.LoggerConfig() logger_config.buildloggerv3.CopyFrom(buildlogger_options) create_options = pb.CreateOptions( args=["ls"], working_directory='.', output=pb.OutputOptions(loggers=[logger_config])) res = stub.Create(request=create_options) self.assertEqual(0, res.exit_code) res = stub.Close(empty_pb2.Empty()) self.assertTrue(res.success) jasper_service.terminate()
def get_logger_config(group_id=None, test_id=None, process_name=None, prefix=None, trial=None): # pylint: disable=too-many-locals """Return the jasper logger config.""" import jasper.jasper_pb2 as pb username = os.getenv("CEDAR_USERNAME", default="") api_key = os.getenv("CEDAR_API_KEY", default="") test_id = utils.default_if_none(test_id, "") process_name = utils.default_if_none(process_name, "") prefix = utils.default_if_none(prefix, "") trial = utils.default_if_none(trial, 0) logger_config = pb.LoggerConfig() log_level = pb.LogLevel(threshold=30, default=30) log_format = pb.LogFormat.Value("LOGFORMATPLAIN") if config.EVERGREEN_TASK_ID and group_id is not None: buildlogger_info = pb.BuildloggerV3Info( project=config.EVERGREEN_PROJECT_NAME, version=config.EVERGREEN_VERSION_ID, variant=config.EVERGREEN_VARIANT_NAME, task_name=config.EVERGREEN_TASK_NAME, task_id=config.EVERGREEN_TASK_ID, execution=config.EVERGREEN_EXECUTION, test_name=str(test_id), proc_name=process_name, trial=trial, format=log_format, tags=[str(group_id)], prefix=prefix, base_address=config.CEDAR_URL, rpc_port=config.CEDAR_RPC_PORT, username=username, api_key=api_key) buildlogger_options = pb.BuildloggerV3Options( buildloggerv3=buildlogger_info, level=log_level) logger_config.buildloggerv3.CopyFrom(buildlogger_options) else: buffered = pb.BufferOptions() base_opts = pb.BaseOptions(format=log_format, level=log_level, buffer=buffered) log_opts = pb.DefaultLoggerOptions(prefix=prefix, base=base_opts) logger_config.default.CopyFrom(log_opts) return logger_config