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_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()
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_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()
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()
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()
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")) )
app_filter = DashboardFilters() \ .with_sources(aws_src) dashboard_with_source_filter = Dashboard()\ .with_name('Dashboard With Source Filter')\ .with_charts(chart)\ .with_filters(app_filter) """ Example 4: Creating a new Dashboard with time(as string) filter """ # With the same filters as above example, program = Data('cpu.utilization', filter=filters).publish() chart = TimeSeriesChart().with_name('Chart_Name').with_program(program) time = FilterTime().with_start("-1h").with_end("Now") app_filter = DashboardFilters() \ .with_time(time) dashboard_with_time_as_string_filter = Dashboard()\ .with_name('Dashboard With Time as String Filter')\ .with_charts(chart)\ .with_filters(app_filter) """ Example 5: Creating a new Dashboard with time(as integer) filter """ # With the same filters as above example, program = Data('cpu.utilization', filter=filters).publish() chart = TimeSeriesChart().with_name('Chart_Name').with_program(program)