|
| 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