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 Zendesk Support: Replace ZendeskSupportAuditLogsIncrementalSync with low-code #53620

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 79c1aa37-dae3-42ae-b333-d1c105477715
dockerImageTag: 4.6.0
dockerImageTag: 4.7.0-rc.1
dockerRepository: airbyte/source-zendesk-support
documentationUrl: https://docs.airbyte.com/integrations/sources/zendesk-support
githubIssueLabel: source-zendesk-support
Expand All @@ -30,6 +30,8 @@ data:
enabled: true
releaseStage: generally_available
releases:
rolloutConfiguration:
enableProgressiveRollout: true
breakingChanges:
1.0.0:
message: "`cursor_field` for `Tickets` stream is changed to `generated_timestamp`"
Expand Down
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 = "4.6.0"
version = "4.7.0-rc.1"
name = "source-zendesk-support"
description = "Source implementation for Zendesk Support."
authors = [ "Airbyte <[email protected]>",]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.

from dataclasses import dataclass
from typing import Any, List, Mapping, MutableMapping, Optional
from typing import Any, List, Mapping

import requests

from airbyte_cdk.sources.declarative.extractors.record_extractor import RecordExtractor
from airbyte_cdk.sources.declarative.incremental import DatetimeBasedCursor
from airbyte_cdk.sources.declarative.requesters.request_option import RequestOptionType
from airbyte_cdk.sources.declarative.types import StreamSlice, StreamState


@dataclass
class ZendeskSupportAuditLogsIncrementalSync(DatetimeBasedCursor):
"""
This class is created for the Audit Logs stream. List with time range is used for record filtering.
"""

def get_request_params(
self,
*,
stream_state: Optional[StreamState] = None,
stream_slice: Optional[StreamSlice] = None,
next_page_token: Optional[Mapping[str, Any]] = None,
) -> Mapping[str, Any]:
option_type = RequestOptionType.request_parameter
options: MutableMapping[str, Any] = {}
if not stream_slice:
return options

# set list with time range
if self.start_time_option and self.start_time_option.inject_into == option_type:
start_time = stream_slice.get(self._partition_field_start.eval(self.config))
options[self.start_time_option.field_name.eval(config=self.config)] = [start_time] # type: ignore # field_name is always casted to an interpolated string
if self.end_time_option and self.end_time_option.inject_into == option_type:
options[self.end_time_option.field_name.eval(config=self.config)].append(
stream_slice.get(self._partition_field_end.eval(self.config))
) # type: ignore # field_name is always casted to an interpolated string
return options


class ZendeskSupportExtractorEvents(RecordExtractor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,27 +241,19 @@ definitions:
requester:
$ref: "#/definitions/retriever/requester"
request_parameters:
filter[created_at][]: "{{ [ stream_interval['start_time'], stream_interval['end_time'] ] if next_page_token is none else '' }}"
sort: "created_at"
paginator:
$ref: "#/definitions/links_next_paginator"
incremental_sync:
class_name: source_zendesk_support.components.ZendeskSupportAuditLogsIncrementalSync
type: CustomIncrementalSync
type: DatetimeBasedCursor
cursor_datetime_formats:
- "%Y-%m-%dT%H:%M:%SZ"
- "%Y-%m-%dT%H:%M:%S%z"
datetime_format: "%Y-%m-%dT%H:%M:%SZ"
cursor_field: "{{ parameters.get('cursor_field', 'updated_at') }}"
start_datetime:
datetime: "{{ config.get('start_date') or day_delta(-3650, '%Y-%m-%dT%H:%M:%SZ') }}"
start_time_option:
inject_into: request_parameter
field_name: "filter[created_at][]"
type: RequestOption
end_time_option:
inject_into: request_parameter
field_name: "filter[created_at][]"
type: RequestOption
$parameters:
name: "audit_logs"
path: "audit_logs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#


from typing import Dict, Optional
from typing import Dict

import pytest
import requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,9 @@
import requests
from source_zendesk_support.components import (
ZendeskSupportAttributeDefinitionsExtractor,
ZendeskSupportAuditLogsIncrementalSync,
ZendeskSupportExtractorEvents,
)

from airbyte_cdk.sources.declarative.requesters.request_option import RequestOptionType


@pytest.mark.parametrize(
"stream_state, stream_slice, next_page_token, expected_params",
[
(
{},
{"start_time": "2022-01-01T00:00:00Z", "end_time": "2022-01-02T00:00:00Z"},
{},
{"start_time_field": ["2022-01-01T00:00:00Z", "2022-01-02T00:00:00Z"]},
),
({}, {}, {}, {}),
],
)
def test_audit_logs_incremental_sync(mocker, stream_state, stream_slice, next_page_token, expected_params):
# Instantiate the incremental sync class
sync = ZendeskSupportAuditLogsIncrementalSync("2021-06-01T00:00:00Z", "updated_at", "%Y-%m-%dT%H:%M:%SZ", {}, {})

# Setup mock for start_time_option.field_name.eval
mock_field_name = mocker.MagicMock()
mock_field_name.eval.return_value = "start_time_field"

mock_start_time_option = mocker.MagicMock()
mock_start_time_option.field_name = mock_field_name
mock_start_time_option.inject_into = RequestOptionType.request_parameter

# Setting up the injected options
sync.start_time_option = mock_start_time_option
sync.end_time_option = mock_start_time_option # Assuming same field_name for simplicity

# Patch eval methods to return appropriate field keys
sync._partition_field_start = mocker.MagicMock()
sync._partition_field_start.eval.return_value = "start_time"
sync._partition_field_end = mocker.MagicMock()
sync._partition_field_end.eval.return_value = "end_time"

# Get the request parameters
params = sync.get_request_params(stream_state=stream_state, stream_slice=stream_slice, next_page_token=next_page_token)

# Assert that params match the expected output
assert params == expected_params, f"Expected params {expected_params}, but got {params}"


@pytest.mark.parametrize(
"response_data, expected_events",
Expand Down
5 changes: 3 additions & 2 deletions docs/integrations/sources/zendesk-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ The Zendesk connector ideally should not run into Zendesk API limitations under

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 4.6.0 | 2024-12-09 | [47939](https://github.com/airbytehq/airbyte/pull/47939) | Add `User Identities` stream |
| 4.5.0 | 2024-12-02 | [48761](https://github.com/airbytehq/airbyte/pull/48761) | Add `Categories` and `Sections` stream |
| 4.7.0-rc.1 | 2025-02-13 | [53620](https://github.com/airbytehq/airbyte/pull/53620) | Replace ZendeskSupportAuditLogsIncrementalSync with low-code DatetimeBasedCursor |
| 4.6.0 | 2024-12-09 | [47939](https://github.com/airbytehq/airbyte/pull/47939) | Add `User Identities` stream |
| 4.5.0 | 2024-12-02 | [48761](https://github.com/airbytehq/airbyte/pull/48761) | Add `Categories` and `Sections` stream |
| 4.4.4 | 2025-02-08 | [51943](https://github.com/airbytehq/airbyte/pull/51943) | Update dependencies |
| 4.4.3 | 2025-02-03 | [52625](https://github.com/airbytehq/airbyte/pull/52625) | Update error message during check for `organization_access_enabled` |
| 4.4.2 | 2025-01-11 | [48309](https://github.com/airbytehq/airbyte/pull/48309) | Starting with this version, the Docker image is now rootless. Please note that this and future versions will not be compatible with Airbyte versions earlier than 0.64 |
Expand Down
Loading