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

refactor(config)!: re-design and clean-up configuration #979

Merged
merged 42 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3043c2c
Refactor CLI
Alex6323 Dec 13, 2022
227ec8e
Remove custom Default impls from config types
Alex6323 Dec 13, 2022
5c83c33
Remove config.template.toml
Alex6323 Dec 13, 2022
34aff37
Add gen-config tool
Alex6323 Dec 14, 2022
1b8f96d
Merge branch 'main' into refactor/config/config-refactor
Alex6323 Dec 14, 2022
f989c0f
Fix CI
Alex6323 Dec 14, 2022
c9cd8a6
Fix tests
Alex6323 Dec 14, 2022
2c8dbea
Fix docs
Alex6323 Dec 14, 2022
7700dea
Use only non-default CLI commands in docker-compose.yml
Alex6323 Dec 14, 2022
c0f5793
Let's try enforcing MongoDb auth
Alex6323 Dec 14, 2022
99f9b47
Let's try again
Alex6323 Dec 14, 2022
1c55eca
What happens now?
Alex6323 Dec 14, 2022
42b0b0f
Move defaults into constants
Alex6323 Dec 16, 2022
f674fc8
Remove user Argon configuration
Alex6323 Dec 16, 2022
611f793
Improve API configuration
Alex6323 Dec 16, 2022
e68cc71
Complete default consts
Alex6323 Dec 16, 2022
5a4715c
Fix clippy box default warning
Alex6323 Dec 16, 2022
d682d2f
Merge branch 'fix/clippy/box-default' into refactor/config/config-ref…
Alex6323 Dec 16, 2022
308a361
Fix docs
Alex6323 Dec 16, 2022
05d3615
Format
Alex6323 Dec 16, 2022
72aa03d
Fix CI
Alex6323 Dec 16, 2022
697607f
Renaming
Alex6323 Dec 17, 2022
be8ff50
Simplify CLI
Alex6323 Dec 19, 2022
cd44f15
Remove config file
Alex6323 Dec 19, 2022
8d2d806
Switch toggle to disable flags
Alex6323 Dec 19, 2022
5776d56
Re-enable replica set for integration tests
Alex6323 Dec 19, 2022
2d43530
Merge branch 'main' into refactor/config/config-refactor
Alex6323 Dec 19, 2022
5f5c7e0
Fix merge
Alex6323 Dec 19, 2022
e0a7e71
(Temporarily) fix integration test CI
Alex6323 Dec 20, 2022
b013252
Merge branch 'main' into refactor/config/config-refactor
Alex6323 Dec 20, 2022
4c22547
Fix and small reorder
Alex6323 Dec 20, 2022
9f2663b
Obey the Clippy overlord
Alex6323 Dec 20, 2022
d20eccd
Impl From<*Args> for *Configs
Alex6323 Dec 20, 2022
6987b76
More details regarding replica-sets with auth
Alex6323 Dec 20, 2022
fafdc94
Fix check-all-features
Alex6323 Dec 22, 2022
492bc45
Feature headache
Alex6323 Dec 23, 2022
d071abc
Feature headache 2
Alex6323 Dec 23, 2022
ac450c6
Last fixes
Alex6323 Dec 23, 2022
dc31c2f
Load .env file in inx-chronicle docker service
Alex6323 Dec 23, 2022
44a937d
Different approach
Alex6323 Dec 23, 2022
63c234e
Add example to README
Alex6323 Dec 23, 2022
1b9fdaf
Update README.md
grtlr Dec 23, 2022
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
10 changes: 9 additions & 1 deletion src/bin/inx-chronicle/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,20 @@ impl From<&InfluxDbArgs> for chronicle::db::influxdb::InfluxDbConfig {
password: value.influxdb_password.clone(),
#[cfg(feature = "analytics")]
analytics_enabled: !value.disable_analytics,
#[cfg(not(feature = "analytics"))]
analytics_enabled: false,
#[cfg(feature = "analytics")]
analytics_database_name: value.analytics_database_name.clone(),
#[cfg(not(feature = "analytics"))]
analytics_database_name: String::new(),
#[cfg(feature = "metrics")]
metrics_enabled: !value.disable_metrics,
#[cfg(not(feature = "metrics"))]
metrics_enabled: false,
#[cfg(feature = "metrics")]
metrics_database_name: value.metrics_database_name.clone(),
#[cfg(not(feature = "metrics"))]
metrics_database_name: String::new(),
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -291,7 +299,7 @@ impl ClArgs {
);
return Ok(PostCommand::Exit);
}
#[cfg(all(feature = "analytics", feature = "stardust"))]
#[cfg(all(feature = "analytics", feature = "stardust", feature = "inx"))]
Subcommands::FillAnalytics {
start_milestone,
end_milestone,
Expand Down
12 changes: 7 additions & 5 deletions src/bin/inx-chronicle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ async fn main() -> eyre::Result<()> {
#[cfg(all(feature = "inx", feature = "stardust"))]
if config.inx.enabled {
#[cfg(any(feature = "analytics", feature = "metrics"))]
#[allow(clippy::vec_init_then_push)]
let influx_db = if config.influxdb.analytics_enabled || config.influxdb.metrics_enabled {
info!("Connecting to influx database at address `{}`", config.influxdb.url);
let influx_db = chronicle::db::influxdb::InfluxDb::connect(&config.influxdb).await?;
info!(
"Connected to influx databases `{}` and `{}`",
influx_db.analytics().database_name(),
influx_db.metrics().database_name()
);
let mut databases = vec![];
#[cfg(feature = "analytics")]
databases.push(influx_db.analytics().database_name());
#[cfg(feature = "metrics")]
databases.push(influx_db.metrics().database_name());
info!("Connected to influx databases `{databases:?}`");
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
Some(influx_db)
} else {
None
Expand Down
12 changes: 0 additions & 12 deletions src/db/influxdb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ pub const DEFAULT_USERNAME: &str = "root";
/// The default InfluxDb password.
pub const DEFAULT_PASSWORD: &str = "password";
/// The default whether to enable influx analytics writes.
#[cfg(feature = "analytics")]
pub const DEFAULT_ANALYTICS_ENABLED: bool = true;
/// The default name of the analytics database to connect to.
#[cfg(feature = "analytics")]
pub const DEFAULT_ANALYTICS_DATABASE_NAME: &str = "chronicle_analytics";
/// The default whether to enable influx metrics writes.
#[cfg(feature = "metrics")]
pub const DEFAULT_METRICS_ENABLED: bool = true;
/// The default name of the metrics database to connect to.
#[cfg(feature = "metrics")]
pub const DEFAULT_METRICS_DATABASE_NAME: &str = "chronicle_metrics";

/// The influxdb [`influxdb::Client`] config.
Expand All @@ -36,16 +32,12 @@ pub struct InfluxDbConfig {
/// The InfluxDb password.
pub password: String,
/// Whether to enable influx analytics writes.
#[cfg(feature = "analytics")]
pub analytics_enabled: bool,
/// The name of the database to insert analytics.
#[cfg(feature = "analytics")]
pub analytics_database_name: String,
/// Whether to enable influx metrics writes.
#[cfg(feature = "metrics")]
pub metrics_enabled: bool,
/// The name of the database to insert metrics.
#[cfg(feature = "metrics")]
pub metrics_database_name: String,
}

Expand All @@ -55,13 +47,9 @@ impl Default for InfluxDbConfig {
url: DEFAULT_URL.to_string(),
username: DEFAULT_USERNAME.to_string(),
password: DEFAULT_PASSWORD.to_string(),
#[cfg(feature = "analytics")]
analytics_enabled: DEFAULT_ANALYTICS_ENABLED,
#[cfg(feature = "analytics")]
analytics_database_name: DEFAULT_ANALYTICS_DATABASE_NAME.to_string(),
#[cfg(feature = "metrics")]
metrics_enabled: DEFAULT_METRICS_ENABLED,
#[cfg(feature = "metrics")]
metrics_database_name: DEFAULT_METRICS_DATABASE_NAME.to_string(),
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/db/mongodb/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ pub trait MongoDbCollectionExt: MongoDbCollection {
}
impl<T: MongoDbCollection> MongoDbCollectionExt for T {}

pub(crate) struct InsertResult {
pub(crate) _ignored: usize,
pub struct InsertResult {
pub _ignored: usize,
Alex6323 marked this conversation as resolved.
Show resolved Hide resolved
}

#[allow(missing_docs)]
#[async_trait]
pub(crate) trait InsertIgnoreDuplicatesExt<T> {
pub trait InsertIgnoreDuplicatesExt<T> {
/// Inserts many records and ignores duplicate key errors.
async fn insert_many_ignore_duplicates(
&self,
Expand Down
3 changes: 1 addition & 2 deletions src/db/mongodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use mongodb::{
Client,
};

pub(crate) use self::collection::InsertIgnoreDuplicatesExt;
pub use self::collection::{MongoDbCollection, MongoDbCollectionExt};
pub use self::collection::{InsertIgnoreDuplicatesExt, MongoDbCollection, MongoDbCollectionExt};

const DUPLICATE_KEY_CODE: i32 = 11000;

Expand Down