Skip to content

Commit

Permalink
chore: add option to delete benchmarking bucket (#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
cojenco committed May 18, 2023
1 parent 2ad709a commit 2b449cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions tests/perf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $ python3 benchmarking.py --num_samples 10000 --object_size 5120..16384 --output
| --test_type | test type to run benchmarking | `w1r3`, `range` | `w1r3` |
| --output_file | file to output results to | any file path | `output_bench<TIMESTAMP>.csv` |
| --tmp_dir | temp directory path on file system | any file path | `tm-perf-metrics` |
| --delete_bucket | whether or not to delete GCS bucket used for benchmarking| bool | `False` |


## Workload definition and CSV headers
Expand Down
13 changes: 7 additions & 6 deletions tests/perf/_perf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,20 @@ def get_bucket_instance(bucket_name):
return bucket


def cleanup_bucket(bucket):
def cleanup_bucket(bucket, delete_bucket=False):
# Delete blobs first as the bucket may contain more than 256 blobs.
try:
blobs = bucket.list_blobs()
for blob in blobs:
blob.delete()
except Exception as e:
logging.exception(f"Caught an exception while deleting blobs\n {e}")
# Delete bucket.
try:
bucket.delete(force=True)
except Exception as e:
logging.exception(f"Caught an exception while deleting bucket\n {e}")
# Delete bucket if delete_bucket is set to True
if delete_bucket:
try:
bucket.delete(force=True)
except Exception as e:
logging.exception(f"Caught an exception while deleting bucket\n {e}")


def get_min_max_size(object_size):
Expand Down
8 changes: 7 additions & 1 deletion tests/perf/benchmarking.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main(args):
)

# Cleanup and delete blobs.
_pu.cleanup_bucket(bucket)
_pu.cleanup_bucket(bucket, delete_bucket=args.delete_bucket)

# BBMC will not surface errors unless the process is terminated with a non zero code.
if counter.count.errors != 0:
Expand Down Expand Up @@ -173,6 +173,12 @@ def main(args):
default=_pu.DEFAULT_BASE_DIR,
help="Temp directory path on file system",
)
parser.add_argument(
"--delete_bucket",
type=bool,
default=False,
help="Whether or not to delete GCS bucket used for benchmarking",
)
args = parser.parse_args()

main(args)

0 comments on commit 2b449cd

Please sign in to comment.