Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): add conversation, task, sla and approval tables to freshservice (#109108)

Tom Owersceace69fd989
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 51b520f64aee..46f9dc3a0427 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -3397,18 +3397,18 @@ Note: The `/api/selector/\*` family is a set of ~18 small lookup collections (al
## Freshservice — gaps
-Today (24): `agent_groups`, `agent_roles`, `agents`, `asset_types`, `assets`, `changes`, `contract_types`, `contracts`, `departments`, `locations`, `problems`, `products`, `purchase_orders`, `relationship_types`, `relationships`, `releases`, `requester_groups`, `requesters`, `software`, `software_installations`, `software_users`, `ticket_time_entries`, `tickets`, `vendors`
+Today (31): `agent_groups`, `agent_roles`, `agents`, `approvals`, `asset_types`, `assets`, `change_tasks`, `changes`, `contract_types`, `contracts`, `departments`, `locations`, `problem_tasks`, `problems`, `products`, `purchase_orders`, `relationship_types`, `relationships`, `release_tasks`, `releases`, `requester_groups`, `requesters`, `sla_policies`, `software`, `software_installations`, `software_users`, `ticket_conversations`, `ticket_tasks`, `ticket_time_entries`, `tickets`, `vendors`
Diffed against: <https://api.freshservice.com/>
-- [ ] `tickets/{id}/conversations` — the actual reply and note bodies on every ticket — required for any response-content or agent-activity analysis (high)
+- [x] `tickets/{id}/conversations` — the actual reply and note bodies on every ticket — required for any response-content or agent-activity analysis (high) — synced as `ticket_conversations`
- [x] `tickets/{id}/time_entries` — time tracked per ticket, the basis of effort and cost-per-ticket reporting (high)
- [x] `contracts (+ contract_types lookup)` — asset/vendor contracts with cost and renewal dates; contract_types resolves the type ID carried on each contract (high)
- [x] `applications/{id}/users and /installations (software users, software installations)` — membership tables joining the software we already sync to users and devices — license utilization is impossible without them (high)
- [x] `assets/{id}/relationships (+ relationship_types lookup)` — the CMDB dependency graph plus the lookup that names each relationship type (high) — synced through the account-wide `/api/v2/relationships` listing, which returns the same edges without fanning out per asset
-- [ ] `sla_policies` — lookup that resolves the SLA policy ID on tickets into targets and escalation rules (medium)
-- [ ] `tickets/{id}/tasks (and problem/change/release tasks)` — sub-task breakdown and completion state under each ticket (medium)
-- [ ] `approvals` — account-wide approval records with approver, state and timestamps — the service-request bottleneck metric (medium)
+- [x] `sla_policies` — lookup that resolves the SLA policy ID on tickets into targets and escalation rules (medium)
+- [x] `tickets/{id}/tasks (and problem/change/release tasks)` — sub-task breakdown and completion state under each ticket (medium) — synced as `ticket_tasks`, `problem_tasks`, `change_tasks` and `release_tasks`
+- [x] `approvals` — account-wide approval records with approver, state and timestamps — the service-request bottleneck metric (medium) — the listing needs a filter beyond `parent`, so it is swept once per ticket/change module and approval status
- [ ] `alerts (+ alert logs)` — alert-management records that precede incidents; logs give the state transition history (medium)
- [ ] `service_catalog/items (+ service_categories lookup)` — resolves what was actually requested in each service request, and the category lookup (medium)
- [ ] `tickets/{id}/csat_response` — satisfaction score per ticket — the headline support quality metric (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/canonical_descriptions.py
index dc91669c67ba..831a51fe88ee 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/canonical_descriptions.py
@@ -362,4 +362,121 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
custom_fields="Values of the account's custom time-entry fields.",
),
},
+ "ticket_conversations": {
+ "description": "A reply or note on a ticket.",
+ "docs_url": "https://api.freshservice.com/#conversations",
+ "columns": _columns(
+ ticket_id="ID of the ticket the conversation belongs to.",
+ user_id="ID of the user who created the conversation.",
+ body="Content of the conversation, in HTML.",
+ body_text="Content of the conversation, in plain text.",
+ incoming="Whether the conversation was created by an outside email to the ticket.",
+ private="Whether the conversation is a private note.",
+ source="Source of the conversation, e.g. reply, note or email.",
+ support_email="Support email address the reply was sent from.",
+ from_email="Email address the conversation was sent from.",
+ to_emails="Email addresses the conversation was sent to.",
+ cc_emails="Email addresses copied on the conversation.",
+ bcc_emails="Email addresses blind-copied on the conversation.",
+ attachments="Files attached to the conversation.",
+ ),
+ },
+ "ticket_tasks": {
+ "description": "A task that breaks down the work on a ticket.",
+ "docs_url": "https://api.freshservice.com/#ticket_task_attributes",
+ "columns": _columns(
+ ticket_id="ID of the ticket the task belongs to, injected from the parent ticket.",
+ agent_id="ID of the agent the task is assigned to.",
+ group_id="ID of the agent group the task is assigned to.",
+ status="Status of the task: 1 Open, 2 In Progress, 3 Completed, 4 Blocked.",
+ due_date="Time by which the task is due.",
+ notify_before="Seconds before the due date at which a reminder is sent.",
+ title="Title of the task.",
+ description="Description of the task.",
+ closed_at="Time at which the task was closed.",
+ workspace_id="ID of the workspace the task belongs to.",
+ ),
+ },
+ "problem_tasks": {
+ "description": "A task that breaks down the work on a problem.",
+ "docs_url": "https://api.freshservice.com/#problem_task_attributes",
+ "columns": _columns(
+ problem_id="ID of the problem the task belongs to, injected from the parent problem.",
+ agent_id="ID of the agent the task is assigned to.",
+ group_id="ID of the agent group the task is assigned to.",
+ status="Status of the task: 1 Open, 2 In Progress, 3 Completed, 4 Blocked.",
+ due_date="Time by which the task is due.",
+ notify_before="Seconds before the due date at which a reminder is sent.",
+ title="Title of the task.",
+ description="Description of the task.",
+ closed_at="Time at which the task was closed.",
+ workspace_id="ID of the workspace the task belongs to.",
+ ),
+ },
+ "change_tasks": {
+ "description": "A task that breaks down the work on a change.",
+ "docs_url": "https://api.freshservice.com/#change_task_attributes",
+ "columns": _columns(
+ change_id="ID of the change the task belongs to, injected from the parent change.",
+ agent_id="ID of the agent the task is assigned to.",
+ group_id="ID of the agent group the task is assigned to.",
+ status="Status of the task: 1 Open, 2 In Progress, 3 Completed, 4 Blocked.",
+ due_date="Time by which the task is due.",
+ notify_before="Seconds before the due date at which a reminder is sent.",
+ title="Title of the task.",
+ description="Description of the task.",
+ closed_at="Time at which the task was closed.",
+ workspace_id="ID of the workspace the task belongs to.",
+ ),
+ },
+ "release_tasks": {
+ "description": "A task that breaks down the work on a release.",
+ "docs_url": "https://api.freshservice.com/#release_task_attributes",
+ "columns": _columns(
+ release_id="ID of the release the task belongs to, injected from the parent release.",
+ agent_id="ID of the agent the task is assigned to.",
+ group_id="ID of the agent group the task is assigned to.",
+ status="Status of the task: 1 Open, 2 In Progress, 3 Completed, 4 Blocked.",
+ due_date="Time by which the task is due.",
+ notify_before="Seconds before the due date at which a reminder is sent.",
+ title="Title of the task.",
+ description="Description of the task.",
+ closed_at="Time at which the task was closed.",
+ workspace_id="ID of the workspace the task belongs to.",
+ ),
+ },
+ "sla_policies": {
+ "description": "A service level agreement policy that sets response and resolution targets for tickets.",
+ "docs_url": "https://api.freshservice.com/#sla-policies",
+ "columns": _columns(
+ name="Name of the SLA policy.",
+ description="Short description of the SLA policy.",
+ position="Rank of the SLA policy among the other SLA policies.",
+ is_default="Whether this is the default SLA policy.",
+ active="Whether the SLA policy is active.",
+ deleted="Whether the SLA policy is deleted.",
+ sla_targets="Response and resolution targets, in seconds, for each ticket priority.",
+ applicable_to="Conditions that select the tickets the SLA policy applies to.",
+ escalation="Escalation rules for response and resolution breaches.",
+ workspace_id="ID of the workspace the SLA policy belongs to.",
+ ),
+ },
+ "approvals": {
+ "description": "An approval request on a ticket or change.",
+ "docs_url": "https://api.freshservice.com/#approvals",
+ "columns": _columns(
+ parent="Module of the record the approval is for: ticket or change.",
+ parent_id="ID of the ticket or change the approval is for.",
+ approver_id="User ID of the approver.",
+ approver_name="Name of the approver.",
+ approval_type="Approval rule: 1 Everyone, 2 Anyone, 3 Majority, 4 First Responder.",
+ level="Level of the approval in the approval chain.",
+ user_id="ID of the user who requested the approval.",
+ user_name="Name of the user who requested the approval.",
+ approval_status="Status of the approval: requested, approved, rejected or cancelled.",
+ approval_group="Approval group the approval belongs to.",
+ delegatee="User the approval is delegated to.",
+ latest_remark="Latest remark left on the approval.",
+ ),
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/freshservice.py b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/freshservice.py
index a765f4ac930d..4a0e11fe9bd3 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/freshservice.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/freshservice.py
@@ -1,4 +1,4 @@
-from collections.abc import Iterable
+from collections.abc import Iterable, Iterator
from datetime import UTC, date, datetime
from typing import Any, Optional, cast
@@ -16,12 +16,15 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
HeaderLinkPaginator,
+ PageNumberPaginator,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ClientConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.freshservice.settings import (
+ APPROVAL_PARENTS,
+ APPROVAL_STATUSES,
FRESHSERVICE_ENDPOINTS,
FreshserviceEndpointConfig,
)
@@ -38,7 +41,8 @@ class FreshserviceResumeConfig:
# Top-level endpoints resume from the opaque Link-header `next` URL.
next_url: Optional[str] = None
# Fan-out endpoints resume by parent: the child paths already swept, the one in progress,
- # and that path's paginator state — see `common.rest_source.__init__`.
+ # and that path's paginator state — see `common.rest_source.__init__`. The approvals sweep
+ # reuses these fields for its "<parent>:<status>" slices.
completed: Optional[list[str]] = None
current: Optional[str] = None
child_state: Optional[dict[str, Any]] = None
@@ -205,6 +209,61 @@ def _fanout_source(
return _make_source_response(config, lambda: dependent_resource)
+def _approvals_source(
+ config: FreshserviceEndpointConfig,
+ domain: str,
+ api_key: str,
+ team_id: int,
+ job_id: str,
+ resumable_source_manager: ResumableSourceManager[FreshserviceResumeConfig],
+) -> SourceResponse:
+ resume = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None
+ completed: list[str] = list(resume.completed or []) if resume else []
+ current = resume.current if resume else None
+ current_state = resume.child_state if resume else None
+
+ def items() -> Iterator[Any]:
+ for parent in APPROVAL_PARENTS:
+ for status in APPROVAL_STATUSES:
+ slice_key = f"{parent}:{status}"
+ if slice_key in completed:
+ continue
+
+ def save_checkpoint(state: Optional[dict[str, Any]], slice_key: str = slice_key) -> None:
+ if state:
+ resumable_source_manager.save_state(
+ FreshserviceResumeConfig(completed=list(completed), current=slice_key, child_state=state)
+ )
+
+ rest_config: RESTAPIConfig = {
+ "client": _client_config(domain, api_key),
+ "resources": [
+ {
+ "name": config.name,
+ "endpoint": {
+ "path": config.path,
+ "params": {"parent": parent, "status": status},
+ "data_selector": config.data_key,
+ # The approvals docs only describe a `page` param, not Link headers.
+ "paginator": PageNumberPaginator(base_page=1),
+ },
+ }
+ ],
+ }
+ yield from rest_api_resource(
+ rest_config,
+ team_id,
+ job_id,
+ None,
+ resume_hook=save_checkpoint,
+ initial_paginator_state=current_state if slice_key == current else None,
+ )
+ completed.append(slice_key)
+ resumable_source_manager.save_state(FreshserviceResumeConfig(completed=list(completed)))
+
+ return _make_source_response(config, items)
+
+
def freshservice_source(
api_key: str,
domain: str,
@@ -220,6 +279,9 @@ def freshservice_source(
if config.fanout is not None:
return _fanout_source(config, domain, api_key, team_id, job_id, resumable_source_manager)
+ if endpoint == "approvals":
+ return _approvals_source(config, domain, api_key, team_id, job_id, resumable_source_manager)
+
return _top_level_source(
config,
domain,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/settings.py
index 49c41465527e..618f53ba76fb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/settings.py
@@ -16,7 +16,7 @@ PER_PAGE = 100
# entries has to visit every ticket, not just the recent ones.
_ALL_TICKETS_SINCE = "1970-01-01T00:00:00Z"
-# A ticket or application can be deleted between the parent listing and the child fetch; treat
+# A ticket, problem, change, release or application can be deleted between the parent listing and the child fetch; treat
# that 404 as an empty child rather than failing the whole sweep.
_IGNORE_MISSING_PARENT: list[ResponseAction] = [{"status_code": 404, "action": "ignore"}]
@@ -40,6 +40,23 @@ _TICKET_FANOUT = DependentEndpointConfig(
)
+def _parent_fanout(parent_name: str, parent_id_field: str) -> DependentEndpointConfig:
+ return DependentEndpointConfig(
+ parent_name=parent_name,
+ resolve_param=parent_id_field,
+ resolve_field="id",
+ include_from_parent=["id"],
+ parent_field_renames={"id": parent_id_field},
+ child_response_actions=_IGNORE_MISSING_PARENT,
+ )
+
+
+# The account-wide approvals listing rejects a request that carries only `parent`, so the table
+# is swept one (parent module, status) slice at a time.
+APPROVAL_PARENTS = ("ticket", "change")
+APPROVAL_STATUSES = ("requested", "approved", "rejected", "cancelled")
+
+
# Mutable by choice: instances flow into `build_dependent_resource`'s
# `endpoint_configs: Mapping[str, FanoutEndpointLike]`, and mypy treats a frozen dataclass's
# fields as read-only, which is incompatible with that Protocol's plain attributes.
@@ -116,6 +133,19 @@ FRESHSERVICE_ENDPOINTS: dict[str, FreshserviceEndpointConfig] = {
data_key="releases",
partition_key="created_at",
),
+ "sla_policies": FreshserviceEndpointConfig(
+ name="sla_policies",
+ path="/api/v2/sla_policies",
+ data_key="sla_policies",
+ ),
+ "approvals": FreshserviceEndpointConfig(
+ name="approvals",
+ path="/api/v2/approvals",
+ data_key="approvals",
+ partition_key="created_at",
+ # Ticket and change approvals come from separate modules, so `parent` stays in the key.
+ primary_keys=["parent", "id"],
+ ),
"requesters": FreshserviceEndpointConfig(
name="requesters",
path="/api/v2/requesters",
@@ -236,6 +266,48 @@ FRESHSERVICE_ENDPOINTS: dict[str, FreshserviceEndpointConfig] = {
primary_keys=["ticket_id", "id"],
fanout=_TICKET_FANOUT,
),
+ # Conversation rows already carry `ticket_id`; the injected parent id writes the same value.
+ "ticket_conversations": FreshserviceEndpointConfig(
+ name="ticket_conversations",
+ path="/api/v2/tickets/{ticket_id}/conversations",
+ data_key="conversations",
+ partition_key="created_at",
+ primary_keys=["ticket_id", "id"],
+ fanout=_TICKET_FANOUT,
+ ),
+ # Task ids are numbered per parent record, so the parent id stays in each task table's key.
+ "ticket_tasks": FreshserviceEndpointConfig(
+ name="ticket_tasks",
+ path="/api/v2/tickets/{ticket_id}/tasks",
+ data_key="tasks",
+ partition_key="created_at",
+ primary_keys=["ticket_id", "id"],
+ fanout=_TICKET_FANOUT,
+ ),
+ "problem_tasks": FreshserviceEndpointConfig(
+ name="problem_tasks",
+ path="/api/v2/problems/{problem_id}/tasks",
+ data_key="tasks",
+ partition_key="created_at",
+ primary_keys=["problem_id", "id"],
+ fanout=_parent_fanout("problems", "problem_id"),
+ ),
+ "change_tasks": FreshserviceEndpointConfig(
+ name="change_tasks",
+ path="/api/v2/changes/{change_id}/tasks",
+ data_key="tasks",
+ partition_key="created_at",
+ primary_keys=["change_id", "id"],
+ fanout=_parent_fanout("changes", "change_id"),
+ ),
+ "release_tasks": FreshserviceEndpointConfig(
+ name="release_tasks",
+ path="/api/v2/releases/{release_id}/tasks",
+ data_key="tasks",
+ partition_key="created_at",
+ primary_keys=["release_id", "id"],
+ fanout=_parent_fanout("releases", "release_id"),
+ ),
}
ENDPOINTS = tuple(FRESHSERVICE_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/tests/test_freshservice.py b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/tests/test_freshservice.py
index 5e31546f804c..5b13429632b2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/tests/test_freshservice.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/freshservice/tests/test_freshservice.py
@@ -268,6 +268,11 @@ class TestFanout:
"applications/{}/installations",
),
("ticket_time_entries", "tickets", "time_entries", "ticket_id", "tickets/{}/time_entries"),
+ ("ticket_conversations", "tickets", "conversations", "ticket_id", "tickets/{}/conversations"),
+ ("ticket_tasks", "tickets", "tasks", "ticket_id", "tickets/{}/tasks"),
+ ("problem_tasks", "problems", "tasks", "problem_id", "problems/{}/tasks"),
+ ("change_tasks", "changes", "tasks", "change_id", "changes/{}/tasks"),
+ ("release_tasks", "releases", "tasks", "release_id", "releases/{}/tasks"),
],
)
@mock.patch(CLIENT_SESSION_PATCH)
@@ -345,6 +350,83 @@ class TestFanout:
assert rows == [{"id": 100, "application_id": 9}]
+class TestApprovals:
+ @staticmethod
+ def _slices(snapshots: list[dict[str, Any]]) -> list[tuple[str, str, int]]:
+ return [(s["params"]["parent"], s["params"]["status"], s["params"]["page"]) for s in snapshots]
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_sweeps_every_parent_and_status(self, MockSession) -> None:
+ session = MockSession.return_value
+ snapshots = _wire(
+ session,
+ [
+ _response({"approvals": [{"id": 1, "parent": "ticket"}]}),
+ _response({"approvals": []}),
+ *[_response({"approvals": []}) for _ in range(7)],
+ ],
+ )
+
+ manager = _make_manager()
+ rows = _run("approvals", manager=manager)
+
+ assert rows == [{"id": 1, "parent": "ticket"}]
+ # The listing rejects a request without a second filter, so every status is asked for
+ # separately, and each slice pages until an empty page.
+ assert self._slices(snapshots) == [
+ ("ticket", "requested", 1),
+ ("ticket", "requested", 2),
+ ("ticket", "approved", 1),
+ ("ticket", "rejected", 1),
+ ("ticket", "cancelled", 1),
+ ("change", "requested", 1),
+ ("change", "approved", 1),
+ ("change", "rejected", 1),
+ ("change", "cancelled", 1),
+ ]
+ assert manager.save_state.call_args.args[0].completed == [
+ f"{parent}:{status}"
+ for parent in ("ticket", "change")
+ for status in ("requested", "approved", "rejected", "cancelled")
+ ]
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_resumes_at_the_saved_slice_and_page(self, MockSession) -> None:
+ session = MockSession.return_value
+ snapshots = _wire(
+ session,
+ [
+ _response({"approvals": [{"id": 5, "parent": "change"}]}),
+ _response({"approvals": []}),
+ _response({"approvals": []}),
+ _response({"approvals": []}),
+ ],
+ )
+
+ manager = _make_manager(
+ resume_state=FreshserviceResumeConfig(
+ completed=[
+ "ticket:requested",
+ "ticket:approved",
+ "ticket:rejected",
+ "ticket:cancelled",
+ "change:requested",
+ ],
+ current="change:approved",
+ child_state={"page": 3},
+ )
+ )
+ rows = _run("approvals", manager=manager)
+
+ assert rows == [{"id": 5, "parent": "change"}]
+ assert self._slices(snapshots) == [
+ ("change", "approved", 3),
+ ("change", "approved", 4),
+ ("change", "rejected", 1),
+ ("change", "cancelled", 1),
+ ]
+
+
class TestValidateCredentials:
@pytest.mark.parametrize("status_code", [200, 401, 403])
@mock.patch(FRESHSERVICE_SESSION_PATCH)