Skip to content

🐛 Source Orb: fix window request for credit_ledger_entries #36036

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

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-orb/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 7f0455fb-4518-4ec0-b7a3-d808bf8081cc
dockerImageTag: 1.1.1
dockerImageTag: 1.1.2
dockerRepository: airbyte/source-orb
githubIssueLabel: source-orb
icon: orb.svg
Expand Down
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-orb/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = [ "poetry-core>=1.0.0",]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
version = "1.1.1"
version = "1.1.2"
name = "source-orb"
description = "Source implementation for Orb."
authors = [ "Airbyte <[email protected]>",]
Expand Down
17 changes: 10 additions & 7 deletions airbyte-integrations/connectors/source-orb/source_orb/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class Customers(IncrementalOrbStream):
API Docs: https://docs.withorb.com/reference/list-customers
"""

use_cache = True

def path(self, **kwargs) -> str:
return "customers"

Expand Down Expand Up @@ -590,14 +592,11 @@ def enrich_ledger_entries_with_event_data(self, ledger_entries):
# Build up a list of the subset of ledger entries we are expected
# to enrich with event metadata.
event_id_to_ledger_entries = {}
min_created_at_timestamp = pendulum.now()
max_created_at_timestamp = pendulum.now()

for entry in ledger_entries:
maybe_event_id: Optional[str] = entry.get("event_id")
if maybe_event_id:
min_created_at_timestamp = min(min_created_at_timestamp, pendulum.parse(entry["created_at"]))
max_created_at_timestamp = max(max_created_at_timestamp, pendulum.parse(entry["created_at"]))
created_at_timestamp = pendulum.parse(entry.get("created_at", pendulum.now()))
# There can be multiple entries with the same event ID
event_id_to_ledger_entries[maybe_event_id] = event_id_to_ledger_entries.get(maybe_event_id, []) + [entry]

Expand Down Expand Up @@ -628,8 +627,8 @@ def modify_ledger_entry_schema(ledger_entry):
# event_ids to filter on
request_filter_json = {
"event_ids": list(event_id_to_ledger_entries),
"timeframe_start": min_created_at_timestamp.to_iso8601_string(),
"timeframe_end": max_created_at_timestamp.add(minutes=1).to_iso8601_string(),
"timeframe_start": created_at_timestamp.to_iso8601_string(),
"timeframe_end": created_at_timestamp.add(days=30).to_iso8601_string(),
}

# Prepare request with self._session, which should
Expand All @@ -638,7 +637,11 @@ def modify_ledger_entry_schema(ledger_entry):
prepared_request = self._session.prepare_request(requests.Request(**args))
events_response: requests.Response = self._session.send(prepared_request)
# Error for invalid responses
events_response.raise_for_status()
if events_response.status_code != 200:
self.logger.info(request_filter_json)
self.logger.error(events_response.text)
events_response.raise_for_status()

paginated_events_response_body = events_response.json()

if paginated_events_response_body["pagination_metadata"]["has_more"]:
Expand Down
5 changes: 5 additions & 0 deletions docs/integrations/sources/orb.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ In order to capture data that has been updated after creation, please run a peri

The Orb connector should not run into Orb API limitations under normal usage. Please [create an issue](https://github.com/airbytehq/airbyte/issues) if you see any rate limit issues that are not automatically retried successfully.

:::warning
The `credit_ledger_entries` stream will now include `events` data. This upgrade uses the `created_at` timestamps from the `credits` to establish a 30-day timeframe, with the earliest `created_at` as the starting point. This restriction is set by the Orb API.
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nit:
events have always been included in credit_ledger_entries. The start/end date and 30 day limit is new, though.

:::

## Getting started

### Requirements
Expand All @@ -54,6 +58,7 @@ an Orb Account and API Key.

| Version | Date | Pull Request | Subject |
| --- |------------|----------------------------------------------------------| --- |
| 1.1.2 | 2024-03-13 | [x](https://github.com/airbytehq/airbyte/pull/x) | Fix window to 30 days for events query timesframe start and query |
| 1.1.1 | 2024-02-07 | [35005](https://github.com/airbytehq/airbyte/pull/35005) | Pass timeframe_start, timeframe_end to events query |
| 1.1.0 | 2023-03-03 | [24567](https://github.com/airbytehq/airbyte/pull/24567) | Add Invoices incremental stream merged from [#24737](https://github.com/airbytehq/airbyte/pull/24737) |
| 1.0.0 | 2023-02-02 | [21951](https://github.com/airbytehq/airbyte/pull/21951) | Add SubscriptionUsage stream, and made `start_date` a required field |
Expand Down