google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Flaky BigQuery system tests

Open tseaver opened this issue 8 years ago • 29 comments

E.g., see:

https://circleci.com/gh/GoogleCloudPlatform/google-cloud-python/5869

tseaver avatar Mar 07 '18 21:03 tseaver

@tswast Any clue why the back-end is failing this way?

tseaver avatar Mar 07 '18 21:03 tseaver

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 avatar Mar 07 '18 21:03 tswast

@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.

frankyn avatar Mar 08 '18 01:03 frankyn

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

tswast avatar Mar 08 '18 04:03 tswast

Made PR #5004 to remove this test. Is it likely other tests will act the same way?

chemelnucfin avatar Mar 08 '18 07:03 chemelnucfin

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 avatar Mar 08 '18 16:03 tswast

@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?

tseaver avatar Mar 12 '18 17:03 tseaver

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.

tswast avatar Mar 12 '18 17:03 tswast

FWIW, I've just cleaned out a bunch of GCS buckets with bq- prefixes, presumably orphaned somehow from Bigquery system tests.

tseaver avatar Mar 15 '18 18:03 tseaver

@tswast Stalled BQ snippets tests caused a failure today.

tseaver avatar Apr 17 '18 17:04 tseaver

I really wish we used verbose output so we could see which snippets are stalling.

tswast avatar Apr 17 '18 18:04 tswast

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.

tseaver avatar Apr 17 '18 19:04 tseaver

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

tswast avatar Apr 17 '18 20:04 tswast

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.

tswast avatar Apr 17 '18 20:04 tswast

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.

tswast avatar Apr 18 '18 20:04 tswast

Sent https://github.com/GoogleCloudPlatform/google-cloud-python/pull/5209. The list_jobs snippet had a regression to showing all jobs in the project.

tswast avatar Apr 18 '18 21:04 tswast

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)

tswast avatar Apr 18 '18 21:04 tswast

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

tseaver avatar Apr 27 '18 16:04 tseaver

I'll run a profile locally to see if any test in particular is eating up most of the time.

tswast avatar Apr 27 '18 17:04 tswast

$ 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_columns and test_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 the query() method has, since it is a pretty thin wrapper around query())
  • 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 for test_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 the query() method.
  • test_load_avro_from_uri_then_dump_table needs 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 with bigquery_browse_table snippet. https://github.com/GoogleCloudPlatform/google-cloud-python/blob/05c595f26e8c91011adb5b564bb52be386f107b6/docs/bigquery/snippets.py#L750-L773
  • test_extract_table_w_job_config : redundant with bigquery_extract_table_json snippet. https://github.com/GoogleCloudPlatform/google-cloud-python/blob/05c595f26e8c91011adb5b564bb52be386f107b6/docs/bigquery/snippets.py#L1454-L1473
  • test_load_table_from_local_file_then_dump_table : redundant with bigquery_load_from_file snippet. 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.

tswast avatar Apr 27 '18 18:04 tswast