Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃帀 Source Amazon Ads: add option to customize look back window value #19491

Merged
merged 25 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
43b1175
add new configurable field
dandpz Nov 16, 2022
66eb96c
update docker image version
dandpz Nov 16, 2022
5e6f604
amazon-ads.md updated
dandpz Nov 16, 2022
f828c2e
Merge branch 'master' into customizable-lookback-window
dandpz Nov 17, 2022
949a002
Merge branch 'master' into customizable-lookback-window
dandpz Nov 22, 2022
bea3214
Merge branch 'master' into customizable-lookback-window
dandpz Dec 1, 2022
d8c46fa
remove unnecessary constant
dandpz Jan 19, 2023
4eecbd0
Merge branch 'master' into customizable-lookback-window
dandpz Jan 19, 2023
b6e74e7
Merge branch 'master' into customizable-lookback-window
dandpz Jan 19, 2023
24244f9
Merge branch 'airbytehq:master' into customizable-lookback-window
dandpz Jan 20, 2023
c0b0f56
rollback changes inside seed files
dandpz Jan 20, 2023
d2386e5
fully revert changes
dandpz Jan 20, 2023
0a04945
pre load lbw default value
dandpz Jan 20, 2023
509da21
fix value access
dandpz Jan 20, 2023
7817006
update config fixture
dandpz Jan 20, 2023
45ce570
Merge branch 'master' into customizable-lookback-window
dandpz Jan 23, 2023
c95ece0
Merge branch 'master' into customizable-lookback-window
dandpz Jan 24, 2023
f6ac47c
Merge branch 'master' into customizable-lookback-window
dandpz Jan 24, 2023
83bf40e
Merge branch 'master' into customizable-lookback-window
dandpz Jan 24, 2023
5eaaa21
Merge branch 'master' into customizable-lookback-window
dandpz Jan 24, 2023
067b981
Merge branch 'master' into customizable-lookback-window
dandpz Jan 25, 2023
868bb74
Merge branch 'master' into customizable-lookback-window
dandpz Jan 25, 2023
88335e3
Merge branch 'master' into customizable-lookback-window
dandpz Jan 26, 2023
eb48a41
auto-bump connector version
octavia-squidington-iii Jan 26, 2023
241b00c
Merge branch 'master' into customizable-lookback-window
marcosmarxm Jan 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
- name: Amazon Ads
sourceDefinitionId: c6b0a29e-1da9-4512-9002-7bfd0cba2246
dockerRepository: airbyte/source-amazon-ads
dockerImageTag: 0.1.27
dockerImageTag: 0.1.28
dandpz marked this conversation as resolved.
Show resolved Hide resolved
documentationUrl: https://docs.airbyte.com/integrations/sources/amazon-ads
icon: amazonads.svg
sourceType: api
Expand Down
12 changes: 11 additions & 1 deletion airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-amazon-ads:0.1.27"
- dockerImage: "airbyte/source-amazon-ads:0.1.28"
dandpz marked this conversation as resolved.
Show resolved Hide resolved
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/amazon-ads"
connectionSpecification:
Expand Down Expand Up @@ -880,6 +880,16 @@
type: "array"
uniqueItems: true
order: 7
look_back_window:
dandpz marked this conversation as resolved.
Show resolved Hide resolved
title: "Look Back Window"
description: "The amount of days to go back in time to get the updated data\
\ from Amazon Ads"
examples:
- 3
- 10
type: "integer"
default: 3
order: 8
required:
- "client_id"
- "client_secret"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]


