def test_dashboard_create_with_filters_source_with_missing_property_and_value_failure(session, chart):
    with pytest.raises(ValueError):
        aws_src = FilterSource()

        dashboard_filter = DashboardFilters() \
            .with_sources(aws_src)

        Dashboard(session=session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_time_missing_start_and_end_time_failure(session, chart):
    with pytest.raises(ValueError):
        time = FilterTime()

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_time_start_unexpected_last_character_failure(chart):
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start("-1z")\
            .with_end("Now")

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_time_start_and_end_time_as_unsupported_data_type_failure(session, chart):
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start(True)\
            .with_end(False)

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_time_start_and_end_time_as_different_data_types_failure(session, chart):
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start(1523808000000)\
            .with_end("Now")

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_time_start_time_is_not_less_than_end_time_failure(session, chart):
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start(1523894400000)\
            .with_end(1523808000000)

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_with_unexpected_data_type_failure(session, chart):
    with pytest.raises(ValueError):
        app_var = FilterVariable().with_alias('app') \
            .with_is_required("THIS SHOULD BE BOOLEAN NOT A STRING") \
            .with_value('bar')

        dashboard_filter = DashboardFilters() \
            .with_variables(app_var)

        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
def test_dashboard_create_with_filters_with_missing_property_failure(session, chart):
    with pytest.raises(ValueError):
        app_var = FilterVariable().with_alias('app') \
            .with_is_required(True) \
            .with_value('bar')

        dashboard_filter = DashboardFilters() \
            .with_variables(app_var)

        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
Example #9
0
def test_dashboard_create_with_filters_time_end_time_is_not_Now_failure():
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start("-1h")\
            .with_end("Not Now")

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=global_session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(mk_chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
Example #10
0
def test_dashboard_create_with_filters_source_with_empty_value_failure():
    with pytest.raises(ValueError):
        aws_src = FilterSource() \
            .with_property("aws_region") \
            .with_value("")

        dashboard_filter = DashboardFilters() \
            .with_sources(aws_src)

        Dashboard(session=global_session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(mk_chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_time_start_no_integer_after_negative_sign_failure(session, chart):
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start("-zh")\
            .with_end("Now")

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_time_as_integer_success(sfx_recorder, session, chart):
    time = FilterTime()\
        .with_start(1523721600000)\
        .with_end(1523808000000)

    dashboard_filter = DashboardFilters()\
        .with_time(time)

    with sfx_recorder.use_cassette('dashboard_create_with_filters_time_as_integer_success',
                                      serialize_with='prettyjson'):
        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
def test_dashboard_create_with_filters_source_success(sfx_recorder, session, chart):
    aws_src = FilterSource()\
        .with_property("aws_region")\
        .with_value("us-west-2")

    dashboard_filter = DashboardFilters()\
        .with_sources(aws_src)

    with sfx_recorder.use_cassette('dashboard_create_with_filters_source_success',
                                      serialize_with='prettyjson'):
        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
Example #14
0
def test_dashboard_create_with_filters_time_end_time_is_negative_integer_failure(
):
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start(1523808000000)\
            .with_end(-1523894400000)

        dashboard_filter = DashboardFilters() \
            .with_time(time)

        Dashboard(session=global_session) \
            .with_name('testy mctesterson') \
            .with_api_token('foo') \
            .with_charts(mk_chart('lol')) \
            .with_filters(dashboard_filter) \
            .create()
def test_dashboard_create_with_filters_with_multiple_values_success(sfx_recorder, session, chart):
    app_var = FilterVariable().with_alias('app') \
        .with_property('app') \
        .with_is_required(True) \
        .with_value('bar1', 'bar2')

    dashboard_filter = DashboardFilters() \
        .with_variables(app_var)

    with sfx_recorder.use_cassette('dashboard_create_with_filters_with_multiple_values_success',
                                      serialize_with='prettyjson'):
        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
Example #16
0
def test_dashboard_create_with_filters_time_as_string_success():
    time = FilterTime()\
        .with_start("-1h")\
        .with_end("Now")

    dashboard_filter = DashboardFilters()\
        .with_time(time)

    with global_recorder.use_cassette(
            'dashboard_create_with_filters_time_as_string_success',
            serialize_with='prettyjson'):
        Dashboard(session=global_session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(mk_chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
def test_dashboard_update_existing_dashboard_with_filters_success(sfx_recorder, session, chart):

    app_var = FilterVariable().with_alias('app') \
        .with_property('app') \
        .with_is_required(True) \
        .with_value('bar1', 'bar2')

    dashboard_filter = DashboardFilters() \
        .with_variables(app_var)

    with sfx_recorder.use_cassette('dashboard_update_with_filters_success',
                                      serialize_with='prettyjson'):

        # This Dashboard already exists. So, it will be updated
        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .update()
Example #18
0
def create_pipeline_dashboard(pipeline_name, resources):
    """
    Creates a Dashboard for a Data Pipeline that is defined by a list of AwsResources
    """
    charts = []

    # When defining our Dashboard we could have just called the functions above to create the charts
    # we wanted but instead we've further abstracted by defining AWS Resource Types that can now
    # map to functions.
    for resource in resources:
        if resource.type == AwsResourceType.Lambda:
            charts.extend(
                create_lambda_charts(resource.name, resource.description))
        elif resource.type == AwsResourceType.DynamoDb:
            charts.extend(
                create_dynamodb_charts(resource.name, resource.description))
        elif resource.type == AwsResourceType.DynamoDbWithStream:
            charts.extend(
                create_dynamodb_with_stream_charts(resource.name,
                                                   resource.description))
        elif resource.type == AwsResourceType.SqsQueue:
            charts.extend(
                create_sqs_charts(resource.name, resource.description))
        elif resource.type == AwsResourceType.KinesisStream:
            charts.extend(
                create_kinesis_charts(resource.name, resource.description))
        else:
            raise ValueError("unknown type " + str(resource.type))

    return Dashboard() \
        .with_name(pipeline_name) \
        .with_charts(*charts) \
        .with_filters(
        DashboardFilters() \
            .with_variables(FilterVariable() \
                            .with_property("aws_account_id")
                            .with_alias("aws_account_id")
                            .with_value(aws_account_id)
                            .with_apply_if_exists(True))
            .with_time(FilterTime().with_start("-7d").with_end("Now"))
    )
def test_dashboard_update_with_filters_success(sfx_recorder, session, chart):
    app_var = FilterVariable().with_alias('app') \
        .with_property('app') \
        .with_is_required(True) \
        .with_value('bar')

    env_var = FilterVariable().with_alias('env') \
        .with_property('env') \
        .with_is_required(True) \
        .with_value('prod')

    dashboard_filter = DashboardFilters() \
        .with_variables(app_var, env_var)

    with sfx_recorder.use_cassette('dashboard_update_with_filters_success',
                                      serialize_with='prettyjson'):

        # This Dashboard does not exist. So, a new dashboard should be created
        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .update()
Example #20
0
from signal_analog.filters import DashboardFilters, FilterVariable, FilterSource, FilterTime
"""
Example 1: Creating a new Dashboard with Filter Variable

This creates a new dashboard for the app specified and with the charts provided and with the Dashboard Filter provided
"""
filters = And(Filter('app', 'my-app'), Filter('env', 'test'))
program = Data('cpu.utilization', filter=filters).publish()
chart = TimeSeriesChart().with_name('Chart_Name').with_program(program)

app_var = FilterVariable().with_alias('application name') \
    .with_property('app') \
    .with_is_required(True) \
    .with_value('my-app')

app_filter = DashboardFilters() \
    .with_variables(app_var)

dashboard_with_single_filter_variable = Dashboard()\
    .with_name('Dashboard Name')\
    .with_charts(chart)\
    .with_filters(app_filter)
"""
Example 2: Creating a new Dashboard with multiple filters

"""
# With the same filters as above example,
program = Data('cpu.utilization', filter=filters).publish()
chart = TimeSeriesChart().with_name('Chart_Name').with_program(program)

app_var = FilterVariable().with_alias('application name') \
    .with_property('app') \