Exemple #1
0
def session_from_config(config: SessionConfig) -> Session:
    """
    Construct a whylogs session from a `SessionConfig`
    """
    writers = list(map(lambda x: writer_from_config(x), config.writers))
    return Session(config.project, config.pipeline, writers, config.verbose,
                   config.with_rotation_time, config.cache)
Exemple #2
0
def test_no_log_rotation(tmpdir):
    output_path = tmpdir.mkdir("whylogs")
    shutil.rmtree(output_path, ignore_errors=True)
    writer_config = WriterConfig("local", ["protobuf"], output_path.realpath())
    yaml_data = writer_config.to_yaml()
    basewriter = writer_from_config(WriterConfig.from_yaml(yaml_data))
    l = Logger(session_id="", dataset_name="testing", writers=[basewriter], dataset_timestamp=datetime.datetime.now(tz=timezone.utc), with_rotation_time=None)
    l.log({"quick_test": 3})
    l.flush()
Exemple #3
0
def test_write_template_path():
    data_time = time.from_utc_ms(9999)
    session_time = time.from_utc_ms(88888)
    path_template = "$name-$session_timestamp-$dataset_timestamp-$session_id"
    writer_config = WriterConfig("local", ["protobuf", "flat"], "output", path_template, "dataset-profile-$name")
    writer = writer_from_config(writer_config)
    dp = DatasetProfile("name", data_time, session_time, session_id="session")
    assert writer.path_suffix(dp) == "name-88888-9999-session"
    assert writer.file_name(dp, ".txt") == "dataset-profile-name.txt"
Exemple #4
0
def session_from_config(config: SessionConfig) -> Session:
    """
    Construct a whylogs session from a `SessionConfig`
    """
    writers = list(map(lambda x: writer_from_config(x), config.writers))
    metadata_writer = None
    if config.metadata:
        metadata_writer = metadata_from_config(config.metadata)
    return Session(
        config.project,
        config.pipeline,
        writers,
        metadata_writer,
        config.verbose,
        config.with_rotation_time,
        config.cache_size,
        report_progress=config.report_progress,
    )
Exemple #5
0
def session_from_config(config: SessionConfig = None,
                        config_path: Optional[str] = "") -> Session:
    """
    Construct a whylogs session from a `SessionConfig` or from a config_path
    """

    if config is None:
        config = load_config(config_path)

    writers = list(map(lambda x: writer_from_config(x), config.writers))
    metadata_writer = None
    if config.metadata:
        metadata_writer = metadata_from_config(config.metadata)
    return Session(
        config.project,
        config.pipeline,
        writers,
        metadata_writer,
        config.verbose,
        config.with_rotation_time,
        config.cache_size,
        report_progress=config.report_progress,
    )
Exemple #6
0
def test_non_valid_type(tmpdir):

    config = WriterConfig(type="blob", formats=["json"], output_path=tmpdir)
    with pytest.raises(ValueError):
        writer_from_config(config)
Exemple #7
0
def session_from_config(config: SessionConfig) -> Session:
    """
    Construct a WhyLogs session from a `SessionConfig`
    """
    writers = list(map(lambda x: writer_from_config(x), config.writers))
    return Session(config.project, config.pipeline, writers, config.verbose)