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

Fix InfluxDB Cloud <-> CrateDB Cloud connectivity once more #154

Merged
merged 1 commit into from
May 30, 2024
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


## Unreleased
- Fix InfluxDB Cloud <-> CrateDB Cloud connectivity by using
`ssl=true` query argument also for `influxdb2://` source URLs.

## 2024/05/30 v0.0.11
- Fix InfluxDB Cloud <-> CrateDB Cloud connectivity by propagating
Expand Down
9 changes: 8 additions & 1 deletion cratedb_toolkit/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import typing as t
from abc import abstractmethod

from yarl import URL

from cratedb_toolkit.api.guide import GuidingTexts
from cratedb_toolkit.cluster.util import get_cluster_info
from cratedb_toolkit.exception import CroudException, OperationFailed
from cratedb_toolkit.model import ClusterInformation, DatabaseAddress, InputOutputResource, TableAddress
from cratedb_toolkit.util.data import asbool

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -109,7 +112,11 @@ def load_table(self, resource: InputOutputResource, target: TableAddress):
if source_url.startswith("influxdb"):
from cratedb_toolkit.io.influxdb import influxdb_copy

source_url = source_url.replace("influxdb2://", "http://")
http_scheme = "http://"
source_url_obj = URL(source_url)
if asbool(source_url_obj.query.get("ssl")):
http_scheme = "https://"
source_url = source_url.replace("influxdb2://", http_scheme)
if not influxdb_copy(source_url, target_url, progress=True):
msg = "Data loading failed"
logger.error(msg)
Expand Down
17 changes: 2 additions & 15 deletions cratedb_toolkit/testing/testcontainers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,12 @@
# under the License.
import logging
import os
from typing import Any

from testcontainers.core.container import DockerContainer

logger = logging.getLogger(__name__)

from cratedb_toolkit.util.data import asbool

# from sqlalchemy.util.langhelpers
# from paste.deploy.converters
def asbool(obj: Any) -> bool:
if isinstance(obj, str):
obj = obj.strip().lower()
if obj in ["true", "yes", "on", "y", "t", "1"]:
return True
elif obj in ["false", "no", "off", "n", "f", "0"]:
return False
else:
raise ValueError("String is not true/false: %r" % obj)
return bool(obj)
logger = logging.getLogger(__name__)


class ExtendedDockerContainer(DockerContainer):
Expand Down
14 changes: 14 additions & 0 deletions cratedb_toolkit/util/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ def str_contains(haystack, *needles):
"""
haystack = str(haystack)
return any(needle in haystack for needle in needles)


# from sqlalchemy.util.langhelpers
# from paste.deploy.converters
def asbool(obj: t.Any) -> bool:
if isinstance(obj, str):
obj = obj.strip().lower()
if obj in ["true", "yes", "on", "y", "t", "1"]:
return True
elif obj in ["false", "no", "off", "n", "f", "0"]:
return False
else:
raise ValueError("String is not true/false: %r" % obj)
return bool(obj)
22 changes: 20 additions & 2 deletions doc/io/influxdb/loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ working with InfluxDB.
pip install --upgrade 'cratedb-toolkit[influxdb]'
```

## Example
Import two data points into InfluxDB.
## Examples

### Workstation

An exemplary walkthrough, copying data from InfluxDB to CrateDB, both services
expected to be listening on `localhost`.

Import two data points into InfluxDB.
```shell
export INFLUX_ORG=example
export INFLUX_TOKEN=token
Expand Down Expand Up @@ -49,4 +54,17 @@ ctk show table "testdrive.demo"
:::


### Cloud

A canonical invocation for copying data from InfluxDB Cloud to CrateDB Cloud.
Please note the `ssl=true` query parameter at the end of both database
connection URLs.

```shell
ctk load table \
"influxdb2://9fafc869a91a3517:[email protected]/testdrive/demo?ssl=true" \
--cratedb-sqlalchemy-url="crate://admin:[email protected]:4200/testdrive/demo?ssl=true"
```


[influxio]: inv:influxio:*:label#index