示例#1
0
def test_dashboard_group_update_success(sfx_recorder, session):
    # Enforcing the request body helps to prevent a defect from being masked due to over-mocking
    # the requests/responses.
    with betamax.Betamax.configure() as config:
        initial_cassette_options = config.default_cassette_options[
            'match_requests_on']
        config.default_cassette_options['match_requests_on'] = [
            'body', 'method', 'uri'
        ]

        with sfx_recorder.use_cassette('dashboard_group_update_success',
                                       serialize_with='prettyjson'):
            name = 'spaceX lol'
            updated_name = 'updated_dashboard_group_name'
            updated_team_id = 'updated_team_id'

            dashboard_group = DashboardGroup(session=session)\
                .with_name(name)\
                .with_api_token('foo')

            create_result = dashboard_group.create()

            update_result = dashboard_group\
                .with_id(create_result['id'])\
                .with_teams(updated_team_id)\
                .update(name='updated_dashboard_group_name',
                        description='updated_dashboard_group_description')

            assert create_result['name'] == name
            assert update_result['name'] == updated_name
            assert updated_team_id in update_result['teams']

        with betamax.Betamax.configure() as config:
            config.default_cassette_options[
                'match_requests_on'] = initial_cassette_options
def test_dashboard_group_with_dashboard_update_success(sfx_recorder, session, dashboard):
    with sfx_recorder.use_cassette(
        'dashboard_group_with_dashboard_update_success',
            serialize_with='prettyjson'):

        dashboard_group = DashboardGroup(session=session) \
            .with_name('spaceX') \
            .with_dashboards(
                dashboard('Falcon99', 'chart1'),
                dashboard('FalconHeavy', 'chart2')) \
            .with_api_token('foo')

        dashboard_group.update()
def test_dashboard_group_with_dashboard_create_force_success(sfx_recorder, session, dashboard):

    name = 'spaceX'
    dashboard_group = DashboardGroup(session=session)\
        .with_name(name) \
        .with_dashboards(dashboard('Falcon99', 'chart1'))\
        .with_api_token('foo')

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

        result = dashboard_group.create(force=True)

        assert result['name'] == name
        assert len(result['dashboards']) == 1
示例#4
0
def test_dashboard_group_with_dashboard_create_success():

    name = 'spaceX unique'
    group = DashboardGroup(session=global_session)\
        .with_name(name)\
        .with_dashboards(mk_dashboard('Falcon99', 'chart1'))\
        .with_api_token('foo')\

    with global_recorder.use_cassette(
            'dashboard_group_with_dashboard_create_success',
            serialize_with='prettyjson'):

        result = group.create()

        assert result['name'] == name
        assert len(result['dashboards']) == 1
def test_dashboard_group_create_success(sfx_recorder, session):
    with sfx_recorder.use_cassette('dashboard_group_create_success',
                                      serialize_with='prettyjson'):
        DashboardGroup(session=session)\
            .with_name('spaceX')\
            .with_api_token('foo')\
            .create()
def test_dashboard_group_with_delete_existing_dashboard_update_success(sfx_recorder, session, dashboard):
    name = 'spaceX'

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

        dashboard_group = DashboardGroup(session=session) \
            .with_name(name) \
            .with_dashboards(dashboard('Draagoon', 'chart3')) \
            .with_api_token('foo')

        response = dashboard_group.update()

        assert response['name'] == name
        assert len(response['dashboards']) == 1
def test_dashboard_group_with_dashboard_create_interactive_failure(confirm, sfx_recorder, session, dashboard):
    confirm.__getitem__.return_value = 'n'

    name = 'spaceX'

    dashboard_group = DashboardGroup(session=session) \
        .with_name(name) \
        .with_dashboards(dashboard('Falcon99', 'chart1')) \
        .with_api_token('foo')

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

            result = dashboard_group.create(interactive=True)
            assert result['name'] == name
            assert len(result['dashboards']) == 1
