def test_dashboard_create_with_filters_with_multiple_variables_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_create_with_filters_with_multiple_variables_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_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()
Пример #4
0
def test_dashboard_update_with_filters_success():
    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 global_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=global_session)\
            .with_name('testy mctesterson')\
            .with_api_token('foo')\
            .with_charts(mk_chart('lol'))\
            .with_filters(dashboard_filter)\
            .update()
Пример #5
0
def test_dashboard_create_with_filters_with_one_variable_success():
    app_var = FilterVariable().with_alias('app') \
        .with_property('app') \
        .with_is_required(True) \
        .with_value('bar')

    dashboard_filter = DashboardFilters() \
        .with_variables(app_var)

    with global_recorder.use_cassette(
            'dashboard_create_with_filters_with_one_variable_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()
Пример #7
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"))
    )
Пример #8
0
from signal_analog.flow import Data, Filter
from signal_analog.charts import TimeSeriesChart
from signal_analog.dashboards import Dashboard
from signal_analog.combinators import And
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()