Skip to content

Commit

Permalink
Merge pull request #172 from samply/chore/max-db-attempts-cla
Browse files Browse the repository at this point in the history
Chore/max db attempts cla
  • Loading branch information
enola-dkfz authored Oct 11, 2024
2 parents 8eb9871 + 9ecd9a5 commit 2bb6afe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Samply.Focus v0.7.0 2024-09-24

In this release, we are extending the supported data backends beyond CQL-enabled FHIR stores. We now support PostgreSQL as well. Usage instructions are included in the Readme.

## Major changes
* PostgreSQL support added

Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ In order to use Postgres querying, a Docker image built with the feature "dktk"
POSTGRES_CONNECTION_STRING = "postgresql://postgres:Test.123@localhost:5432/postgres" # Postgres connection string
```

Additionally when using Postgres this optional variable can be set:
```bash
MAX_DB_ATTEMPTS = "8" # Max number of attempts to connect to the database, default value: 8
```

Obfuscating zero counts is by default switched off. To enable obfuscating zero counts, set the env. variable `OBFUSCATE_ZERO`.

Optionally, you can provide the `TLS_CA_CERTIFICATES_DIR` environment variable to add additional trusted certificates, e.g., if you have a TLS-terminating proxy server in place. The application respects the `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY`, and their respective lowercase equivalents.
Expand All @@ -85,7 +90,7 @@ Creating a sample task containing an abstract syntax tree (AST) query using curl
curl -v -X POST -H "Content-Type: application/json" --data '{"id":"7fffefff-ffef-fcff-feef-feffffffffff","from":"app1.proxy1.broker","to":["app1.proxy1.broker"],"ttl":"10s","failure_strategy":{"retry":{"backoff_millisecs":1000,"max_tries":5}},"metadata":{"project":"bbmri"},"body":"eyJsYW5nIjoiYXN0IiwicGF5bG9hZCI6ImV5SmhjM1FpT25zaWIzQmxjbUZ1WkNJNklrOVNJaXdpWTJocGJHUnlaVzRpT2x0N0ltOXdaWEpoYm1RaU9pSkJUa1FpTENKamFHbHNaSEpsYmlJNlczc2liM0JsY21GdVpDSTZJazlTSWl3aVkyaHBiR1J5Wlc0aU9sdDdJbXRsZVNJNkltZGxibVJsY2lJc0luUjVjR1VpT2lKRlVWVkJURk1pTENKemVYTjBaVzBpT2lJaUxDSjJZV3gxWlNJNkltMWhiR1VpZlN4N0ltdGxlU0k2SW1kbGJtUmxjaUlzSW5SNWNHVWlPaUpGVVZWQlRGTWlMQ0p6ZVhOMFpXMGlPaUlpTENKMllXeDFaU0k2SW1abGJXRnNaU0o5WFgxZGZWMTlMQ0pwWkNJNkltRTJaakZqWTJZekxXVmlaakV0TkRJMFppMDVaRFk1TFRSbE5XUXhNelZtTWpNME1DSjkifQ=="}' -H "Authorization: ApiKey app1.proxy1.broker App1Secret" http://localhost:8081/v1/tasks
```

Creating a sample SQL task for a `SELECT_TABLES` query using curl:
Creating a sample SQL task for a `SELECT_TEST` query using curl:
```bash
curl -v -X POST -H "Content-Type: application/json" --data '{"id":"7fffefff-ffef-fcff-feef-feffffffffff","from":"app1.proxy1.broker","to":["app1.proxy1.broker"],"ttl":"10s","failure_strategy":{"retry":{"backoff_millisecs":1000,"max_tries":5}},"metadata":{"project":"exliquid"},"body":"eyJwYXlsb2FkIjoiU0VMRUNUX1RBQkxFUyJ9"}' -H "Authorization: ApiKey app1.proxy1.broker App1Secret" http://localhost:8081/v1/tasks
```
Expand Down
11 changes: 10 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,15 @@ struct CliArgs {
#[clap(long, env, value_parser)]
auth_header: Option<String>,

/// Database connection string
/// Postgres connection string
#[cfg(feature = "query-sql")]
#[clap(long, env, value_parser)]
postgres_connection_string: Option<String>,

/// Max number of attempts to connect to the database
#[cfg(feature = "query-sql")]
#[clap(long, env, value_parser, default_value = "8")]
max_db_attempts: u32,
}

pub(crate) struct Config {
Expand Down Expand Up @@ -195,6 +200,8 @@ pub(crate) struct Config {
pub auth_header: Option<String>,
#[cfg(feature = "query-sql")]
pub postgres_connection_string: Option<String>,
#[cfg(feature = "query-sql")]
pub max_db_attempts: u32,
}

impl Config {
Expand Down Expand Up @@ -238,6 +245,8 @@ impl Config {
auth_header: cli_args.auth_header,
#[cfg(feature = "query-sql")]
postgres_connection_string: cli_args.postgres_connection_string,
#[cfg(feature = "query-sql")]
max_db_attempts: cli_args.max_db_attempts,
client,
};
Ok(config)
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async fn get_db_pool() -> Result<Option<DbPool>,ExitCode> {
#[cfg(feature = "query-sql")]
async fn get_db_pool() -> Result<Option<DbPool>,ExitCode> {
if let Some(connection_string) = CONFIG.postgres_connection_string.clone() {
match db::get_pg_connection_pool(&connection_string, 8).await {
match db::get_pg_connection_pool(&connection_string, CONFIG.max_db_attempts).await {
Err(e) => {
error!("Error connecting to database: {}", e);
Err(ExitCode::from(8))
Expand Down

0 comments on commit 2bb6afe

Please sign in to comment.