def test_dashboard_group_read_success(sfx_recorder, session):
    with sfx_recorder.use_cassette('dashboard_group_read_success',
                                      serialize_with='prettyjson'):
        expected = '[prod] Legacyidmapping Application Dashboard Group'
        response = DashboardGroup(session=session)\
            .with_api_token('foo')\
            .with_name(expected)\
            .read()

        assert response['name'] == expected
def test_dashboard_group_update_success(sfx_recorder, session):

    name = 'spaceX lol'
    updated_name = 'updated_dashboard_group_name'

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

        dashboard_group = DashboardGroup(session=session)\
            .with_name(name)\
            .with_api_token('foo')

        create_result = dashboard_group.create()

        update_result = dashboard_group\
            .with_id(create_result['id'])\
            .update(name='updated_dashboard_group_name',
                    description='updated_dashboard_group_description')

        assert create_result['name'] == name
        assert update_result['name'] == updated_name
def test_dashboard_group_create_force_success(sfx_recorder, session):
    dashboard_group = DashboardGroup(session=session)\
        .with_name('spaceX')\
        .with_api_token('foo')\

    with sfx_recorder.use_cassette('dashboard_group_create_success_force',
                                      serialize_with='prettyjson'):
        # Create our first dashboard group
        dashboard_group.create()
        with pytest.raises(SignalAnalogError):
            # Verify that we can't create it again
            dashboard_group.create()
        # Force the dashboard group to create itself again
        dashboard_group.create(force=True)
def test_dashboard_group_create_interactive_failure(confirm, sfx_recorder, session):
    confirm.__getitem__.return_value = 'n'
    dashboard_group = DashboardGroup(session=session) \
        .with_name('spaceX') \
        .with_api_token('foo')
    with sfx_recorder.use_cassette(
        'dashboard_group_create_failure_interactive',
            serialize_with='prettyjson'):

        # Create our first dashboard_group
        dashboard_group.create()
        with pytest.raises(SignalAnalogError):
            # Verify that we can't create it again
            dashboard_group.create()
            dashboard_group.create(interactive=True)
示例#12
0
def test_dashboard_group_create_interactive_success(confirm):
    confirm.__getitem__.return_value = 'y'
    dashboard_group = DashboardGroup(session=global_session) \
        .with_name('spaceX') \
        .with_api_token('foo')
    with global_recorder.use_cassette(
            'dashboard_group_create_success_interactive',
            serialize_with='prettyjson'):

        # Create our first dashboard group
        dashboard_group.create()
        with pytest.raises(SignalAnalogError):
            # Verify that we can't create it again
            dashboard_group.create()
        # Run the dashboard group creation in interactive mode
        dashboard_group.create(interactive=True)
def test_dashboard_group_update_failure(sfx_recorder, session):

    dashboard_group = DashboardGroup(session=session) \
        .with_name('spaceX') \
        .with_api_token('foo')
    with sfx_recorder.use_cassette('dashboard_group_update_failure',
                                      serialize_with='prettyjson'):
        # Just to make sure there are multiple dashboard groups exists,
        # create a new dashboard group with the same name
        dashboard_group.create(force=True)
        dashboard_group.create(force=True)

        with pytest.raises(SignalAnalogError):
            # Verify that we can't update when multiple dashboard groups exist
            dashboard_group.update(
                name='updated_dashboard_group_name',
                description='updated_dashboard_group_description')
def test_dashboard_group_clone_success(sfx_recorder, session):
    with sfx_recorder.use_cassette('dashboard_group_clone_success',
                                      serialize_with='prettyjson'):
        DashboardGroup(session=session)\
            .with_api_token('foo')\
            .clone('DWgX6iYAcAA', 'DWgX6dNAYAA')
def test_dashboard_group_delete_success(sfx_recorder, session):
    with sfx_recorder.use_cassette('dashboard_group_delete_success',
                                      serialize_with='prettyjson'):
        DashboardGroup(session=session)\
            .with_api_token('foo')\
            .delete('DWgXZfyAcAA')
示例#16
0
from signal_analog.charts import TimeSeriesChart
from signal_analog.dashboards import Dashboard, DashboardGroup
from signal_analog.combinators import And
"""
Creating a new Dashboard Group with Dashboards
"""
filters = And(Filter('host', 'learn-signalfx'))

program = Data('cpu.utilization', filter=filters).publish()
cpu_chart = TimeSeriesChart().with_name('CPU').with_program(program)

program = Data('postgres_query_time', rollup='rate', filter=filters).publish()
query_time = TimeSeriesChart().with_name('Query Time').with_program(program)

program = Data('memory.utilization', filter=filters).publish()
memory_chart = TimeSeriesChart().with_name('Memory').with_program(program)

dashboard1 = Dashboard().with_name('Dashboard 1').with_charts(
    query_time, cpu_chart, memory_chart)

dashboard_group = DashboardGroup() \
    .with_name('Learn Signal Analog') \
    .with_dashboards(dashboard1)

if __name__ == '__main__':
    from signal_analog.cli import CliBuilder

    cli = CliBuilder().with_resources(dashboard_group)\
        .build()
    cli()
示例#17
0
            .with_time(FilterTime().with_start("-7d").with_end("Now"))
    )


if __name__ == '__main__':
    dashboards = []
    dashboards.append(
        create_pipeline_dashboard("My Data Pipeline Dashboard", [
            AwsResouce(AwsResourceType.SqsQueue, 'some-queue',
                       'This queue is triggered by a SNS topic'),
            AwsResouce(AwsResourceType.Lambda, 'some-lambda',
                       'Lambda listens to Queue and writes to DynamoDB'),
            AwsResouce(AwsResourceType.DynamoDbWithStream, 'my-table',
                       'Updated by lambda'),
            AwsResouce(
                AwsResourceType.Lambda, 'another-lambda',
                'Lambda listens to DynamoDB stream and writes to Kinesis stream'
            ),
            AwsResouce(AwsResourceType.KinesisStream, 'some-kinesis-stream',
                       'Some stream with consumers')
        ]))

    # TODO: by simply calling the `create_pipeline_dashboard()` function we can add additional Dashboards in a config style

    group = DashboardGroup() \
        .with_name("My Data Pipeline Dashboard Group") \
        .with_dashboards(*dashboards)

    cli = CliBuilder().with_resources(group).build()
    cli()
def test_dashboard_group_with_team_noop():
    group = DashboardGroup()

    # Sfx API will ignore an empty teams object, so this is harmless.
    assert group.with_teams().options['teams'] == []
def test_dashboard_group_with_team_happy():
    expected = '1234'
    group = DashboardGroup().with_teams(expected)

    assert group.options['teams'] == [expected]
示例#20
0
#!/usr/bin/env python
"""Examples for the `signal_analog.dashboards` module."""

from signal_analog.flow import Data, Filter
from signal_analog.charts import TimeSeriesChart
from signal_analog.dashboards import Dashboard, DashboardGroup
from signal_analog.combinators import And
"""
Example 1: Creating a new Dashboard Group

This creates a new dashboard group
"""
dashboard_group = DashboardGroup().with_name('Dashboard Group Name')
"""
Example 2: Creating a new Dashboard Group with Dashboards

"""
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)

program1 = Data('network.utilization', filter=filters).publish()
chart1 = TimeSeriesChart().with_name('Chart_Name').with_program(program)

program2 = Data('api_errors', filter=filters).publish()
chart2 = TimeSeriesChart().with_name('Chart_Name').with_program(program)

dashboard1 = Dashboard().with_name('Dashboard1').with_charts(chart)
dashboard2 = Dashboard().with_name('Dashboard2').with_charts(chart, chart1)
dashboard3 = Dashboard().with_name('Dashboard3')\