Skip to content

Commit 3d2bf06

Browse files
grubberrakashkulk
authored andcommitted
Source Amazon Ads: remove "report_wait_timeout", "report_generation_max_retries" from config (#18985)
Signed-off-by: Sergey Chvalyuk <[email protected]>
1 parent f214168 commit 3d2bf06

File tree

10 files changed

+61
-81
lines changed

10 files changed

+61
-81
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
- name: Amazon Ads
4848
sourceDefinitionId: c6b0a29e-1da9-4512-9002-7bfd0cba2246
4949
dockerRepository: airbyte/source-amazon-ads
50-
dockerImageTag: 0.1.24
50+
dockerImageTag: 0.1.25
5151
documentationUrl: https://docs.airbyte.com/integrations/sources/amazon-ads
5252
icon: amazonads.svg
5353
sourceType: api

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@
725725
supportsNormalization: false
726726
supportsDBT: false
727727
supported_destination_sync_modes: []
728-
- dockerImage: "airbyte/source-amazon-ads:0.1.24"
728+
- dockerImage: "airbyte/source-amazon-ads:0.1.25"
729729
spec:
730730
documentationUrl: "https://docs.airbyte.com/integrations/sources/amazon-ads"
731731
connectionSpecification:
@@ -770,40 +770,20 @@
770770
type: "string"
771771
default: "NA"
772772
order: 4
773-
report_wait_timeout:
774-
title: "Report Wait Timeout"
775-
description: "Timeout duration in minutes for Reports. Default is 60 minutes."
776-
default: 60
777-
examples:
778-
- 60
779-
- 120
780-
order: 5
781-
type: "integer"
782-
report_generation_max_retries:
783-
title: "Report Generation Maximum Retries"
784-
description: "Maximum retries Airbyte will attempt for fetching report data.\
785-
\ Default is 5."
786-
default: 5
787-
examples:
788-
- 5
789-
- 10
790-
- 15
791-
order: 6
792-
type: "integer"
793773
start_date:
794774
title: "Start Date"
795775
description: "The Start date for collecting reports, should not be more\
796776
\ than 60 days in the past. In YYYY-MM-DD format"
797777
examples:
798778
- "2022-10-10"
799779
- "2022-10-22"
800-
order: 7
780+
order: 5
801781
type: "string"
802782
profiles:
803783
title: "Profile IDs"
804784
description: "Profile IDs you want to fetch data for. See <a href=\"https://advertising.amazon.com/API/docs/en-us/concepts/authorization/profiles\"\
805785
>docs</a> for more details."
806-
order: 8
786+
order: 6
807787
type: "array"
808788
items:
809789
type: "integer"
@@ -820,7 +800,7 @@
820800
- "archived"
821801
type: "array"
822802
uniqueItems: true
823-
order: 9
803+
order: 7
824804
required:
825805
- "client_id"
826806
- "client_secret"

airbyte-integrations/connectors/source-amazon-ads/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

1515

16-
LABEL io.airbyte.version=0.1.24
16+
LABEL io.airbyte.version=0.1.25
1717
LABEL io.airbyte.name=airbyte/source-amazon-ads

airbyte-integrations/connectors/source-amazon-ads/integration_tests/spec.json

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,17 @@
3838
"default": "NA",
3939
"order": 4
4040
},
41-
"report_wait_timeout": {
42-
"title": "Report Wait Timeout",
43-
"description": "Timeout duration in minutes for Reports. Default is 60 minutes.",
44-
"default": 60,
45-
"examples": [60, 120],
46-
"order": 5,
47-
"type": "integer"
48-
},
49-
"report_generation_max_retries": {
50-
"title": "Report Generation Maximum Retries",
51-
"description": "Maximum retries Airbyte will attempt for fetching report data. Default is 5.",
52-
"default": 5,
53-
"examples": [5, 10, 15],
54-
"order": 6,
55-
"type": "integer"
56-
},
5741
"start_date": {
5842
"title": "Start Date",
5943
"description": "The Start date for collecting reports, should not be more than 60 days in the past. In YYYY-MM-DD format",
6044
"examples": ["2022-10-10", "2022-10-22"],
61-
"order": 7,
45+
"order": 5,
6246
"type": "string"
6347
},
6448
"profiles": {
6549
"title": "Profile IDs",
6650
"description": "Profile IDs you want to fetch data for. See <a href=\"https://advertising.amazon.com/API/docs/en-us/concepts/authorization/profiles\">docs</a> for more details.",
67-
"order": 8,
51+
"order": 6,
6852
"type": "array",
6953
"items": {
7054
"type": "integer"
@@ -79,7 +63,7 @@
7963
},
8064
"type": "array",
8165
"uniqueItems": true,
82-
"order": 9
66+
"order": 7
8367
}
8468
},
8569
"required": ["client_id", "client_secret", "refresh_token"],

airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/spec.yaml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,6 @@ connectionSpecification:
4646
type: string
4747
default: NA
4848
order: 4
49-
report_wait_timeout:
50-
title: Report Wait Timeout
51-
description: Timeout duration in minutes for Reports. Default is 60 minutes.
52-
default: 60
53-
examples:
54-
- 60
55-
- 120
56-
order: 5
57-
type: integer
58-
report_generation_max_retries:
59-
title: Report Generation Maximum Retries
60-
description:
61-
Maximum retries Airbyte will attempt for fetching report data.
62-
Default is 5.
63-
default: 5
64-
examples:
65-
- 5
66-
- 10
67-
- 15
68-
order: 6
69-
type: integer
7049
start_date:
7150
title: Start Date
7251
description:
@@ -75,14 +54,14 @@ connectionSpecification:
7554
examples:
7655
- "2022-10-10"
7756
- "2022-10-22"
78-
order: 7
57+
order: 5
7958
type: string
8059
profiles:
8160
title: Profile IDs
8261
description:
8362
Profile IDs you want to fetch data for. See <a href="https://advertising.amazon.com/API/docs/en-us/concepts/authorization/profiles">docs</a>
8463
for more details.
85-
order: 8
64+
order: 6
8665
type: array
8766
items:
8867
type: integer
@@ -97,7 +76,7 @@ connectionSpecification:
9776
- archived
9877
type: array
9978
uniqueItems: true
100-
order: 9
79+
order: 7
10180
required:
10281
- client_id
10382
- client_secret

airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/streams/report_streams/report_streams.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from pydantic import BaseModel
2323
from source_amazon_ads.schemas import CatalogModel, MetricsReport, Profile
2424
from source_amazon_ads.streams.common import BasicAmazonAdsStream
25-
from source_amazon_ads.utils import iterate_one_by_one
25+
from source_amazon_ads.utils import get_typed_env, iterate_one_by_one
2626

2727

2828
class RecordType(str, Enum):
@@ -112,14 +112,16 @@ class ReportStream(BasicAmazonAdsStream, ABC):
112112
]
113113

114114
def __init__(self, config: Mapping[str, Any], profiles: List[Profile], authenticator: Oauth2Authenticator):
115+
super().__init__(config, profiles)
115116
self._state = {}
116117
self._authenticator = authenticator
117118
self._session = requests.Session()
118119
self._model = self._generate_model()
119-
self.report_wait_timeout = config.get("report_wait_timeout", 60)
120-
self.report_generation_maximum_retries = config.get("report_generation_max_retries", 5)
121120
self._start_date: Optional[Date] = config.get("start_date")
122-
super().__init__(config, profiles)
121+
# Timeout duration in minutes for Reports. Default is 180 minutes.
122+
self.report_wait_timeout: int = get_typed_env("REPORT_WAIT_TIMEOUT", 180)
123+
# Maximum retries Airbyte will attempt for fetching report data. Default is 5.
124+
self.report_generation_maximum_retries: int = get_typed_env("REPORT_GENERATION_MAX_RETRIES", 5)
123125

124126
@property
125127
def model(self) -> CatalogModel:
@@ -407,7 +409,7 @@ def _download_report(self, report_info: ReportInfo, url: str) -> List[dict]:
407409

408410
def get_error_display_message(self, exception: BaseException) -> Optional[str]:
409411
if isinstance(exception, ReportGenerationInProgress):
410-
return f'Report(s) generation time took more than {self.report_wait_timeout} minutes, please increase the "report_wait_timeout" parameter in configuration.'
412+
return f"Report(s) generation time took more than {self.report_wait_timeout} minutes and failed because of Amazon API issues. Please wait some time and run synchronization again."
411413
return super().get_error_display_message(exception)
412414

413415
def _get_response_error_details(self, response) -> Optional[str]:

airbyte-integrations/connectors/source-amazon-ads/source_amazon_ads/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
33
#
44

