forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BEAM-7667] report GCS throttling time to Dataflow autoscaler
- Loading branch information
Showing
5 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http:https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from __future__ import absolute_import | ||
|
||
import logging | ||
import math | ||
import time | ||
|
||
from apache_beam.metrics.metric import Metrics | ||
from apitools.base.py import exceptions | ||
from apitools.base.py import http_wrapper | ||
from apitools.base.py import util | ||
|
||
|
||
class GcsIOOverrides(object): | ||
"""Functions for overriding Google Cloud Storage I/O client.""" | ||
|
||
_THROTTLED_SECS = Metrics.counter('StorageV1', "cumulativeThrottlingSeconds") | ||
|
||
@classmethod | ||
def retry_func(cls, retry_args): | ||
# handling GCS download throttling errors (BEAM-7424) | ||
if (isinstance(retry_args.exc, exceptions.BadStatusCodeError) and | ||
retry_args.exc.status_code == http_wrapper.TOO_MANY_REQUESTS): | ||
logging.debug( | ||
'Caught GCS quota error (%s), retrying.', retry_args.exc.status_code) | ||
else: | ||
return http_wrapper.HandleExceptionsAndRebuildHttpConnections(retry_args) | ||
|
||
http_wrapper.RebuildHttpConnections(retry_args.http) | ||
logging.debug('Retrying request to url %s after exception %s', | ||
retry_args.http_request.url, retry_args.exc) | ||
sleep_seconds = util.CalculateWaitForRetry( | ||
retry_args.num_retries, max_wait=retry_args.max_retry_wait) | ||
cls._THROTTLED_SECS.inc(math.ceil(sleep_seconds)) | ||
time.sleep(sleep_seconds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters