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 Freshdesk: providing the updated_since parameter on the initial sync for Tickets stream #6442

Merged
merged 10 commits into from
Oct 13, 2021

Conversation

vitaliizazmic
Copy link
Contributor

What

By default Freshdesk API only retrieves tickets created within the past 30 days since. The connector should provide the updated_since parameter for the Tickets streams on the initial sync. The pagination logic should probably change to always use update_since instead of only after the first 300 pages are retrieved.

Closes #6133

How

Requested feature is already partially implemented, when state is set. Connector uses updated_since and custom pagination. So for solving issue was made changes:

  1. Added additional parameter to spec for specifying initial update_since value.
  2. Use this value if state isn't presented.

Pre-merge Checklist

  • 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
  • Connector version bumped like described here

@vitaliizazmic vitaliizazmic self-assigned this Sep 24, 2021
@github-actions github-actions bot added the area/connectors Connector related issues label Sep 24, 2021
@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Sep 24, 2021

/test connector=source-freshdesk

🕑 source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1270272735
❌ source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1270272735
🐛

@jrhizor jrhizor temporarily deployed to more-secrets September 24, 2021 14:49 Inactive
@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Sep 24, 2021

/test connector=source-freshdesk

🕑 source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1270341636
✅ source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1270341636
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                       Stmts   Miss  Cover
	 --------------------------------------------------------------
	 base_python/__init__.py                       13      0   100%
	 base_python/catalog_helpers.py                10      6    40%
	 base_python/cdk/__init__.py                    0      0   100%
	 base_python/cdk/abstract_source.py            83     59    29%
	 base_python/cdk/streams/__init__.py            0      0   100%
	 base_python/cdk/streams/auth/__init__.py       0      0   100%
	 base_python/cdk/streams/auth/core.py           8      1    88%
	 base_python/cdk/streams/auth/jwt.py            5      5     0%
	 base_python/cdk/streams/auth/oauth.py         37     26    30%
	 base_python/cdk/streams/auth/token.py          9      4    56%
	 base_python/cdk/streams/core.py               63     32    49%
	 base_python/cdk/streams/exceptions.py         10      2    80%
	 base_python/cdk/streams/http.py               67     33    51%
	 base_python/cdk/streams/rate_limiting.py      30     14    53%
	 base_python/cdk/utils/__init__.py              0      0   100%
	 base_python/cdk/utils/casing.py                4      0   100%
	 base_python/client.py                         56     33    41%
	 base_python/entrypoint.py                     70     56    20%
	 base_python/integration.py                    52     25    52%
	 base_python/logger.py                         33     19    42%
	 base_python/schema_helpers.py                 56     41    27%
	 base_python/source.py                         51     34    33%
	 main_dev.py                                    3      3     0%
	 --------------------------------------------------------------
	 TOTAL                                        660    393    40%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                           Stmts   Miss  Cover
	 --------------------------------------------------
	 main_dev.py                        6      6     0%
	 source_freshdesk/__init__.py       2      0   100%
	 source_freshdesk/api.py          194     89    54%
	 source_freshdesk/client.py        38     10    74%
	 source_freshdesk/errors.py         8      0   100%
	 source_freshdesk/source.py         4      0   100%
	 source_freshdesk/utils.py         42     23    45%
	 --------------------------------------------------
	 TOTAL                            294    128    56%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                           Stmts   Miss  Cover
	 --------------------------------------------------
	 main_dev.py                        6      6     0%
	 source_freshdesk/__init__.py       2      0   100%
	 source_freshdesk/api.py          194     78    60%
	 source_freshdesk/client.py        38     18    53%
	 source_freshdesk/errors.py         8      0   100%
	 source_freshdesk/source.py         4      0   100%
	 source_freshdesk/utils.py         42      2    95%
	 --------------------------------------------------
	 TOTAL                            294    104    65%

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets September 24, 2021 15:09 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets September 24, 2021 15:10 Inactive
@CLAassistant
Copy link

CLAassistant commented Sep 27, 2021

CLA assistant check
All committers have signed the CLA.

"tickets_updated_since": {
"title": "Tickets updated since",
"description": "By default, only tickets that have been created within the past 30 days will be returned. For older tickets, use this parameter",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just "format": "date-time"?

@@ -48,8 +48,10 @@


class Client(BaseClient):
def __init__(self, domain, api_key, requests_per_minute: int = None):
self._api = API(domain=domain, api_key=api_key, requests_per_minute=requests_per_minute)
def __init__(self, domain, api_key, requests_per_minute: int = None, tickets_updated_since: str = None):
Copy link
Contributor

@keu keu Sep 28, 2021

Choose a reason for hiding this comment

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

pass array of ticket_ids instead

Copy link
Contributor

@keu keu left a comment

Choose a reason for hiding this comment

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

see comments

@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Sep 30, 2021

/test connector=source-freshdesk

🕑 source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1291378507
✅ source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1291378507
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                       Stmts   Miss  Cover
	 --------------------------------------------------------------
	 base_python/__init__.py                       13      0   100%
	 base_python/catalog_helpers.py                10      6    40%
	 base_python/cdk/__init__.py                    0      0   100%
	 base_python/cdk/abstract_source.py            83     59    29%
	 base_python/cdk/streams/__init__.py            0      0   100%
	 base_python/cdk/streams/auth/__init__.py       0      0   100%
	 base_python/cdk/streams/auth/core.py           8      1    88%
	 base_python/cdk/streams/auth/jwt.py            5      5     0%
	 base_python/cdk/streams/auth/oauth.py         37     26    30%
	 base_python/cdk/streams/auth/token.py          9      4    56%
	 base_python/cdk/streams/core.py               63     32    49%
	 base_python/cdk/streams/exceptions.py         10      2    80%
	 base_python/cdk/streams/http.py               67     33    51%
	 base_python/cdk/streams/rate_limiting.py      30     14    53%
	 base_python/cdk/utils/__init__.py              0      0   100%
	 base_python/cdk/utils/casing.py                4      0   100%
	 base_python/client.py                         56     33    41%
	 base_python/entrypoint.py                     70     56    20%
	 base_python/integration.py                    52     25    52%
	 base_python/logger.py                         33     19    42%
	 base_python/schema_helpers.py                 56     41    27%
	 base_python/source.py                         51     34    33%
	 main_dev.py                                    3      3     0%
	 --------------------------------------------------------------
	 TOTAL                                        660    393    40%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                           Stmts   Miss  Cover
	 --------------------------------------------------
	 main_dev.py                        6      6     0%
	 source_freshdesk/__init__.py       2      0   100%
	 source_freshdesk/api.py          194     89    54%
	 source_freshdesk/client.py        38     10    74%
	 source_freshdesk/errors.py         8      0   100%
	 source_freshdesk/source.py         4      0   100%
	 source_freshdesk/utils.py         42     23    45%
	 --------------------------------------------------
	 TOTAL                            294    128    56%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                           Stmts   Miss  Cover
	 --------------------------------------------------
	 main_dev.py                        6      6     0%
	 source_freshdesk/__init__.py       2      0   100%
	 source_freshdesk/api.py          194     78    60%
	 source_freshdesk/client.py        38     18    53%
	 source_freshdesk/errors.py         8      0   100%
	 source_freshdesk/source.py         4      0   100%
	 source_freshdesk/utils.py         42      2    95%
	 --------------------------------------------------
	 TOTAL                            294    104    65%

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets September 30, 2021 14:08 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets September 30, 2021 14:10 Inactive
params = {**params, **self._state_params()}
state_params = self._state_params()
if not state_params and self._api.start_date:
params["updated_since"] = pendulum.parse(self._api.start_date)
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't you parse it in the source?

@@ -326,7 +333,10 @@ def get_tickets(
def read(self, getter: Callable, params: Mapping[str, Any] = None) -> Iterator:
"""Read using getter, patched to respect current state"""
params = params or {}
params = {**params, **self._state_params()}
state_params = self._state_params()
Copy link
Contributor

Choose a reason for hiding this comment

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

move this logic to state params

Comment on lines 128 to 131
@property
def start_date(self):
return self._start_date

Copy link
Contributor

Choose a reason for hiding this comment

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

no use

Comment on lines 27 to 30
"title": "Tickets updated since",
"description": "By default, only tickets that have been created within the past 30 days will be returned. For older tickets, set start date for syncing",
"format": "date-time",
"examples": ["2020-12-01T00:00:00Z"]
Copy link
Contributor

Choose a reason for hiding this comment

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

regex to validate datetime format? maybe

Copy link
Contributor

@keu keu left a comment

Choose a reason for hiding this comment

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

see comments

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 1, 2021 09:48 Inactive
@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 1, 2021 10:04 Inactive
@vitaliizazmic vitaliizazmic requested a review from keu October 1, 2021 10:05
@@ -22,6 +22,13 @@
"title": "Requests per minute",
"type": "integer",
"description": "Number of requests per minute that this source allowed to use."
},
"start_date": {
"title": "Tickets updated since",
Copy link
Contributor

Choose a reason for hiding this comment

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

So this option is only used for tickets? If so, the title should be Tickets lookback window and param name tickets_lookback_window

},
"start_date": {
"title": "Tickets updated since",
"description": "By default, only tickets that have been created within the past 30 days will be returned. For older tickets, set start date for syncing",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"description": "By default, only tickets that have been created within the past 30 days will be returned. For older tickets, set start date for syncing",
"description": "By default, only tickets that have been created within the past 30 days will be returned. Set this parameter to override that value",

@@ -255,6 +258,13 @@ def list(self, fields: Sequence[str] = None) -> Iterator[dict]:
class TicketsAPI(IncrementalStreamAPI):
call_credit = 3 # each include consumes 2 additional credits

def _state_params(self) -> Mapping[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

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

is this applicable only for tickets? why not apply to all incremental streams? (just asking, not sure what the APi supports)

Copy link
Contributor

@keu keu Oct 5, 2021

Choose a reason for hiding this comment

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

@sherifnada , @vitaliizazmic
it is a good question, I can think about

  • users that want to sync only specific tickets (because of the size of stream?? mb)
  • and users that want to sync everything after a specific date

so both usages are possible, the general start_date will satisfy the second scenario.
To achieve also first one user will need to sync all streams except tickets in full_refresh mode and then enable incremental.
So, yes, we can probably introduce start_date for all incremental streams

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sherifnada @keu I've checked API documentation and Source. Freshdesk API doesn't have ability to filter most of streams. Almost all incremental streams use full refresh syncing and than filter records on our side. But contacts can be filtered by _updated_since, Satisfaction Ratings by created_since, Time Entries by executed_after. Should I implement start_date for this streams?

Copy link
Contributor

Choose a reason for hiding this comment

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

if they also have a 30 day max by default, then I would say we should implement it

Copy link
Contributor

Choose a reason for hiding this comment

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

TimeEntries, Contacts and Companies support real increment, I'm not sure about Satisfaction Ratings as it is not clear if records can be updated, it definitely has ts_updated column, but can it be different from ts_created? I don't know.
taking into account that TimeEntries related to tickets I think it worth to make general start_date config, and not just for tickets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sherifnada only Tickets has this restriction.

Copy link
Contributor

Choose a reason for hiding this comment

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

upon discussion with @vitaliizazmic we agreed to add start_date to the following incremental streams:

  • contacts
  • tickets
  • companies
  • satisfaction ratings

the default value is now - 30 days

we will always use updated_since parameters in tickets streams (because old logic rely on created tickets, not updated, which break dependant streams - conversations)

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 13, 2021 12:46 Inactive
# Since this logic rely not on updated tickets, it can break tickets dependant streams - conversations.
# So updated_since parameter will be always used in tickets streams. And start_date will be used too
# with default value 30 days look back.
self._start_date = pendulum.parse(start_date) if start_date else pendulum.now().add(days=-30)
Copy link
Contributor

@keu keu Oct 13, 2021

Choose a reason for hiding this comment

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

Suggested change
self._start_date = pendulum.parse(start_date) if start_date else pendulum.now().add(days=-30)
self._start_date = pendulum.parse(start_date) if start_date else pendulum.now() - duration(days=30)

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 13, 2021 14:09 Inactive
@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Oct 13, 2021

/test connector=source-freshdesk

🕑 source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1337861717
✅ source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1337861717
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                       Stmts   Miss  Cover
	 --------------------------------------------------------------
	 base_python/__init__.py                       13      0   100%
	 base_python/catalog_helpers.py                10      6    40%
	 base_python/cdk/__init__.py                    0      0   100%
	 base_python/cdk/abstract_source.py            83     59    29%
	 base_python/cdk/streams/__init__.py            0      0   100%
	 base_python/cdk/streams/auth/__init__.py       0      0   100%
	 base_python/cdk/streams/auth/core.py           8      1    88%
	 base_python/cdk/streams/auth/jwt.py            5      5     0%
	 base_python/cdk/streams/auth/oauth.py         37     26    30%
	 base_python/cdk/streams/auth/token.py          9      4    56%
	 base_python/cdk/streams/core.py               63     32    49%
	 base_python/cdk/streams/exceptions.py         10      2    80%
	 base_python/cdk/streams/http.py               67     33    51%
	 base_python/cdk/streams/rate_limiting.py      30     14    53%
	 base_python/cdk/utils/__init__.py              0      0   100%
	 base_python/cdk/utils/casing.py                4      0   100%
	 base_python/client.py                         56     33    41%
	 base_python/entrypoint.py                     70     56    20%
	 base_python/integration.py                    52     25    52%
	 base_python/logger.py                         33     19    42%
	 base_python/schema_helpers.py                 56     41    27%
	 base_python/source.py                         51     34    33%
	 main_dev.py                                    3      3     0%
	 --------------------------------------------------------------
	 TOTAL                                        660    393    40%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                           Stmts   Miss  Cover
	 --------------------------------------------------
	 main_dev.py                        6      6     0%
	 source_freshdesk/__init__.py       2      0   100%
	 source_freshdesk/api.py          189     85    55%
	 source_freshdesk/client.py        38     10    74%
	 source_freshdesk/errors.py         8      0   100%
	 source_freshdesk/source.py         4      0   100%
	 source_freshdesk/utils.py         42     23    45%
	 --------------------------------------------------
	 TOTAL                            289    124    57%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                           Stmts   Miss  Cover
	 --------------------------------------------------
	 main_dev.py                        6      6     0%
	 source_freshdesk/__init__.py       2      0   100%
	 source_freshdesk/api.py          189     74    61%
	 source_freshdesk/client.py        38     18    53%
	 source_freshdesk/errors.py         8      0   100%
	 source_freshdesk/source.py         4      0   100%
	 source_freshdesk/utils.py         42      2    95%
	 --------------------------------------------------
	 TOTAL                            289    100    65%

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 13, 2021 14:17 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets October 13, 2021 14:19 Inactive
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Oct 13, 2021
@vitaliizazmic
Copy link
Contributor Author

vitaliizazmic commented Oct 13, 2021

/publish connector=connectors/source-freshdesk

🕑 connectors/source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1337939169
✅ connectors/source-freshdesk https://github.com/airbytehq/airbyte/actions/runs/1337939169

@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 13, 2021 14:35 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets October 13, 2021 14:37 Inactive
@vitaliizazmic vitaliizazmic temporarily deployed to more-secrets October 13, 2021 14:49 Inactive
@vitaliizazmic vitaliizazmic merged commit 74fecdd into master Oct 13, 2021
@vitaliizazmic vitaliizazmic deleted the vitalii/6133_freshdesk_return_all_tickets branch October 13, 2021 15:20
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 connectors/source/freshdesk connectors/sources-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Freshdesk Source only returns tickets created within the past 30 days
7 participants