Skip to content

Commit

Permalink
Replace AirbyteLogger with logging.Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
girarda committed May 15, 2024
1 parent e19e634 commit 2a9bb60
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 22 deletions.
44 changes: 38 additions & 6 deletions airbyte-integrations/connectors/destination-astra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,44 @@ async def post_connector_install(connector_container: Container) -> Container:
return await connector_container.with_env_variable("MY_POST_BUILD_ENV_VAR", "my_post_build_env_var_value")
```

#### Build your own connector image


#### Use `airbyte-ci` to build your connector
The Airbyte way of building this connector is to use our `airbyte-ci` tool.
You can follow install instructions [here](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md#L1).
Then running the following command will build your connector:

```bash
airbyte-ci connectors --name destination-astra build
```
Once the command is done, you will find your connector image in your local docker registry: `airbyte/destination-astra:dev`.

##### Customizing our build process
When contributing on our connector you might need to customize the build process to add a system dependency or set an env var.
You can customize our build process by adding a `build_customization.py` module to your connector.
This module should contain a `pre_connector_install` and `post_connector_install` async function that will mutate the base image and the connector container respectively.
It will be imported at runtime by our build process and the functions will be called if they exist.

Here is an example of a `build_customization.py` module:
```python
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
# Feel free to check the dagger documentation for more information on the Container object and its methods.
# https://dagger-io.readthedocs.io/en/sdk-python-v0.6.4/
from dagger import Container


async def pre_connector_install(base_image_container: Container) -> Container:
return await base_image_container.with_env_variable("MY_PRE_BUILD_ENV_VAR", "my_pre_build_env_var_value")

async def post_connector_install(connector_container: Container) -> Container:
return await connector_container.with_env_variable("MY_POST_BUILD_ENV_VAR", "my_post_build_env_var_value")
```

#### Build your own connector image
This connector is built using our dynamic built process in `airbyte-ci`.
The base image used to build it is defined within the metadata.yaml file under the `connectorBuildOptions`.
The build logic is defined using [Dagger](https://dagger.io/) [here](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/pipelines/builds/python_connectors.py).
Expand All @@ -88,7 +124,6 @@ It does not rely on a Dockerfile.
If you would like to patch our connector and build your own a simple approach would be to:

1. Create your own Dockerfile based on the latest version of the connector image.

```Dockerfile
FROM airbyte/destination-astra:latest

Expand All @@ -99,17 +134,14 @@ RUN pip install ./airbyte/integration_code
# ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
# ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
```

Please use this as an example. This is not optimized.

2. Build your image:

```bash
docker build -t airbyte/destination-astra:dev .
# Running the spec command against your patched connector
docker run airbyte/destination-astra:dev spec
```

#### Run

Then run any of the connector commands as follows:
Expand Down Expand Up @@ -160,4 +192,4 @@ You've checked out the repo, implemented a million dollar feature, and you're re
1. Create a Pull Request.
1. Pat yourself on the back for being an awesome contributor.
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#


import logging
from typing import Any, Iterable, Mapping

from airbyte_cdk import AirbyteLogger
from airbyte_cdk.destinations import Destination
from airbyte_cdk.destinations.vector_db_based.document_processor import DocumentProcessor
from airbyte_cdk.destinations.vector_db_based.embedder import Embedder, create_from_config
Expand Down Expand Up @@ -37,7 +37,7 @@ def write(
)
yield from writer.write(configured_catalog, input_messages)

def check(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> AirbyteConnectionStatus:
def check(self, logger: logging.Logger, config: Mapping[str, Any]) -> AirbyteConnectionStatus:
parsed_config = ConfigModel.parse_obj(config)
self._init_indexer(parsed_config)
checks = [self.embedder.check(), self.indexer.check(), DocumentProcessor.check_config(parsed_config.processing)]
Expand Down
19 changes: 8 additions & 11 deletions airbyte-integrations/connectors/destination-astra/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ data:
allowedHosts:
hosts:
- "*.apps.astra.datastax.com"
registries:
oss:
enabled: true
cloud:
enabled: true
connectorBuildOptions:
# Please update to the latest version of the connector base image.
# Please use the full address with sha256 hash to guarantee build reproducibility.
# https://hub.docker.com/r/airbyte/python-connector-base
baseImage: docker.io/airbyte/python-connector-base:1.0.0@sha256:dd17e347fbda94f7c3abff539be298a65af2d7fc27a307d89297df1081a45c27
baseImage: docker.io/airbyte/python-connector-base:1.2.0@sha256:c22a9d97464b69d6ef01898edf3f8612dc11614f05a84984451dde195f337db9
connectorSubtype: database
connectorType: destination
definitionId: 042ce96f-1158-4662-9543-e2ff015be97a
dockerImageTag: 0.1.3
dockerImageTag: 0.1.5
dockerRepository: airbyte/destination-astra
documentationUrl: https://docs.airbyte.com/integrations/destinations/astra
githubIssueLabel: destination-astra
icon: astra.svg
license: MIT
name: Astra DB
registries:
cloud:
enabled: true
oss:
enabled: true
releaseDate: 2024-01-10
releaseStage: alpha
supportLevel: community
documentationUrl: https://docs.airbyte.com/integrations/destinations/astra
tags:
- language:python
- cdk:python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "airbyte-destination-astra"
version = "0.1.3"
version = "0.1.4"
description = "Airbyte destination implementation for Astra DB."
authors = ["Airbyte <[email protected]>"]
license = "MIT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

import logging
import unittest
from unittest.mock import MagicMock, Mock, patch

from airbyte_cdk import AirbyteLogger
from airbyte_cdk.models import ConnectorSpecification, Status
from destination_astra.config import ConfigModel
from destination_astra.destination import DestinationAstra
Expand All @@ -24,7 +24,7 @@ def setUp(self):
},
}
self.config_model = ConfigModel.parse_obj(self.config)
self.logger = AirbyteLogger()
self.logger = logging.getLogger("airbyte")

@patch("destination_astra.destination.AstraIndexer")
@patch("destination_astra.destination.create_from_config")
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/destinations/astra.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This page contains the setup guide and reference information for the destination

| Version | Date | Pull Request | Subject |
| :------ | :--------- | :----------- | :-------------------------------------------------------- |
| 0.1.4 | 2024-05-15 | [0](https://github.com/airbytehq/airbyte/pull/0) | Replace AirbyteLogger with logging.Logger |
| 0.1.3 | 2024-04-19 | #37405 | Add "airbyte" user-agent in the HTTP requests to Astra DB |
| 0.1.2 | 2024-04-15 | | Moved to Poetry; Updated CDK & pytest versions |
| 0.1.1 | 2024-01-26 | | DS Branding Update |
Expand Down

0 comments on commit 2a9bb60

Please sign in to comment.