def testInitEngines_usesCorrectIsolationLevelsInStaging(
            self, mock_get_secret, mock_in_gae, mock_in_staging,
            mock_create_engine):
        # Arrange
        mock_in_gae.return_value = True
        mock_in_staging.return_value = True
        # Pretend all secret values are just the key suffixed with '_value'
        mock_get_secret.side_effect = lambda key: f'{key}_value'

        # Act
        SQLAlchemyEngineManager.init_engines_for_server_postgres_instances()

        # Assert
        assert mock_create_engine.call_args_list == [
            call(
                'postgresql://*****:*****@/sqlalchemy_db_name_value'
                '?host=/cloudsql/cloudsql_instance_id_value',
                isolation_level=None,
                pool_recycle=600),
            call(
                'postgresql://*****:*****@/state_db_name_value'
                '?host=/cloudsql/state_cloudsql_instance_id_value',
                isolation_level='SERIALIZABLE',
                pool_recycle=600),
            call(
                'postgresql://*****:*****@/operations_db_name_value'
                '?host=/cloudsql/operations_cloudsql_instance_id_value',
                isolation_level=None,
                pool_recycle=600),
            call(
                'postgresql://*****:*****@/'
                'justice_counts_db_name_value?host=/cloudsql/justice_counts_cloudsql_instance_id_value',
                isolation_level='SERIALIZABLE',
                pool_recycle=600),
        ]
예제 #2
0
    def testInitEngines_usesCorrectIsolationLevelsInStaging(self, mock_in_gae, mock_in_staging, mock_create_engine):
        # Arrange
        mock_in_gae.return_value = True
        mock_in_staging.return_value = True

        # Act
        SQLAlchemyEngineManager.init_engines_for_server_postgres_instances()

        # Assert
        assert mock_create_engine.call_args_list == [
            call('path', isolation_level=None, pool_recycle=600),
            call('path', isolation_level='SERIALIZABLE', pool_recycle=600),
            call('path', isolation_level=None, pool_recycle=600),
        ]
    def testInitEngines_usesCorrectIsolationLevels(self, mock_get_secret,
                                                   mock_in_gcp,
                                                   mock_in_production,
                                                   mock_create_engine):
        # Arrange
        mock_in_gcp.return_value = True
        mock_in_production.return_value = True
        # Pretend all secret values are just the key suffixed with '_value'
        mock_get_secret.side_effect = lambda key: f"{key}_value"

        # Act
        SQLAlchemyEngineManager.init_engines_for_server_postgres_instances()

        # Assert
        assert mock_create_engine.call_args_list == [
            call(
                "postgresql://*****:*****@/sqlalchemy_db_name_value"
                "?host=/cloudsql/sqlalchemy_cloudsql_instance_id_value",
                isolation_level=None,
                pool_recycle=600,
            ),
            call(
                "postgresql://*****:*****@/state_db_name_value"
                "?host=/cloudsql/state_cloudsql_instance_id_value",
                isolation_level="SERIALIZABLE",
                pool_recycle=600,
            ),
            call(
                "postgresql://*****:*****@/operations_db_name_value"
                "?host=/cloudsql/operations_cloudsql_instance_id_value",
                isolation_level=None,
                pool_recycle=600,
            ),
            call(
                "postgresql://*****:*****@/"
                "justice_counts_db_name_value?host=/cloudsql/justice_counts_cloudsql_instance_id_value",
                isolation_level="SERIALIZABLE",
                pool_recycle=600,
            ),
            call(
                "postgresql://*****:*****@/"
                "case_triage_db_name_value?host=/cloudsql/case_triage_cloudsql_instance_id_value",
                isolation_level=None,
                pool_recycle=600,
            ),
        ]
예제 #4
0
)
app.register_blueprint(store_single_count_blueprint, url_prefix="/single_count")
app.register_blueprint(cloud_sql_to_bq_blueprint, url_prefix="/cloud_sql_to_bq")
app.register_blueprint(backup_manager_blueprint, url_prefix="/backup_manager")
app.register_blueprint(dataflow_monitor_blueprint, url_prefix="/dataflow_monitor")
app.register_blueprint(validation_manager_blueprint, url_prefix="/validation_manager")
app.register_blueprint(
    calculation_data_storage_manager_blueprint,
    url_prefix="/calculation_data_storage_manager",
)
app.register_blueprint(reporting_endpoint_blueprint, url_prefix="/reporting")
app.register_blueprint(export_blueprint, url_prefix="/export")
app.register_blueprint(justice_counts_control, url_prefix="/justice_counts")

if environment.in_gcp():
    SQLAlchemyEngineManager.init_engines_for_server_postgres_instances()

# Export traces and metrics to stackdriver if running in GCP
if environment.in_gcp():
    monitoring.register_stackdriver_exporter()
    trace_exporter = stackdriver_trace.StackdriverExporter(
        project_id=metadata.project_id(), transport=AsyncTransport
    )
    trace_sampler = trace.CompositeSampler(
        {
            "/direct/process_job": samplers.AlwaysOnSampler(),
            # There are a lot of scraper requests, so they can use the default rate of 1 in 10k.
            "/scraper/": samplers.ProbabilitySampler(),
            "/scrape_aggregate_reports/": samplers.ProbabilitySampler(),
        },
        # For other requests, trace 1 in 20.