Skip to content

Commit cf91fb8

Browse files
committed
Query Collector: Respect CRATEDB_SQLALCHEMY_URL environment variable
1 parent 9b5f04d commit cf91fb8

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Added basic utility command `ctk tail`, for tailing a database
99
table, and optionally following the tail
1010
- Table Loader: Added capability to load InfluxDB Line Protocol (ILP) files
11+
- Query Collector: Now respects `CRATEDB_SQLALCHEMY_URL` environment variable
1112

1213
## 2024/10/13 v0.0.29
1314
- MongoDB: Added Zyp transformations to the CDC subsystem,

cratedb_toolkit/wtf/query_collector.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
import urllib3
1212
from crate import client
1313

14+
from cratedb_toolkit.model import DatabaseAddress
15+
1416
logger = logging.getLogger(__name__)
1517

16-
host = os.getenv("HOSTNAME", "localhost:4200")
17-
username = os.getenv("USERNAME", "crate")
18-
password = os.getenv("PASSWORD", "")
18+
cratedb_sqlalchemy_url = os.getenv("CRATEDB_SQLALCHEMY_URL", "crate://crate@localhost:4200")
19+
uri = DatabaseAddress.from_string(cratedb_sqlalchemy_url)
20+
host = f"{uri.uri.host}:{uri.uri.port}"
21+
username = uri.uri.username
22+
password = uri.uri.password
1923
interval = float(os.getenv("INTERVAL", 10))
2024
stmt_log_table = os.getenv("STMT_TABLE", "stats.statement_log")
2125
last_exec_table = os.getenv("LAST_EXEC_TABLE", "stats.last_execution")

tests/wtf/test_cli.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from boltons.iterutils import get_path
44
from click.testing import CliRunner
5-
from yarl import URL
65

76
from cratedb_toolkit.wtf.cli import cli
87

@@ -94,14 +93,11 @@ def test_wtf_cli_statistics_collect(cratedb, caplog):
9493
Verify `cratedb-wtf job-statistics collect`.
9594
"""
9695

97-
uri = URL(cratedb.database.dburi)
98-
9996
# Invoke command.
10097
runner = CliRunner(env={"CRATEDB_SQLALCHEMY_URL": cratedb.database.dburi})
10198
result = runner.invoke(
10299
cli,
103100
args="job-statistics collect --once",
104-
env={"HOSTNAME": f"{uri.host}:{uri.port}"},
105101
catch_exceptions=False,
106102
)
107103
assert result.exit_code == 0

0 commit comments

Comments
 (0)