Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 399457d

Browse files
grtlrAlex6323
andauthored
feat(config)!: Remove ambiguity from CLI config (#1010)
* feat(config)!: get rid of ambiguity in MongoDB args * remove retries * remove feature flag * Fix integration tests Co-authored-by: /alex/ <[email protected]>
1 parent ab38091 commit 399457d

File tree

11 files changed

+20
-100
lines changed

11 files changed

+20
-100
lines changed

.github/workflows/_test_int.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
#mongodb-replica-set: test-rs
4646

4747
- name: Test DB
48+
env:
49+
MONGODB_CONN_STR: mongodb://root:root@localhost:27017
4850
uses: actions-rs/cargo@v1
4951
with:
5052
command: ci-test-int

docker/docker-compose.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ services:
1818
depends_on:
1919
influx:
2020
condition: service_started
21-
mongo:
22-
condition: service_started
2321
hornet:
2422
condition: service_healthy
2523
build:
@@ -30,10 +28,13 @@ services:
3028
- "8042:8042/tcp" # REST API
3129
- "9100:9100/tcp" # Metrics
3230
tty: true
31+
deploy:
32+
restart_policy:
33+
condition: on-failure
34+
delay: 5s
35+
max_attempts: 3
3336
command:
34-
- "--mongodb-conn-str=mongodb://mongo:27017"
35-
- "--mongodb-username=${MONGODB_USERNAME}"
36-
- "--mongodb-password=${MONGODB_PASSWORD}"
37+
- "--mongodb-conn-str=${MONGODB_CONN_STR}"
3738
- "--influxdb-url=http://influx:8086"
3839
- "--influxdb-username=${INFLUXDB_USERNAME}"
3940
- "--influxdb-password=${INFLUXDB_PASSWORD}"

src/bin/inx-chronicle/cli.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,16 @@ pub struct MongoDbArgs {
4141
default_value = mongodb::DEFAULT_CONN_STR,
4242
)]
4343
pub mongodb_conn_str: String,
44-
/// The MongoDb username.
45-
#[arg(long, value_name = "USERNAME", env = "MONGODB_USERNAME", default_value = mongodb::DEFAULT_USERNAME)]
46-
pub mongodb_username: String,
47-
/// The MongoDb password.
48-
#[arg(long, value_name = "PASSWORD", env = "MONGODB_PASSWORD", default_value = mongodb::DEFAULT_PASSWORD)]
49-
pub mongodb_password: String,
5044
/// The MongoDb database name.
5145
#[arg(long, value_name = "NAME", default_value = mongodb::DEFAULT_DATABASE_NAME)]
5246
pub mongodb_database_name: String,
53-
/// The MongoDb minimum pool size.
54-
#[arg(long, value_name = "SIZE", default_value_t = mongodb::DEFAULT_MIN_POOL_SIZE)]
55-
pub mongodb_min_pool_size: u32,
5647
}
5748

