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 use of schema configuration setting, it was not honored #117

Merged
merged 1 commit into from
Jan 23, 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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased

- Packaging: Re-add compatibility with glibc 2.31,
by building on ``golang:1.20-bullseye``.
- Fixed use of ``schema`` configuration setting, it was not honored.


2024-01-12 0.5.0
Expand Down
9 changes: 9 additions & 0 deletions crate.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ func newCrateEndpoint(ep *endpointConfig) *crateEndpoint {
// a connection from the pool manually and prepare it there before use.
// https://github.com/jackc/pgx/issues/791#issuecomment-660508309
poolConf.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {

// Switch to different database schema when requested.
if ep.Schema != "" {
_, err := conn.Exec(ctx, fmt.Sprintf("SET search_path TO '%s';", ep.Schema))
if err != nil {
return fmt.Errorf("error setting search path: %v", err)
}
}

_, err := conn.Prepare(ctx, "write_statement", crateWriteStatement)
if err != nil {
return fmt.Errorf("error preparing write statement: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ addopts = """
-rfEX -p pytester --strict-markers --verbosity=3
"""
env = [
"CRATEDB_CONNECTION_STRING=crate://crate@localhost/?ssl=false",
"CRATEDB_CONNECTION_STRING=crate://crate@localhost/?ssl=false&schema=testdrive",
amotl marked this conversation as resolved.
Show resolved Hide resolved
"CRATEDB_PROMETHEUS_ADAPTER_METRICS_URL=http://localhost:9268/metrics",
"PROMETHEUS_URL=http://localhost:9090",
]
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def cratedb_prometheus_adapter(reset_database, cratedb_client, flush_database):
Start the CrateDB Prometheus Adapter.
"""

command = "go run ."
command = "go run . -config.file tests/cpa-config.yml"
with process(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as daemon:
# Give the server time to start.
time.sleep(2)
Expand Down
20 changes: 20 additions & 0 deletions tests/cpa-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cratedb_endpoints:
- host: "localhost" # Host to connect to (default: "localhost").
port: 5432 # Port to connect to (default: 5432).
user: "crate" # Username to use (default: "crate")
password: "" # Password to use (default: "").
schema: "testdrive" # Schema to use (default: "").
surister marked this conversation as resolved.
Show resolved Hide resolved
max_connections: 0 # The maximum number of concurrent connections (default: runtime.NumCPU()).
# It will get forwarded to pgx's `pool_max_conns`, and determines
# the maximum number of connections in the connection pool for
# both connection pools (read and write).
read_pool_size_max: 0 # Configure the maximum pool size for read operations individually.
# (default: runtime.NumCPU())
write_pool_size_max: 0 # Configure the maximum pool size for write operations individually.
# (default: runtime.NumCPU())
connect_timeout: 10 # TCP connect timeout (seconds) (default: 10).
# It has the same meaning as libpq's `connect_timeout`.
read_timeout: 5 # Query context timeout for read queries (seconds) (default: 5).
write_timeout: 5 # Query context timeout for write queries (seconds) (default: 5).
enable_tls: false # Whether to connect using TLS (default: false).
allow_insecure_tls: false # Whether to allow insecure / invalid TLS certificates (default: false).
2 changes: 1 addition & 1 deletion tests/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_verify_no_failures(prometheus_client):
result = prometheus_client.get_metric_aggregation(
failed_total_attribute, operations=["sum"]
)
assert result == {"sum": 0.0}
assert result == {"sum": 0.0}, f"{failed_total_attribute} tracked {result['sum']} errors"


def test_verify_write_activity(prometheus_client):
Expand Down
Loading