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

Fix check connection for earlier date in Google Analytics #8087

Merged

Conversation

augan-rymkhan
Copy link
Contributor

@augan-rymkhan augan-rymkhan commented Nov 18, 2021

What

This error happens If a user enters start_date before the date when Google analytics account had the first data.
In check_connection method the current implementation tries to get data for the first date-slice to check the reading permissions.

For example:

  1. Google Analytics account is created on 2021-02-10
  2. User enters 2021-01-01 as start_date, and windows_in_date = 30
    3. check_connection method sends a request only for the first slice (2021-01-01 - 2021-01-31)
    read_check list is empty because there is no data for that slice. Also there no exception is raised, so check_connection methods returns None
    self.check could not unpack None

How

In check_connection read records using test stream TestStreamConnection, which has pag_size = 1 and overriden request_body_json method where we configure request to fetch records from start_date up to now for testing case.
If it returns some valid records, we assume a user has the right permission to read, otherwise we return validation error message.

Recommended reading order

  1. x.java
  2. y.python

🚨 User Impact 🚨

Are there any breaking changes? If yes, please make sure to include it here and in any changelogs with the 🚨🚨 emoji
What is the end result perceived by the user?

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? 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
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • 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 connector is published, connector added to connector index 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

Updating a connector

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

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.

@github-actions github-actions bot added the area/connectors Connector related issues label Nov 18, 2021
Copy link
Contributor

@avida avida left a comment

Choose a reason for hiding this comment

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

Instead of guessing which slice contains records you could just modify request to specify whole date range from start_date up to now and set pageSize parameter to 1 (instead of 100000). Please read docs for details

@augan-rymkhan
Copy link
Contributor Author

augan-rymkhan commented Nov 18, 2021

@keu @sergei-solonitcyn @avida
It's not related to this issue. Source Google Analytics v4 fails two acceptance tests in master branch.

1st failed test.
When running acceptance test, abnormal state is start_date = 2050-05-01
end_date = current day
We set the earliest date of them to start_date, it will be equal to end_date, i.e. current day
So for that slice we get some records, but the test case assumes that it should not produce records for future date, 2050-05-01.

assert not records, "The sync should produce no records when run with the state with abnormally large values"
E AssertionError: The sync should produce no records when run with the state with abnormally large values

2nd failed test

E AssertionError: Second incremental sync should produce records older or equal to cursor value from the state. Stream: monthly_active_users
E assert '20211118' >= '20211212'

@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 19, 2021 05:33 Inactive
@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 19, 2021 06:02 Inactive
@augan-rymkhan augan-rymkhan self-assigned this Nov 19, 2021
@augan-rymkhan augan-rymkhan linked an issue Nov 19, 2021 that may be closed by this pull request
@augan-rymkhan augan-rymkhan changed the title Arymkhan/fix check connection for earlier date ga Fix check connection for earlier date in Google Analytics Nov 19, 2021
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Nov 19, 2021
@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 19, 2021 08:47 Inactive
@keu
Copy link
Contributor

keu commented Nov 19, 2021

Instead of guessing which slice contains records you could just modify request to specify whole date range from start_date up to now and set pageSize parameter to 1 (instead of 100000). Please read docs for details

but this could be a lot of data and has a high chance of timing out...

@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 19, 2021 10:49 Inactive
@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 19, 2021 11:44 Inactive
@augan-rymkhan
Copy link
Contributor Author

augan-rymkhan commented Nov 19, 2021

Instead of guessing which slice contains records you could just modify request to specify whole date range from start_date up to now and set pageSize parameter to 1 (instead of 100000). Please read docs for details

but this could be a lot of data and has a high chance of timing out...

We set page_size = 1 in TestStreamConnection

@keu maybe, we can try this approach?907795d

Copy link
Contributor

@eliziario eliziario left a comment

Choose a reason for hiding this comment

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

lgtm

@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 23, 2021 06:06 Inactive
@augan-rymkhan augan-rymkhan requested review from sherifnada and Phlair and removed request for Phlair November 23, 2021 11:51
Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

Nicely done with adding the extra unit tests!

@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 24, 2021 04:21 Inactive
@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 24, 2021 04:40 Inactive
@augan-rymkhan
Copy link
Contributor Author

augan-rymkhan commented Nov 24, 2021

/publish connector=connectors/source-google-analytics-v4

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1497946039
❌ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1497946039

@jrhizor jrhizor temporarily deployed to more-secrets November 24, 2021 05:17 Inactive
@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 24, 2021 05:48 Inactive
@augan-rymkhan
Copy link
Contributor Author

augan-rymkhan commented Nov 24, 2021

/publish connector=connectors/source-google-analytics-v4

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1498096139
❌ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1498096139
🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1498096139
❌ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1498096139

@jrhizor jrhizor temporarily deployed to more-secrets November 24, 2021 06:21 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets November 24, 2021 06:36 Inactive
@augan-rymkhan
Copy link
Contributor Author

augan-rymkhan commented Nov 24, 2021

/publish connector=connectors/source-google-analytics-v4 --run-tests=false

Error: Unexpected inputs provided: ["--run-tests"]

@augan-rymkhan
Copy link
Contributor Author

augan-rymkhan commented Nov 24, 2021

/publish connector=connectors/source-google-analytics-v4 run-tests=false

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1498432378
✅ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1498432378

@jrhizor jrhizor temporarily deployed to more-secrets November 24, 2021 08:23 Inactive
@augan-rymkhan augan-rymkhan temporarily deployed to more-secrets November 24, 2021 08:38 Inactive
@augan-rymkhan augan-rymkhan merged commit 82775d6 into master Nov 24, 2021
@augan-rymkhan augan-rymkhan deleted the arymkhan/fix-check-connection-for-earlier-date-ga branch November 24, 2021 09:07
schlattk pushed a commit to schlattk/airbyte that referenced this pull request Jan 4, 2022
…8087)

* Changed tests for `check_connection` method

* Start reading from the latest date-slice to check the reading permissions in `check_connection`

* Fetch records from start_date up to now for testing case

* Add minimal valid records into response_with_records.json

* Changed version of the connector

* formatted codes

* Override stream_slices in Test stream

* return list of date slices inline

* replace valiation msg to "Cannot retrieve data from that view ID"

* formatted code

* fixed error msg in unit tests

* changed version in seed/ yaml files

Co-authored-by: Auganbay <auganenu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entering start date before data in Google analytics gives error
7 participants