5+
import logging
6+
import os
7+
from typing import Union
8+
9+
logger = logging.getLogger("airbyte")
10+
511

612
def iterate_one_by_one(*iterables):
713
iterables = list(iterables)
@@ -13,3 +19,14 @@ def iterate_one_by_one(*iterables):
1319
pass
1420
else:
1521
iterables.append(iterable)
22+
23+
24+
def get_typed_env(name: str, default: Union[str, int]) -> Union[str, int]:
25+
convert = type(default)
26+
assert convert in [str, int]
27+
value = os.environ.get(name, default)
28+
try:
29+
return convert(value)
30+
except ValueError:
31+
logger.warning(f"Cannot convert environment variable {name}={value!r} to type {convert}")
32+
return default

airbyte-integrations/connectors/source-amazon-ads/unit_tests/test_report_streams.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def test_display_report_stream_init_too_many_requests(mocker, config):
244244
),
245245
(
246246
[
247-
(lambda x: x > 5, None, "2021-01-02 04:04:05"),
247+
(lambda x: x > 5, None, "2021-01-02 06:04:05"),
248248
],
249249
ReportGenerationInProgress,
250250
),
@@ -259,11 +259,11 @@ def test_display_report_stream_init_too_many_requests(mocker, config):
259259
(
260260
[
261261
(lambda x: True, "FAILURE", None),
262-
(lambda x: x >= 10, None, "2021-01-02 04:04:05"),
263-
(lambda x: x >= 15, None, "2021-01-02 05:04:05"),
264-
(lambda x: x >= 20, None, "2021-01-02 06:04:05"),
265-
(lambda x: x >= 25, None, "2021-01-02 07:04:05"),
266-
(lambda x: x >= 30, None, "2021-01-02 08:04:05"),
262+
(lambda x: x >= 10, None, "2021-01-02 06:04:05"),
263+
(lambda x: x >= 15, None, "2021-01-02 09:04:05"),
264+
(lambda x: x >= 20, None, "2021-01-02 12:04:05"),
265+
(lambda x: x >= 25, None, "2021-01-02 15:04:05"),
266+
(lambda x: x >= 30, None, "2021-01-02 18:04:05"),
267267
],
268268
ReportGenerationFailure,
269269
),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
from source_amazon_ads.utils import get_typed_env
6+
7+
8+
def test_get_typed_env(monkeypatch):
9+
assert get_typed_env("REPORT_WAIT_TIMEOUT", 180) == 180
10+
assert get_typed_env("BOOLEAN_PARAM", "1") == "1"
11+
assert get_typed_env("STRING_PARAM", "string") == "string"
12+
monkeypatch.setenv("REPORT_WAIT_TIMEOUT", "60")
13+
assert get_typed_env("REPORT_WAIT_TIMEOUT", 180) == 60
14+
monkeypatch.setenv("REPORT_WAIT_TIMEOUT", "60")
15+
assert get_typed_env("REPORT_WAIT_TIMEOUT", "180") == "60"
16+
monkeypatch.setenv("REPORT_WAIT_TIMEOUT", "string")
17+
assert get_typed_env("REPORT_WAIT_TIMEOUT", 180) == 180

docs/integrations/sources/amazon-ads.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ Information about expected report generation waiting time you may find [here](ht
9191

9292
| Version | Date | Pull Request | Subject |
9393
|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------|
94-
| 0.1.24 | 2022-10-19 | [17475](https://github.com/airbytehq/airbyte/pull/17475) | Add filters for state on brand, product and display campaigns |
94+
| 0.1.25 | 2022-11-08 | [18985](https://github.com/airbytehq/airbyte/pull/18985) | Remove "report_wait_timeout", "report_generation_max_retries" from config |
95+
| 0.1.24 | 2022-10-19 | [17475](https://github.com/airbytehq/airbyte/pull/17475) | Add filters for state on brand, product and display campaigns |
9596
| 0.1.23 | 2022-09-06 | [16342](https://github.com/airbytehq/airbyte/pull/16342) | Add attribution reports |
9697
| 0.1.22 | 2022-09-28 | [17304](https://github.com/airbytehq/airbyte/pull/17304) | Migrate to per-stream state. |
9798
| 0.1.21 | 2022-09-27 | [17202](https://github.com/airbytehq/airbyte/pull/17202) | Improved handling if known reporting errors |

0 commit comments

Comments
 (0)