コード例 #1
0
def test_dashboard_create_with_filters_time_start_no_positive_integer_after_negative_sign_failure(
        session, chart):
    with pytest.raises(ValueError):
        time = FilterTime()\
            .with_start("--1h")\
            .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()
コード例 #2
0
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()
コード例 #3
0
def test_dashboard_create_with_filters_time_start_unexpected_last_character_failure(
        session, 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()
コード例 #4
0
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()
コード例 #5
0
def test_dashboard_create_with_filters_time_empty_end_time_failure(
        session, chart):
    with pytest.raises(ValueError):
        time = FilterTime() \
            .with_start('-1h') \
            .with_end('')

        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()
コード例 #6
0
def test_dashboard_create_with_filters_source_with_empty_value_failure(
        session, chart):
    with pytest.raises(ValueError):
        aws_src = FilterSource() \
            .with_property("aws_region") \
            .with_value("")

        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()
コード例 #7
0
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()
コード例 #8
0
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()
コード例 #9
0
def test_dashboard_create_with_filters_source_NOT_success(sfx_recorder, session, chart):
    aws_src = FilterSource()\
        .with_property("aws_region")\
        .with_value("us-west-2") \
        .with_is_not(True)

    dashboard_filter = DashboardFilters()\
        .with_sources(aws_src)

    with sfx_recorder.use_cassette('dashboard_create_with_filters_source_NOT_success',
                                      serialize_with='prettyjson'):
        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
コード例 #10
0
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()
コード例 #11
0
def test_dashboard_create_with_filters_time_as_integer_success():
    time = FilterTime()\
        .with_start(1523721600000)\
        .with_end(1523808000000)

    dashboard_filter = DashboardFilters()\
        .with_time(time)

    with global_recorder.use_cassette(
            'dashboard_create_with_filters_time_as_integer_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()
コード例 #12
0
def test_dashboard_create_with_filters_time_as_string_success(
        sfx_recorder, session, chart):
    time = FilterTime()\
        .with_start("-1h")\
        .with_end("Now")

    dashboard_filter = DashboardFilters()\
        .with_time(time)

    with sfx_recorder.use_cassette(
            'dashboard_create_with_filters_time_as_string_success',
            serialize_with='prettyjson'):
        Dashboard(session=session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(chart('lol'))\
            .with_filters(dashboard_filter)\
            .create()
コード例 #13
0
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()
コード例 #14
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"))
    )
コード例 #15
0
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()
コード例 #16
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') \