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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Amazon Seller Partner: Add GET_BRAND_ANALYTICS_SEARCH_TERMS_REPORT report #8179

Conversation

lizdeika
Copy link
Contributor

@lizdeika lizdeika commented Nov 22, 2021

What

Adds GET_BRAND_ANALYTICS_SEARCH_TERMS_REPORT report to Amazon Seller Partner source connector

How

Recommended reading order

🚨 User Impact 🚨

Pre-merge Checklist

Expand the relevant checklist and delete the others.

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the new connector version is published, connector version bumped in the seed directory as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here

@github-actions github-actions bot added the area/connectors Connector related issues label Nov 22, 2021
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Nov 30, 2021
@lizdeika
Copy link
Contributor Author

» python -m pytest integration_tests -p integration_tests.acceptance
Test session starts (platform: darwin, Python 3.9.8, pytest 6.2.5, pytest-sugar 0.9.4)
cachedir: .pytest_cache
rootdir: /Users/lizdeika/Projects/airbyte, configfile: pytest.ini
plugins: sugar-0.9.4, mock-3.6.1, timeout-1.4.2
collecting ... {"type": "LOG", "log": {"level": "INFO", "message": "Docker run: \nspec\ninput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_match_expected_inputs0_0/run_1/input\noutput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_match_expected_inputs0_0/run_1/output"}}

 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestSpec.test_match_expected[inputs0] ✓             11% █▎
 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestSpec.test_required[inputs0] ✓                   22% ██▎
 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestSpec.test_optional[inputs0] ✓                   33% ███▍
 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestSpec.test_has_secret[inputs0] ✓                 44% ████▌
 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestSpec.test_secret_never_in_the_output[inputs0] ✓ 56% █████▋    {"type": "LOG", "log": {"level": "INFO", "message": "Docker run: \nspec\ninput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_oauth_flow_parameters_inp0/run_1/input\noutput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_oauth_flow_parameters_inp0/run_1/output"}}

 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestSpec.test_oauth_flow_parameters[inputs0] ✓      67% ██████▋   {"type": "LOG", "log": {"level": "INFO", "message": "Docker run: \ncheck --config tap_config.json\ninput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_check_inputs0_0/run_1/input\noutput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_check_inputs0_0/run_1/output"}}

 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestConnection.test_check[inputs0] ✓                78% ███████▊  {"type": "LOG", "log": {"level": "INFO", "message": "Docker run: \ndiscover --config tap_config.json\ninput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_discover_inputs0_0/run_1/input\noutput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_discover_inputs0_0/run_1/output"}}

 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestDiscovery.test_discover[inputs0] ✓              89% ████████▉ {"type": "LOG", "log": {"level": "INFO", "message": "Docker run: \ndiscover --config tap_config.json\ninput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_defined_cursors_exist_in_0/run_1/input\noutput: /private/var/folders/pd/rd8643xs7xz4fnhp4f4wlnk40000gn/T/pytest-of-lizdeika/pytest-14/test_defined_cursors_exist_in_0/run_1/output"}}

 airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_core.py::TestDiscovery.test_defined_cursors_exist_in_schema[inputs0] ✓100% ██████████
=================================================================== short test summary info ====================================================================
SKIPPED [1] ../../bases/source-acceptance-test/source_acceptance_test/plugin.py:56: Skipping TestBasicRead.test_read because not found in the config
SKIPPED [1] ../../bases/source-acceptance-test/source_acceptance_test/plugin.py:56: Skipping TestFullRefresh.test_sequential_reads because not found in the config
SKIPPED [1] ../../bases/source-acceptance-test/source_acceptance_test/plugin.py:56: Skipping TestIncremental.test_two_sequential_reads because not found in the config

Results (9.38s):
       9 passed

» python -m pytest integration_tests
Test session starts (platform: darwin, Python 3.9.8, pytest 6.2.5, pytest-sugar 0.9.4)
cachedir: .pytest_cache
rootdir: /Users/lizdeika/Projects/airbyte, configfile: pytest.ini
plugins: sugar-0.9.4, mock-3.6.1, timeout-1.4.2
collecting ...

Results (0.03s):

» python -m pytest unit_tests
Test session starts (platform: darwin, Python 3.9.8, pytest 6.2.5, pytest-sugar 0.9.4)
cachedir: .pytest_cache
rootdir: /Users/lizdeika/Projects/airbyte, configfile: pytest.ini
plugins: sugar-0.9.4, mock-3.6.1, timeout-1.4.2
collecting ...
 airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_should_retry ✓   33% ███▍
 airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_send_request ✓   67% ██████▋   {"type": "LOG", "log": {"level": "INFO", "message": "Backing off _send_request(...) for 5.0s (airbyte_cdk.sources.streams.http.exceptions.DefaultBackoffException)"}}
{"type": "LOG", "log": {"level": "INFO", "message": "Caught retryable error '' after 1 tries. Waiting 5 seconds then retrying..."}}
{"type": "LOG", "log": {"level": "INFO", "message": "Backing off _send_request(...) for 10.0s (airbyte_cdk.sources.streams.http.exceptions.DefaultBackoffException)"}}
{"type": "LOG", "log": {"level": "INFO", "message": "Caught retryable error '' after 2 tries. Waiting 10 seconds then retrying..."}}
{"type": "LOG", "log": {"level": "INFO", "message": "Backing off _send_request(...) for 20.0s (airbyte_cdk.sources.streams.http.exceptions.DefaultBackoffException)"}}
{"type": "LOG", "log": {"level": "INFO", "message": "Caught retryable error '' after 3 tries. Waiting 20 seconds then retrying..."}}
{"type": "LOG", "log": {"level": "INFO", "message": "Backing off _send_request(...) for 40.0s (airbyte_cdk.sources.streams.http.exceptions.DefaultBackoffException)"}}
{"type": "LOG", "log": {"level": "INFO", "message": "Caught retryable error '' after 4 tries. Waiting 40 seconds then retrying..."}}
{"type": "LOG", "log": {"level": "ERROR", "message": "Giving up _send_request(...) after 5 tries (airbyte_cdk.sources.streams.http.exceptions.DefaultBackoffException)"}}

 airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_send_request_backoff_exception ✓100% ██████████
