Skip to content

Commit

Permalink
Query Collector: Respect CRATEDB_SQLALCHEMY_URL environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 11, 2025
1 parent cbb5fde commit 339c8b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Added basic utility command `ctk tail`, for tailing a database
table, and optionally following the tail
- Table Loader: Added capability to load InfluxDB Line Protocol (ILP) files
- Query Collector: Now respects `CRATEDB_SQLALCHEMY_URL` environment variable

## 2024/10/13 v0.0.29
- MongoDB: Added Zyp transformations to the CDC subsystem,
Expand Down
10 changes: 7 additions & 3 deletions cratedb_toolkit/wtf/query_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import urllib3
from crate import client

from cratedb_toolkit.model import DatabaseAddress

Check warning on line 14 in cratedb_toolkit/wtf/query_collector.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/wtf/query_collector.py#L14

Added line #L14 was not covered by tests

logger = logging.getLogger(__name__)

host = os.getenv("HOSTNAME", "localhost:4200")
username = os.getenv("USERNAME", "crate")
password = os.getenv("PASSWORD", "")
cratedb_sqlalchemy_url = os.getenv("CRATEDB_SQLALCHEMY_URL", "crate://crate@localhost:4200")
uri = DatabaseAddress.from_string(cratedb_sqlalchemy_url)
host = f"{uri.uri.host}:{uri.uri.port}"
username = uri.uri.username
password = uri.uri.password

Check warning on line 22 in cratedb_toolkit/wtf/query_collector.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/wtf/query_collector.py#L18-L22

Added lines #L18 - L22 were not covered by tests
interval = float(os.getenv("INTERVAL", 10))
stmt_log_table = os.getenv("STMT_TABLE", "stats.statement_log")
last_exec_table = os.getenv("LAST_EXEC_TABLE", "stats.last_execution")
Expand Down
4 changes: 0 additions & 4 deletions tests/wtf/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from boltons.iterutils import get_path
from click.testing import CliRunner
from yarl import URL

from cratedb_toolkit.wtf.cli import cli

Expand Down Expand Up @@ -94,14 +93,11 @@ def test_wtf_cli_statistics_collect(cratedb, caplog):
Verify `cratedb-wtf job-statistics collect`.
"""

uri = URL(cratedb.database.dburi)

# Invoke command.
runner = CliRunner(env={"CRATEDB_SQLALCHEMY_URL": cratedb.database.dburi})
result = runner.invoke(
cli,
args="job-statistics collect --once",
env={"HOSTNAME": f"{uri.host}:{uri.port}"},
catch_exceptions=False,
)
assert result.exit_code == 0
Expand Down

0 comments on commit 339c8b9

Please sign in to comment.