5849
impl From<&MongoDbArgs> for chronicle::db::MongoDbConfig {
5950
fn from(value: &MongoDbArgs) -> Self {
6051
Self {
6152
conn_str: value.mongodb_conn_str.clone(),
62-
username: value.mongodb_username.clone(),
63-
password: value.mongodb_password.clone(),
6453
database_name: value.mongodb_database_name.clone(),
65-
min_pool_size: value.mongodb_min_pool_size,
6654
}
6755
}
6856
}
@@ -128,12 +116,6 @@ pub struct InxArgs {
128116
/// The address of the node INX interface Chronicle tries to connect to - if enabled.
129117
#[arg(long, value_name = "URL", default_value = inx::DEFAULT_URL)]
130118
pub inx_url: String,
131-
/// Time to wait until a new connection attempt is made.
132-
#[arg(long, value_name = "DURATION", value_parser = parse_duration, default_value = inx::DEFAULT_RETRY_INTERVAL)]
133-
pub inx_retry_interval: std::time::Duration,
134-
/// Maximum number of tries to establish an INX connection.
135-
#[arg(long, value_name = "COUNT", default_value_t = inx::DEFAULT_RETRY_COUNT)]
136-
pub inx_retry_count: usize,
137119
/// Milestone at which synchronization should begin. If set to `1` Chronicle will try to sync back until the
138120
/// genesis block. If set to `0` Chronicle will start syncing from the most recent milestone it received.
139121
#[arg(long, value_name = "START", default_value_t = inx::DEFAULT_SYNC_START)]
@@ -149,8 +131,6 @@ impl From<&InxArgs> for inx::InxConfig {
149131
Self {
150132
enabled: !value.disable_inx,
151133
url: value.inx_url.clone(),
152-
conn_retry_interval: value.inx_retry_interval,
153-
conn_retry_count: value.inx_retry_count,
154134
sync_start_milestone: value.inx_sync_start.into(),
155135
}
156136
}
@@ -216,7 +196,7 @@ pub struct JwtArgs {
216196
pub jwt_expiration: std::time::Duration,
217197
}
218198

219-
#[cfg(any(feature = "inx", feature = "api"))]
199+
#[cfg(feature = "api")]
220200
fn parse_duration(arg: &str) -> Result<std::time::Duration, humantime::DurationError> {
221201
arg.parse::<humantime::Duration>().map(Into::into)
222202
}

src/bin/inx-chronicle/config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use chronicle::db::MongoDbConfig;
5-
use serde::{Deserialize, Serialize};
65

76
/// Configuration of Chronicle.
8-
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
9-
#[serde(default)]
7+
#[derive(Clone, Default, Debug)]
108
pub struct ChronicleConfig {
119
pub mongodb: MongoDbConfig,
1210
#[cfg(any(feature = "analytics", feature = "metrics"))]

src/bin/inx-chronicle/stardust_inx/config.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
// Copyright 2022 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::time::Duration;
5-
64
use chronicle::types::tangle::MilestoneIndex;
7-
use serde::{Deserialize, Serialize};
85

96
pub const DEFAULT_ENABLED: bool = true;
107
pub const DEFAULT_URL: &str = "http://localhost:9029";
11-
pub const DEFAULT_RETRY_INTERVAL: &str = "5s";
12-
pub const DEFAULT_RETRY_COUNT: usize = 30;
138
pub const DEFAULT_SYNC_START: u32 = 0;
149

1510
/// Configuration for an INX connection.
16-
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
17-
#[serde(default, deny_unknown_fields)]
11+
#[derive(Clone, Debug)]
1812
pub struct InxConfig {
1913
pub enabled: bool,
2014
/// The bind address of node's INX interface.
2115
pub url: String,
22-
/// The time that has to pass until a new connection attempt is made.
23-
#[serde(with = "humantime_serde")]
24-
pub conn_retry_interval: Duration,
25-
/// The number of retries when connecting fails.
26-
pub conn_retry_count: usize,
2716
/// The milestone at which synchronization should begin.
2817
pub sync_start_milestone: MilestoneIndex,
2918
}
@@ -33,8 +22,6 @@ impl Default for InxConfig {
3322
Self {
3423
enabled: DEFAULT_ENABLED,
3524
url: DEFAULT_URL.to_string(),
36-
conn_retry_interval: DEFAULT_RETRY_INTERVAL.parse::<humantime::Duration>().unwrap().into(),
37-
conn_retry_count: DEFAULT_RETRY_COUNT,
3825
sync_start_milestone: DEFAULT_SYNC_START.into(),
3926
}
4027
}

src/bin/inx-chronicle/stardust_inx/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright 2022 IOTA Stiftung
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use chronicle::types::tangle::MilestoneIndex;
4+
use chronicle::{inx::InxError, types::tangle::MilestoneIndex};
55
use thiserror::Error;
66

77
#[derive(Debug, Error)]
88
pub enum InxWorkerError {
99
#[cfg(feature = "analytics")]
1010
#[error("Analytics error: {0}")]
1111
Analytics(#[from] chronicle::db::collections::analytics::Error),
12-
#[error("failed to establish connection")]
13-
ConnectionError,
12+
#[error("failed to establish connection: {0}")]
13+
ConnectionError(#[from] InxError),
1414
#[cfg(any(feature = "analytics", feature = "metrics"))]
1515
#[error("InfluxDb error: {0}")]
1616
InfluxDb(#[from] influxdb::Error),

src/bin/inx-chronicle/stardust_inx/mod.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use chronicle::{
2121
tangle::MilestoneIndex,
2222
},
2323
};
24-
use eyre::{bail, eyre, Result};
24+
use eyre::{bail, Result};
2525
use futures::{StreamExt, TryStreamExt};
2626
use tokio::{task::JoinSet, try_join};
27-
use tracing::{debug, info, instrument, trace, trace_span, warn, Instrument};
27+
use tracing::{debug, info, instrument, trace, trace_span, Instrument};
2828

2929
pub use self::{config::InxConfig, error::InxWorkerError};
3030

@@ -102,20 +102,7 @@ impl InxWorker {
102102
bail!(InxWorkerError::InvalidAddress(self.config.url.clone()));
103103
}
104104

105-
for i in 0..self.config.conn_retry_count {
106-
match Inx::connect(self.config.url.clone()).await {
107-
Ok(inx_client) => return Ok(inx_client),
108-
Err(_) => {
109-
warn!(
110-
"INX connection failed. Retrying in {}s. {} retries remaining.",
111-
self.config.conn_retry_interval.as_secs(),
112-
self.config.conn_retry_count - i
113-
);
114-
tokio::time::sleep(self.config.conn_retry_interval).await;
115-
}
116-
}
117-
}
118-
Err(eyre!(InxWorkerError::ConnectionError))
105+
Ok(Inx::connect(self.config.url.clone()).await?)
119106
}
120107

121108
pub async fn run(&mut self) -> Result<()> {

src/db/influxdb/config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
//! Holds the `InfluxDb` config and its defaults.
55
6-
use serde::{Deserialize, Serialize};
7-
86
/// The default InfluxDb URL to connect to.
97
pub const DEFAULT_URL: &str = "http://localhost:8086";
108
/// The default InfluxDb username.
@@ -26,8 +24,7 @@ pub const DEFAULT_METRICS_DATABASE_NAME: &str = "chronicle_metrics";
2624

2725
/// The influxdb [`influxdb::Client`] config.
2826
#[must_use]
29-
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
30-
#[serde(default, deny_unknown_fields)]
27+
#[derive(Clone, PartialEq, Eq, Debug)]
3128
pub struct InfluxDbConfig {
3229
/// The address of the InfluxDb instance.
3330
pub url: String,

src/db/mongodb/config.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,20 @@ use mongodb::{
77
error::Error,
88
options::{ConnectionString, HostInfo},
99
};
10-
use serde::{Deserialize, Serialize};
1110

1211
/// The default connection string of the database.
1312
pub const DEFAULT_CONN_STR: &str = "mongodb://localhost:27017";
14-
/// The default MongoDB username.
15-
pub const DEFAULT_USERNAME: &str = "root";
16-
/// The default MongoDB password.
17-
pub const DEFAULT_PASSWORD: &str = "root";
1813
/// The default name of the database to connect to.
1914
pub const DEFAULT_DATABASE_NAME: &str = "chronicle";
20-
/// The default minimum amount of connections in the pool.
21-
pub const DEFAULT_MIN_POOL_SIZE: u32 = 2;
2215

2316
/// The [`super::MongoDb`] config.
2417
#[must_use]
25-
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
26-
#[serde(default, deny_unknown_fields)]
18+
#[derive(Clone, PartialEq, Eq, Debug)]
2719
pub struct MongoDbConfig {
2820
/// The connection string of the database.
2921
pub conn_str: String,
30-
/// The MongoDB username.
31-
pub username: String,
32-
/// The MongoDB password.
33-
pub password: String,
3422
/// The name of the database to connect to.
3523
pub database_name: String,
36-
/// The minimum amount of connections in the pool.
37-
pub min_pool_size: u32,
3824
}
3925

4026
impl MongoDbConfig {
@@ -53,10 +39,7 @@ impl Default for MongoDbConfig {
5339
fn default() -> Self {
5440
Self {
5541
conn_str: DEFAULT_CONN_STR.to_string(),
56-
username: DEFAULT_USERNAME.to_string(),
57-
password: DEFAULT_PASSWORD.to_string(),
5842
database_name: DEFAULT_DATABASE_NAME.to_string(),
59-
min_pool_size: DEFAULT_MIN_POOL_SIZE,
6043
}
6144
}
6245
}

src/db/mongodb/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use config::MongoDbConfig;
1212
use mongodb::{
1313
bson::{doc, Document},
1414
error::Error,
15-
options::{ClientOptions, Credential},
15+
options::ClientOptions,
1616
Client,
1717
};
1818

@@ -33,15 +33,6 @@ impl MongoDb {
3333
let mut client_options = ClientOptions::parse(&config.conn_str).await?;
3434

3535
client_options.app_name = Some("Chronicle".to_string());
36-
client_options.min_pool_size = Some(config.min_pool_size);
37-
38-
if client_options.credential.is_none() {
39-
let credential = Credential::builder()
40-
.username(config.username.clone())
41-
.password(config.password.clone())
42-
.build();
43-
client_options.credential = Some(credential);
44-
}
4536

4637
let client = Client::with_options(client_options)?;
4738

tests/common/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ pub async fn setup_database(database_name: impl ToString) -> eyre::Result<MongoD
1515
if let Ok(conn_str) = std::env::var("MONGODB_CONN_STR") {
1616
test_config.conn_str = conn_str;
1717
};
18-
if let Ok(username) = std::env::var("MONGODB_USERNAME") {
19-
test_config.username = username;
20-
};
21-
if let Ok(password) = std::env::var("MONGODB_PASSWORD") {
22-
test_config.password = password;
23-
};
2418

2519
let db = MongoDb::connect(&test_config).await?;
2620
db.clear().await?;

0 commit comments

Comments
 (0)