======================================================================= warnings summary =======================================================================
source_amazon_seller_partner/streams.py:144
  /Users/lizdeika/Projects/airbyte/airbyte-integrations/connectors/source-amazon-seller-partner/source_amazon_seller_partner/streams.py:144: DeprecationWarning: Call to deprecated class NoAuth. (Set `authenticator=None` instead) -- Deprecated since version 0.1.20.
    authenticator: HttpAuthenticator = NoAuth(),

.venv/lib/python3.9/site-packages/deprecated/classic.py:173
airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_should_retry
airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_send_request
airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_send_request_backoff_exception
  /Users/lizdeika/Projects/airbyte/airbyte-integrations/connectors/source-amazon-seller-partner/.venv/lib/python3.9/site-packages/deprecated/classic.py:173: DeprecationWarning: Call to deprecated class HttpAuthenticator. (Use requests.auth.AuthBase instead) -- Deprecated since version 0.1.20.
    return old_new1(cls, *args, **kwargs)

airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_should_retry
airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_send_request
airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py::test_reports_stream_send_request_backoff_exception
  /Users/lizdeika/Projects/airbyte/airbyte-integrations/connectors/source-amazon-seller-partner/unit_tests/test_repots_streams_rate_limits.py:29: DeprecationWarning: Call to deprecated class NoAuth. (Set `authenticator=None` instead) -- Deprecated since version 0.1.20.
    authenticator=NoAuth(),

-- Docs: https://docs.pytest.org/en/stable/warnings.html

Results (0.59s):
       3 passed

@lizdeika lizdeika marked this pull request as ready for review November 30, 2021 09:39
@alafanechere
Copy link
Contributor

Hi @lizdeika thanks for your contribution, we'll review it soon!

@harshithmullapudi
Copy link
Contributor

Hey @lizdeika can you rebase this according to master as we have merged #8021

@harshithmullapudi
Copy link
Contributor

Hey @lizdeika what do you think about the above comment ?

@lizdeika
Copy link
Contributor Author

lizdeika commented Dec 9, 2021

@harshithmullapudi I did merge with master and fixed the merge conflicts

@harshithmullapudi
Copy link
Contributor

@lizdeika I was more curious on this

Hey right now if other reports want to use this same parameter it is bit hard so can we change this to format of

report_options = {
  "REPORT_NAME": #dict report options  
}

@lizdeika
Copy link
Contributor Author

lizdeika commented Dec 9, 2021

@harshithmullapudi Can you guide me here, I do not think I understand what changes should I do 😬

@harshithmullapudi
Copy link
Contributor

Ok it's better if I put this way. What if I want different report_options for different report streams?

@lizdeika
Copy link
Contributor Author

@harshithmullapudi Got it! Please take a look at the changes I've made

Copy link
Contributor

@harshithmullapudi harshithmullapudi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small change. Otherwise LGTM

Comment on lines 413 to 432
def _augmented_data(self, report_options) -> Mapping[str, Any]:
if report_options.get("reportPeriod") is None:
return {}
else:
now = pendulum.now("utc")
if report_options["reportPeriod"] == "DAY":
now = now.subtract(days=1)
data_start_time = now.start_of("day")
data_end_time = now.end_of("day")
elif report_options["reportPeriod"] == "WEEK":
now = now.subtract(weeks=1)

# According to report api docs
# dataStartTime must be a Sunday and dataEndTime must be the following Saturday
pendulum.week_starts_at(pendulum.SUNDAY)
pendulum.week_ends_at(pendulum.SATURDAY)

data_start_time = now.start_of("week")
data_end_time = now.end_of("week")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this into some util or a static function as this doesn't have any dependency on the class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this into some util or a static function as this doesn't have any dependency on the class

👍🏽 Annotated it as a static but leaving inside the class because the logic is report specific and not reusable

@lizdeika
Copy link
Contributor Author

@harshithmullapudi I have annotated _augmented_data and parse_documentas static methods. What do you think? :)

@harshithmullapudi harshithmullapudi merged commit 21ff8a2 into airbytehq:master Dec 16, 2021
@lizdeika lizdeika deleted the amazon-seller-partner-GET_BRAND_ANALYTICS_SEARCH_TERMS_REPORT branch December 16, 2021 12:23
schlattk pushed a commit to schlattk/airbyte that referenced this pull request Jan 4, 2022
…PORT report (airbytehq#8179)

* Source Amazon Seller Partner: Add GET_BRAND_ANALYTICS_SEARCH_TERMS_REPORT report

* loads

* fixes and refactors

* docs

* fixes

* Field definitions

* versions

* versions

* refactor report options to scope by REPORT name

* fix _report_data

* 1

* make _augmented_data a static method

* parse_document is static too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants