Ejemplo n.º 1
0
def test_invalid_dashboard_raises_error():
    with pytest.raises(ConfigurationError) as ex:
        ElasticlogsKibanaSource(track=StaticTrack(),
                                params={
                                    "dashboard": "unknown",
                                    "index_pattern": "elasticlogs*"
                                })

    assert "Unknown dashboard [unknown]. Must be one of ['traffic', 'content_issues', 'discover']." == str(
        ex.value)
Ejemplo n.º 2
0
def test_create_content_issues_dashboard(time):
    time.return_value = 5000

    param_source = ElasticlogsKibanaSource(
        track=StaticTrack(),
        params={
            "dashboard": "content_issues",
            "index_pattern": "elasticlogs-*"
        },
        utcnow=lambda: datetime(year=2019, month=11, day=11))
    response = param_source.params()

    assert response == load("content_issues")
Ejemplo n.º 3
0
def test_create_discover_random_window_length(time, fieldstats):
    time.return_value = 5000

    param_source = ElasticlogsKibanaSource(
        track=StaticTrack(),
        params={
            "dashboard": "discover",
            "index_pattern": "elasticlogs-*",
            "window_length": "random",
            "seed": 1573430400000
        },
        utcnow=lambda: datetime(year=2019, month=11, day=11))
    param_source.partition(0, 1)
    response = param_source.params()

    assert response == load("discover-random-window-length")
def test_create_content_issues_dashboard_with_max_concurrent_shard_requests(
        time):
    time.return_value = 5000

    param_source = ElasticlogsKibanaSource(
        track=StaticTrack(),
        params={
            "dashboard": "content_issues",
            "index_pattern": "elasticlogs-*",
            "max_concurrent_shard_requests": 13,
        },
        utcnow=lambda: datetime(year=2019, month=11, day=11))
    response = param_source.params()

    assert "max_concurrent_shard_requests" in response["params"].keys()
    assert response["params"]["max_concurrent_shard_requests"] == 13
Ejemplo n.º 5
0
def test_generates_a_bulk_that_ends_prematurely():
    generator = StaticEventGenerator(index="elasticlogs",
                                     type="_doc",
                                     doc='{"loc": [-0.14851,51.5250]}',
                                     at_most=5)
    param_source = ElasticlogsBulkSource(track=StaticTrack(),
                                         params={
                                             "index": "elasticlogs",
                                             "bulk-size": 10
                                         },
                                         random_event=generator)
    client_param_source = param_source.partition(partition_index=0,
                                                 total_partitions=1)

    generated_params = client_param_source.params()
    # the actual bulk size does not matter but instead that the generator stopped prematurely after 5 items
    assert len(generated_params["body"].split("\n")) == 10
    assert generated_params["action-metadata-present"] is True
    assert generated_params["bulk-size"] == 5
Ejemplo n.º 6
0
def test_generates_a_complete_bulk():
    expected_bulk_size = 10

    generator = StaticEventGenerator(
        index="elasticlogs",
        type="_doc",
        doc='{"location": [-0.1485188,51.5250666]}')
    param_source = ElasticlogsBulkSource(track=StaticTrack(),
                                         params={
                                             "index": "elasticlogs",
                                             "bulk-size": expected_bulk_size
                                         },
                                         random_event=generator)
    client_param_source = param_source.partition(partition_index=0,
                                                 total_partitions=1)

    generated_params = client_param_source.params()
    assert len(generated_params["body"].split("\n")) == 2 * expected_bulk_size
    assert generated_params["action-metadata-present"] is True
    assert generated_params["bulk-size"] == expected_bulk_size
Ejemplo n.º 7
0
def test_index_pattern_is_mandatory():
    with pytest.raises(KeyError) as ex:
        ElasticlogsKibanaSource(track=StaticTrack(),
                                params={"dashboard": "traffic"})

    assert "'index_pattern'" == str(ex.value)
Ejemplo n.º 8
0
def test_dashboard_is_mandatory():
    with pytest.raises(KeyError) as ex:
        ElasticlogsKibanaSource(track=StaticTrack(),
                                params={"index_pattern": "elasticlogs*"})

    assert "'dashboard'" == str(ex.value)