LABEL io.airbyte.version=0.1.27
LABEL io.airbyte.version=0.1.28
LABEL io.airbyte.name=airbyte/source-amazon-ads
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
"type": "array",
"uniqueItems": true,
"order": 7
},
"look_back_window": {
"title": "Look Back Window",
"description": "The amount of days to go back in time to get the updated data from Amazon Ads",
"default": 3,
"examples": [3, 10],
"order": 8,
"type": "integer"
}
},
"required": ["client_id", "client_secret", "refresh_token"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def _validate_and_transform(self, config: Mapping[str, Any]):
if not config.get("region"):
source_spec = self.spec(logging.getLogger("airbyte"))
config["region"] = source_spec.connectionSpecification["properties"]["region"]["default"]
if not config.get("look_back_window"):
source_spec = self.spec(logging.getLogger("airbyte"))
config["look_back_window"] = source_spec.connectionSpecification["properties"]["look_back_window"]["default"]
return config

def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ connectionSpecification:
type: array
uniqueItems: true
order: 7
look_back_window:
title: "Look Back Window"
description: "The amount of days to go back in time to get the updated data from Amazon Ads"
examples:
- 3
- 10
type: "integer"
default: 3
order: 8
required:
- client_id
- client_secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ class ReportStream(BasicAmazonAdsStream, ABC):
"""

primary_key = ["profileId", "recordType", "reportDate", "updatedAt"]
# Amazon ads updates the data for the next 3 days
LOOK_BACK_WINDOW = 3
# https://advertising.amazon.com/API/docs/en-us/reporting/v2/faq#what-is-the-available-report-history-for-the-version-2-reporting-api
REPORTING_PERIOD = 60
# (Service limits section)
Expand All @@ -118,6 +116,7 @@ def __init__(self, config: Mapping[str, Any], profiles: List[Profile], authentic
self._session = requests.Session()
self._model = self._generate_model()
self._start_date: Optional[Date] = config.get("start_date")
self._look_back_window: int = config["look_back_window"]
# Timeout duration in minutes for Reports. Default is 180 minutes.
self.report_wait_timeout: int = get_typed_env("REPORT_WAIT_TIMEOUT", 180)
# Maximum retries Airbyte will attempt for fetching report data. Default is 5.
Expand Down Expand Up @@ -329,7 +328,7 @@ def get_updated_state(self, current_stream_state: Dict[str, Any], latest_data: M

def _update_state(self, profile: Profile, report_date: str):
report_date = pendulum.from_format(report_date, self.REPORT_DATE_FORMAT).date()
look_back_date = pendulum.today(tz=profile.timezone).date().subtract(days=self.LOOK_BACK_WINDOW - 1)
dandpz marked this conversation as resolved.
Show resolved Hide resolved
look_back_date = pendulum.today(tz=profile.timezone).date().subtract(days=self._look_back_window - 1)
start_date = self.get_start_date(profile, self._state)
updated_state = max(min(report_date, look_back_date), start_date).format(self.REPORT_DATE_FORMAT)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def config():
"client_secret": "test_client_secret",
"refresh_token": "test_refresh",
"region": "NA",
"look_back_window": 3
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def test_check(config_gen):
assert len(responses.calls) == 8
assert url_strip_query(responses.calls[7].request.url) == "https://advertising-api.amazon.com/v2/profiles"

assert command_check(source, config_gen(look_back_window=...)) == AirbyteConnectionStatus(status=Status.SUCCEEDED)


@responses.activate
def test_source_streams(config):
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/amazon-ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Information about expected report generation waiting time you may find [here](ht

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------|
| 0.1.28 | 2023-01-18 | [19491](https://github.com/airbytehq/airbyte/pull/19491) | Add option to customize look back window value
| 0.1.27 | 2023-01-05 | [21082](https://github.com/airbytehq/airbyte/pull/21082) | Fix bug with handling: "Report date is too far in the past." - partial revert of #20662 |
| 0.1.26 | 2022-12-19 | [20662](https://github.com/airbytehq/airbyte/pull/20662) | Fix bug with handling: "Report date is too far in the past." |
| 0.1.25 | 2022-11-08 | [18985](https://github.com/airbytehq/airbyte/pull/18985) | Remove "report_wait_timeout", "report_generation_max_retries" from config |
Expand Down