Skip to content

Commit 50916e7

Browse files
authored
New Desination: Heap Analytics [python cdk] (#20785)
- implement a heap client to load data via the server-side API: https://developers.heap.io/reference/server-side-apis-overview - the connector supports a generic data source, and the api_type determines the output schema. The output schema is dynamic. - users pick the columns that will be loaded to the destination - Consequently, each configured catalog only includes one stream
1 parent f846678 commit 50916e7

File tree

27 files changed

+1845
-0
lines changed

27 files changed

+1845
-0
lines changed

airbyte-config/init/src/main/resources/seed/destination_definitions.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@
160160
documentationUrl: https://docs.airbyte.com/integrations/destinations/pubsub
161161
icon: googlepubsub.svg
162162
releaseStage: alpha
163+
- name: Heap Analytics
164+
destinationDefinitionId: f8e68742-407a-4a3c-99ad-dfd42ae2cba8
165+
dockerRepository: airbyte/destination-heap-analytics
166+
dockerImageTag: 0.1.0
167+
documentationUrl: https://docs.airbyte.com/integrations/destinations/heap-analytics
168+
releaseStage: alpha
163169
- name: Kafka
164170
destinationDefinitionId: 9f760101-60ae-462f-9ee6-b7a9dafd454d
165171
dockerRepository: airbyte/destination-kafka

airbyte-config/init/src/main/resources/seed/destination_specs.yaml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,148 @@
28002800
supportsDBT: false
28012801
supported_destination_sync_modes:
28022802
- "append"
2803+
- dockerImage: "airbyte/destination-heap-analytics:0.1.0"
2804+
spec:
2805+
documentationUrl: "https://docs.airbyte.com/integrations/destinations/heap-analytics"
2806+
connectionSpecification:
2807+
$schema: "http://json-schema.org/draft-07/schema#"
2808+
title: "Heap Analytics Destination Spec"
2809+
type: "object"
2810+
required:
2811+
- "base_url"
2812+
- "app_id"
2813+
- "api"
2814+
additionalProperties: true
2815+
properties:
2816+
app_id:
2817+
order: 0
2818+
type: "string"
2819+
title: "App Id"
2820+
description: "The Environment Id of your Main Profudction project, read\
2821+
\ <a href=\"https://help.heap.io/data-management/data-management-features/projects-environments/\"\
2822+
>the doc</a> to learn more."
2823+
default: "11"
2824+
base_url:
2825+
order: 1
2826+
type: "string"
2827+
title: "Base URL"
2828+
description: "The Base URL for Heap Analytics"
2829+
default: "https://heapanalytics.com"
2830+
examples:
2831+
- "https://heapanalytics.com"
2832+
api:
2833+
order: 2
2834+
type: "object"
2835+
title: "API Type"
2836+
additionalProperties: true
2837+
oneOf:
2838+
- order: 0
2839+
type: "object"
2840+
title: "Track Events"
2841+
required:
2842+
- "api_type"
2843+
- "property_columns"
2844+
- "event_column"
2845+
- "identity_column"
2846+
properties:
2847+
api_type:
2848+
order: 0
2849+
type: "string"
2850+
const: "track"
2851+
property_columns:
2852+
order: 1
2853+
type: "string"
2854+
title: "Property Columns"
2855+
default: "*"
2856+
description: "Please list all columns populated to the properties\
2857+
\ attribute, split by comma(,). It's case sensitive."
2858+
examples:
2859+
- "subject,variation"
2860+
event_column:
2861+
order: 2
2862+
type: "string"
2863+
title: "Event Column"
2864+
description: "Please pick the column populated to the event attribute.\
2865+
\ It's case sensitive."
2866+
examples:
2867+
- "order_name"
2868+
identity_column:
2869+
order: 3
2870+
type: "string"
2871+
title: "Identity Column"
2872+
description: "Please pick the column populated to the identity attribute."
2873+
examples:
2874+
- "email"
2875+
timestamp_column:
2876+
order: 4
2877+
type: "string"
2878+
title: "Identity Column"
2879+
description: "Please pick the column populated to the (optional) timestamp\
2880+
\ attribute. time_now() will be used if missing."
2881+
examples:
2882+
- "updated_at"
2883+
- order: 1
2884+
type: "object"
2885+
title: "Add User Properties"
2886+
required:
2887+
- "api_type"
2888+
- "property_columns"
2889+
- "identity_column"
2890+
properties:
2891+
api_type:
2892+
order: 0
2893+
type: "string"
2894+
const: "add_user_properties"
2895+
property_columns:
2896+
order: 1
2897+
type: "string"
2898+
title: "Property Columns"
2899+
default: "*"
2900+
description: "Please list all columns populated to the properties\
2901+
\ attribute, split by comma(,). It's case sensitive."
2902+
examples:
2903+
- "age,language,profession"
2904+
identity_column:
2905+
order: 3
2906+
type: "string"
2907+
title: "Identity Column"
2908+
description: "Please pick the column populated to the identity attribute."
2909+
examples:
2910+
- "user_id"
2911+
- order: 2
2912+
type: "object"
2913+
title: "Add Account Properties"
2914+
required:
2915+
- "api_type"
2916+
- "property_columns"
2917+
- "account_id_column"
2918+
properties:
2919+
api_type:
2920+
order: 0
2921+
type: "string"
2922+
const: "add_account_properties"
2923+
property_columns:
2924+
order: 1
2925+
type: "string"
2926+
title: "Property Columns"
2927+
default: "*"
2928+
description: "Please list all columns populated to the properties\
2929+
\ attribute, split by comma(,). It's case sensitive."
2930+
examples:
2931+
- "is_in_good_standing,revenue_potential,account_hq,subscription"
2932+
account_id_column:
2933+
order: 3
2934+
type: "string"
2935+
title: "Account ID Column"
2936+
description: "Please pick the column populated to the account_id attribute."
2937+
examples:
2938+
- "company_name"
2939+
supportsIncremental: true
2940+
supportsNormalization: false
2941+
supportsDBT: false
2942+
supported_destination_sync_modes:
2943+
- "append"
2944+
- "append_dedup"
28032945
- dockerImage: "airbyte/destination-kafka:0.1.10"
28042946
spec:
28052947
documentationUrl: "https://docs.airbyte.com/integrations/destinations/kafka"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!Dockerfile
3+
!main.py
4+
!destination_heap_analytics
5+
!setup.py
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM python:3.9.11-alpine3.15 as base
2+
3+
# build and load all requirements
4+
FROM base as builder
5+
WORKDIR /airbyte/integration_code
6+
7+
# upgrade pip to the latest version
8+
RUN apk --no-cache upgrade \
9+
&& pip install --upgrade pip \
10+
&& apk --no-cache add tzdata build-base
11+
12+
13+
COPY setup.py ./
14+
# install necessary packages to a temporary folder
15+
RUN pip install --prefix=/install .
16+
17+
# build a clean environment
18+
FROM base
19+
WORKDIR /airbyte/integration_code
20+
21+
# copy all loaded and built libraries to a pure basic image
22+
COPY --from=builder /install /usr/local
23+
# add default timezone settings
24+
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
25+
RUN echo "Etc/UTC" > /etc/timezone
26+
27+
# bash is installed for more convenient debugging.
28+
RUN apk --no-cache add bash
29+
30+
# copy payload code only
31+
COPY main.py ./
32+
COPY destination_heap_analytics ./destination_heap_analytics
33+
34+
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
35+
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
36+
37+
LABEL io.airbyte.version=0.1.0
38+
LABEL io.airbyte.name=airbyte/destination-heap-analytics
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Heap Analytics Destination
2+
3+
This is the repository for the Heap Analytics destination connector, written in Python.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/destinations/heap-analytics).
5+
6+
## Local development
7+
8+
### Prerequisites
9+
**To iterate on this connector, make sure to complete this prerequisites section.**
10+
11+
#### Minimum Python version required `= 3.7.0`
12+
13+
#### Build & Activate Virtual Environment and install dependencies
14+
15+
From this connector directory, create a virtualenv:
16+
```
17+
python -m venv .venv
18+
```
19+
20+
This will generate a virtual environment for this module in `.venv/`. Make sure this venv is active in your
21+
development environment of choice. To activate it from the terminal, run:
22+
```
23+
source .venv/bin/activate
24+
pip install -r requirements.txt
25+
```
26+
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
27+
28+
Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
29+
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
30+
If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything
31+
should work as you expect.
32+
33+
#### Building via Gradle
34+
From the Airbyte repository root, run:
35+
```
36+
./gradlew :airbyte-integrations:connectors:destination-heap-analytics:build
37+
```
38+
39+
#### Create credentials
40+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/destinations/heap-analytics)
41+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `destination_heap_analytics/spec.json` file.
42+
Note that the `secrets` directory is gitignored by default, so there is no danger of accidentally checking in sensitive information.
43+
See `integration_tests/sample_config.json` for a sample config file.
44+
45+
**If you are an Airbyte core member**, copy the app id in Lastpass under the secret name `destination heap-analytics app id` and replace the app_id under the `sample_files/config-*.json`
46+
47+
### Locally running the connector
48+
49+
#### Server-Side API - Track
50+
51+
Use [this API](https://developers.heap.io/reference/track-1) to send custom events to Heap server-side.
52+
53+
```bash
54+
python main.py spec
55+
python main.py check --config sample_files/config-events.json
56+
cat sample_files/messages.jsonl | python main.py write --config sample_files/config-events.json --catalog sample_files/configured_catalog.json
57+
```
58+
59+
#### Server-Side API - Add User Properties
60+
61+
[This API](https://developers.heap.io/reference/add-user-properties) allows you to attach custom properties to any identified users from your servers, such as Sign Up Date (in ISO8601 format), Total # Transactions Completed, or Total Dollars Spent.
62+
63+
```bash
64+
python main.py spec
65+
python main.py check --config sample_files/config-aup.json
66+
cat sample_files/messages.jsonl | python main.py write --config sample_files/config-aup.json --catalog sample_files/configured_catalog.json
67+
```
68+
69+
#### Server-Side API - Add Account Properties
70+
71+
[This API](https://developers.heap.io/reference/add-account-properties) allows you to attach custom account properties to users. An account ID or use of our Salesforce integration is required for this to work.
72+
73+
```bash
74+
python main.py spec
75+
python main.py check --config sample_files/config-aap.json
76+
cat sample_files/messages.jsonl | python main.py write --config sample_files/config-aap.json --catalog sample_files/configured_catalog.json
77+
```
78+
79+
### Locally running the connector docker image
80+
81+
#### Build
82+
83+
First, make sure you build the latest Docker image:
84+
85+
```bash
86+
docker build . -t airbyte/destination-heap-analytics:dev
87+
```
88+
89+
You can also build the connector image via Gradle:
90+
91+
```bash
92+
./gradlew :airbyte-integrations:connectors:destination-heap-analytics:airbyteDocker
93+
```
94+
95+
When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in
96+
the Dockerfile.
97+
98+
#### Run
99+
100+
Then run any of the connector commands as follows:
101+
Spec command
102+
103+
```bash
104+
docker run --rm airbyte/destination-heap-analytics:dev spec
105+
```
106+
107+
Check command
108+
109+
```bash
110+
docker run --rm -v $(pwd)/sample_files:/sample_files airbyte/destination-heap-analytics:dev check --config /sample_files/config-events.json
111+
docker run --rm -v $(pwd)/sample_files:/sample_files airbyte/destination-heap-analytics:dev check --config /sample_files/config-aap.json
112+
docker run --rm -v $(pwd)/sample_files:/sample_files airbyte/destination-heap-analytics:dev check --config /sample_files/config-aup.json
113+
```
114+
115+
Write command
116+
```bash
117+
# messages.jsonl is a file containing line-separated JSON representing AirbyteMessages
118+
cat sample_files/messages.jsonl | docker run --rm -v $(pwd)/sample_files:/sample_files airbyte/destination-heap-analytics:dev write --config /sample_files/config-events.json --catalog /sample_files/configured_catalog.json
119+
cat sample_files/messages.jsonl | docker run --rm -v $(pwd)/sample_files:/sample_files airbyte/destination-heap-analytics:dev write --config /sample_files/config-aup.json --catalog /sample_files/configured_catalog.json
120+
cat sample_files/messages.jsonl | docker run --rm -v $(pwd)/sample_files:/sample_files airbyte/destination-heap-analytics:dev write --config /sample_files/config-aap.json --catalog /sample_files/configured_catalog.json
121+
```
122+
123+
## Testing
124+
125+
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
126+
First install test dependencies into your virtual environment:
127+
128+
```
129+
pip install .[tests]
130+
```
131+
132+
### Unit Tests
133+
To run unit tests locally, from the connector directory run:
134+
135+
```
136+
python -m pytest unit_tests
137+
```
138+
139+
### Integration Tests
140+
141+
There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all destination connectors) and custom integration tests (which are specific to this connector).
142+
143+
#### Custom Integration tests
144+
145+
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
146+
147+
```bash
148+
python -m pytest integration_tests
149+
```
150+
151+
### Using gradle to run tests
152+
153+
All commands should be run from airbyte project root.
154+
To run unit tests:
155+
156+
```bash
157+
./gradlew :airbyte-integrations:connectors:destination-heap-analytics:unitTest
158+
```
159+
160+
To run acceptance and custom integration tests:
161+
```bash
162+
./gradlew :airbyte-integrations:connectors:destination-heap-analytics:integrationTest
163+
```
164+
165+
## Dependency Management
166+
167+
All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
168+
We split dependencies between two groups, dependencies that are:
169+
170+
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
171+
* required for the testing need to go to `TEST_REQUIREMENTS` list
172+
173+
### Publishing a new version of the connector
174+
175+
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
176+
1. Make sure your changes are passing unit and integration tests.
177+
2. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
178+
3. Create a Pull Request.
179+
4. Pat yourself on the back for being an awesome contributor.
180+
5. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.

0 commit comments

Comments
 (0)