Flaky BigQuery system tests
E.g., see:
https://circleci.com/gh/GoogleCloudPlatform/google-cloud-python/5869
@tswast Any clue why the back-end is failing this way?
ServiceUnavailable: 503 DELETE https://www.googleapis.com/storage/v1/b/bq_load_test_5869_1520454975/o/person_ages.csv: Backend Error
Looks like it's having trouble cleaning up some Cloud Storage files it created. @frankyn is it expected that creating a file in GCS and then deleting it shortly after could be flakey?
The test_load_table_from_uri_w_autodetect_schema_then_get_job test in question is here:
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/fefac75cf728599b6a8a05812337847ef595b705/bigquery/tests/system.py#L546-L588
I might actually be tempted to delete this test altogether. I think we cover the same code with the bigquery_load_table_gcs_json_autodetect snippet.
https://github.com/GoogleCloudPlatform/google-cloud-python/blob/fefac75cf728599b6a8a05812337847ef595b705/docs/bigquery/snippets.py#L622-L646
@tswast I haven't seen an issue with a delete right after creating a bucket.
For this case, docs do recommend a retry with exponential backoff. From the logs, I see exponential timings for retries. Not sure if this test is doing something different(strange) from the others.
Thanks Frank. Yeah, I think it is doing backoff, but perhaps there was just a random failure for this run.
Still, I think the best action here is to delete this particular test since it is redundant with the code snippet test (which also runs as a system test).
Made PR #5004 to remove this test. Is it likely other tests will act the same way?
Thanks @chemelnucfin. I'm slowly adding more "load from GCS" snippets. As I add them, I'll try to remember to remove the corresponding redundant system tests.
@tswast The bigquery system tests are running very slowly today (4 - 4.5 minutes each) today, which is causing unrelated PRs to be marked as failing (CI times the jobs out). Is there a known issue on the back-end we should be concerned about?
I'm not seeing anything on https://status.cloud.google.com/ or in the internal outage tracker. That extra slowness does sound like something could be going on, though.
FWIW, I've just cleaned out a bunch of GCS buckets with bq- prefixes, presumably orphaned somehow from Bigquery system tests.
@tswast Stalled BQ snippets tests caused a failure today.
I really wish we used verbose output so we could see which snippets are stalling.
We are actually passing --quiet, which suppresses even the dots (which might contribute to the CI timeout).
One thing I notice when running locally with --verbose: we have duplicated snippets for all the file formats crossed by all the variations on "load" operations (append, truncate, load from uri, w/ autodetect, etc.). Is that redundancy actually valuable for the docs, versus having a test that the "simple" form of load works with each format, and then a "see also" note for each of the other operations? Those seem to be the most expensive tests to run, BTW.
Unfortunately the docs are structured such that each file format needs 3 or 4 samples specific to that file type.
- Avro 3 samples: load (schema defined by filetype), load append, load truncate
- Parquet 3 samples: load (schema defined by filetype), load append, load truncate
- CSV 4 samples: load with explicit schema, load with autodetect, load append, load truncate
- JSON 4 samples: load with explicit schema, load with autodetect, load append, load truncate
- Datastore Backup 3 samples: load (schema defined by filetype), load append, load truncate
That said, I bet we could get away with 1 or 2 samples for each if we reduce the append/truncate samples to their bare minimum and assume they can follow the other example to figure out where the job config should go.
job_config = bigquery.LoadJobConfig()
job_config.write_disposition = bigquery.WriteDisposition.WRITE_APPEND
job_config = bigquery.LoadJobConfig()
job_config.write_disposition = bigquery.WriteDisposition.WRITE_TRUNCATE
You're right that we could probably play a similar trick with autodetect, but since it only applies to CSV and JSON, there's not as much reason to cut those.
I timed them locally, though there might be something specific with the project used by the CI which may be taking longer.
$ pytest ../docs/bigquery/snippets.py --durations=20
=========================== test session starts ===========================
platform darwin -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /Users/swast/src/google-cloud-python, inifile: setup.cfg
collected 57 items
../docs/bigquery/snippets.py .......................................................ss [100%]
========================== slowest 20 test durations =======================
132.85s call docs/bigquery/snippets.py::test_client_list_jobs
20.10s call docs/bigquery/snippets.py::test_load_table_from_uri_parquet_truncate
19.20s call docs/bigquery/snippets.py::test_load_table_from_uri_parquet_append
16.24s call docs/bigquery/snippets.py::test_load_table_from_uri_parquet
13.21s call docs/bigquery/snippets.py::test_copy_table_multiple_source
12.78s call docs/bigquery/snippets.py::test_load_table_from_uri_json_truncate
10.55s call docs/bigquery/snippets.py::test_load_table_from_uri_json_append
9.62s call docs/bigquery/snippets.py::test_load_table_from_uri_json_autodetect
9.03s call docs/bigquery/snippets.py::test_load_table_from_uri_csv_truncate
8.40s call docs/bigquery/snippets.py::test_browse_table_data
8.25s call docs/bigquery/snippets.py::test_load_table_from_uri_csv_append
7.88s call docs/bigquery/snippets.py::test_load_table_from_uri_json
7.25s call docs/bigquery/snippets.py::test_load_table_from_uri_cmek
6.96s call docs/bigquery/snippets.py::test_load_table_from_file
6.81s call docs/bigquery/snippets.py::test_extract_table_compressed
6.04s call docs/bigquery/snippets.py::test_load_table_from_uri_csv
5.49s call docs/bigquery/snippets.py::test_copy_table_cmek
5.08s call docs/bigquery/snippets.py::test_extract_table_json
4.71s call docs/bigquery/snippets.py::test_extract_table
4.71s call docs/bigquery/snippets.py::test_load_table_from_uri_csv_autodetect
I see that list_jobs is still taking a long time.
Sent https://github.com/GoogleCloudPlatform/google-cloud-python/pull/5209. The list_jobs snippet had a regression to showing all jobs in the project.
I agree that we should probably limit the number of load jobs we do, too, by having more generic samples for truncate/append rather than one for every file type. (Probably do Avro for that, since it's the fastest to load right now)
The BigQuery system tests are waaaaaay too slow: they are taking around 8 minutes each to run today:
51 passed, 1 warnings in 475.45 seconds
nox > Session system(py='2.7') successful. :)
The snippet tests are purtneer as bad (aggregate 20 - 30 minutes or more for the four environments, see the last successful build on master).
I'll run a profile locally to see if any test in particular is eating up most of the time.
$ pytest tests/system.py --durations=50
============================================= test session starts =============================================
platform darwin -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /Users/swast/src/google-cloud-python, inifile: setup.cfg
collected 51 items
tests/system.py s.................................s....s........... [100%]
========================================== slowest 50 test durations ==========================================
67.56s call bigquery/tests/system.py::TestBigQuery::test_query_many_columns
64.80s call bigquery/tests/system.py::TestBigQuery::test_load_table_from_file_w_explicit_location
51.71s call bigquery/tests/system.py::TestBigQuery::test_list_rows_many_columns
34.16s call bigquery/tests/system.py::TestBigQuery::test_dbapi_w_standard_sql_types
30.35s call bigquery/tests/system.py::TestBigQuery::test_query_w_query_params
26.77s call bigquery/tests/system.py::TestBigQuery::test_dbapi_w_query_parameters
19.92s call bigquery/tests/system.py::TestBigQuery::test_query_w_standard_sql_types
15.83s call bigquery/tests/system.py::TestBigQuery::test_dump_table_w_public_data
12.00s call bigquery/tests/system.py::TestBigQuery::test_load_avro_from_uri_then_dump_table
11.96s call bigquery/tests/system.py::TestBigQuery::test_extract_table
11.82s call bigquery/tests/system.py::TestBigQuery::test_load_table_from_local_avro_file_then_dump_table
10.66s call bigquery/tests/system.py::TestBigQuery::test_extract_table_w_job_config
10.24s call bigquery/tests/system.py::TestBigQuery::test_dbapi_w_dml
9.40s call bigquery/tests/system.py::TestBigQuery::test_copy_table
8.81s call bigquery/tests/system.py::TestBigQuery::test_load_table_from_uri_then_dump_table
8.29s call bigquery/tests/system.py::TestBigQuery::test_query_w_dml
6.65s call bigquery/tests/system.py::TestBigQuery::test_list_rows_page_size
6.42s call bigquery/tests/system.py::TestBigQuery::test_dbapi_fetchall
6.23s call bigquery/tests/system.py::TestBigQuery::test_query_external_table
6.01s call bigquery/tests/system.py::TestBigQuery::test_query_w_legacy_sql_types
5.43s call bigquery/tests/system.py::TestBigQuery::test_load_table_from_local_file_then_dump_table
4.43s call bigquery/tests/system.py::TestBigQuery::test_query_table_def
3.88s call bigquery/tests/system.py::TestBigQuery::test_update_table
3.69s call bigquery/tests/system.py::TestBigQuery::test_dump_table_w_public_data_selected_fields
3.38s call bigquery/tests/system.py::TestBigQuery::test_update_dataset
3.25s call bigquery/tests/system.py::TestBigQuery::test_job_cancel
2.97s call bigquery/tests/system.py::TestBigQuery::test_update_table_schema
2.91s call bigquery/tests/system.py::TestBigQuery::test_list_datasets
2.88s call bigquery/tests/system.py::TestBigQuery::test_insert_rows_then_dump_table
2.82s call bigquery/tests/system.py::TestBigQuery::test_list_tables
2.73s call bigquery/tests/system.py::TestBigQuery::test_large_query_w_public_data
2.55s call bigquery/tests/system.py::TestBigQuery::test_create_table_rows_fetch_nested_schema
2.35s call bigquery/tests/system.py::TestBigQuery::test_insert_rows_nested_nested
2.35s call bigquery/tests/system.py::TestBigQuery::test_insert_rows_nested_nested_dictionary
2.15s call bigquery/tests/system.py::TestBigQuery::test_query_w_wrong_config
1.86s call bigquery/tests/system.py::TestBigQuery::test_create_table
1.77s call bigquery/tests/system.py::TestBigQuery::test_query_w_timeout
1.38s call bigquery/tests/system.py::TestBigQuery::test_delete_dataset_delete_contents_true
1.33s call bigquery/tests/system.py::TestBigQuery::test_delete_dataset_delete_contents_false
1.22s call bigquery/tests/system.py::TestBigQuery::test_get_dataset
1.13s call bigquery/tests/system.py::TestBigQuery::test_create_dataset
0.77s call bigquery/tests/system.py::TestBigQuery::test_query_future
0.67s call bigquery/tests/system.py::TestBigQuery::test_query_iter
0.60s call bigquery/tests/system.py::TestBigQuery::test_list_datasets_w_project
0.42s call bigquery/tests/system.py::TestBigQuery::test_get_service_account_email
0.25s call bigquery/tests/system.py::TestBigQuery::test_get_failed_job
0.24s call bigquery/tests/system.py::TestBigQuery::test_get_table_w_public_dataset
0.20s call bigquery/tests/system.py::TestBigQuery::test_query_w_failed_query
0.00s setup bigquery/tests/system.py::TestBigQuery::test_copy_table
0.00s teardown bigquery/tests/system.py::TestBigQuery::test_extract_table
=================================== 48 passed, 3 skipped in 480.64 seconds ====================================
Unfortunately, some of the longest-running ones I'm not comfortable cutting.
test_load_table_from_file_w_explicit_location: tests some particularly tricky cross-location features. We don't have equivalent snippets for these and probably won't.test_query_many_columnsandtest_list_rows_many_columns: response to a bug w/ fix, for example. (Though maybe we could convert to unit test now that we're pretty confident it's working?)test_dbapi_w_standard_sql_types: We do need some tests for querying with the DB-API. (Though perhaps it doesn't need the full set that thequery()method has, since it is a pretty thin wrapper aroundquery())test_query_w_query_params: There are many data types for query parameters, and we need to make sure we are serializing them in a way the API understands. Same argument fortest_query_w_standard_sql_types(many datatypes to support.)test_dbapi_w_query_parameters: These definitely need to stay, as the DB-API does some extra type conversions for query parameters compared to thequery()method.test_load_avro_from_uri_then_dump_tableneeds to stay until we add an Avro snippet. (Loading https://storage.googleapis.com/cloud-samples-data/bigquery/us-states/us-states.avro from GCS)
Some of the top tests are redundant with snippets.py and I would be comfortable dropping from system.py.
test_dump_table_w_public_data,test_dump_table_w_public_data_selected_fields: redundant withbigquery_browse_tablesnippet. https://github.com/GoogleCloudPlatform/google-cloud-python/blob/05c595f26e8c91011adb5b564bb52be386f107b6/docs/bigquery/snippets.py#L750-L773test_extract_table_w_job_config: redundant withbigquery_extract_table_jsonsnippet. https://github.com/GoogleCloudPlatform/google-cloud-python/blob/05c595f26e8c91011adb5b564bb52be386f107b6/docs/bigquery/snippets.py#L1454-L1473test_load_table_from_local_file_then_dump_table: redundant withbigquery_load_from_filesnippet. https://github.com/GoogleCloudPlatform/google-cloud-python/blob/05c595f26e8c91011adb5b564bb52be386f107b6/docs/bigquery/snippets.py#L831-L856- ... quite a few others, though we're getting into the land of decreasing returns.