Skip to content

Commit f6384e1

Browse files
committed
Reduce repetitive logs in pipeline_options. Driveby: fix soft-delete warning.
1 parent ee0a031 commit f6384e1

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

sdks/python/apache_beam/io/gcp/gcsio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def _updated_to_seconds(updated):
642642

643643
def is_soft_delete_enabled(self, gcs_path):
644644
try:
645-
bucket_name, _ = parse_gcs_path(gcs_path)
645+
bucket_name, _ = parse_gcs_path(gcs_path, object_optional=True)
646646
bucket = self.get_bucket(bucket_name)
647647
if (bucket.soft_delete_policy is not None and
648648
bucket.soft_delete_policy.retention_duration_seconds > 0):

sdks/python/apache_beam/options/pipeline_options.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from apache_beam.options.value_provider import StaticValueProvider
3838
from apache_beam.options.value_provider import ValueProvider
3939
from apache_beam.transforms.display import HasDisplayData
40+
from apache_beam.utils import logs
4041
from apache_beam.utils import proto_utils
4142

4243
__all__ = [
@@ -422,9 +423,10 @@ def get_all_options(
422423
known_args, unknown_args = parser.parse_known_args(self._flags)
423424
if retain_unknown_options:
424425
if unknown_args:
425-
_LOGGER.warning(
426-
'Unknown pipeline options received: %s. Ignore if flags are '
427-
'used for internal purposes.' % (','.join(unknown_args)))
426+
if logs.allow_log_once():
427+
_LOGGER.warning(
428+
'Unknown pipeline options received: %s. Ignore if flags are '
429+
'used for internal purposes.' % (','.join(unknown_args)))
428430

429431
seen = set()
430432

@@ -466,7 +468,8 @@ def add_new_arg(arg, **kwargs):
466468
parsed_args, _ = parser.parse_known_args(self._flags)
467469
else:
468470
if unknown_args:
469-
_LOGGER.warning("Discarding unparseable args: %s", unknown_args)
471+
if logs.allow_log_once():
472+
_LOGGER.warning("Discarding unparseable args: %s", unknown_args)
470473
parsed_args = known_args
471474
result = vars(parsed_args)
472475

@@ -1064,19 +1067,21 @@ def _warn_if_soft_delete_policy_enabled(self, arg_name):
10641067
return
10651068

10661069
gcs_path = getattr(self, arg_name, None)
1067-
try:
1068-
from apache_beam.io.gcp import gcsio
1069-
if gcsio.GcsIO().is_soft_delete_enabled(gcs_path):
1070+
if logs.allow_log_once(gcs_path):
1071+
try:
1072+
from apache_beam.io.gcp import gcsio
1073+
if gcsio.GcsIO().is_soft_delete_enabled(gcs_path):
1074+
_LOGGER.warning(
1075+
"Bucket specified in %s has soft-delete policy enabled."
1076+
" To avoid being billed for unnecessary storage costs, turn"
1077+
" off the soft delete feature on buckets that your Dataflow"
1078+
" jobs use for temporary and staging storage. For more"
1079+
" information, see"
1080+
" https://cloud.google.com/storage/docs/use-soft-delete"
1081+
"#remove-soft-delete-policy." % arg_name)
1082+
except ImportError:
10701083
_LOGGER.warning(
1071-
"Bucket specified in %s has soft-delete policy enabled."
1072-
" To avoid being billed for unnecessary storage costs, turn"
1073-
" off the soft delete feature on buckets that your Dataflow"
1074-
" jobs use for temporary and staging storage. For more"
1075-
" information, see"
1076-
" https://cloud.google.com/storage/docs/use-soft-delete"
1077-
"#remove-soft-delete-policy." % arg_name)
1078-
except ImportError:
1079-
_LOGGER.warning('Unable to check soft delete policy due to import error.')
1084+
'Unable to check soft delete policy due to import error.')
10801085

10811086
# If either temp or staging location has an issue, we use the valid one for
10821087
# both locations. If both are bad we return an error.

0 commit comments

Comments
 (0)