Skip to content

Commit

Permalink
Hide empty sections
Browse files Browse the repository at this point in the history
Summary:
Avoid dumping empty sections in config files.

I think they look weird in config
```toml
[tracing-headers]

[worker.snaphosts]
```
  • Loading branch information
muhamadazmy committed Feb 6, 2025
1 parent 6182058 commit c3b2cac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/types/src/config/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ pub struct TracingOptions {
///
/// Specify additional headers you want the system to send to the tracing endpoint (e.g.
/// authentication headers).
#[serde(skip_serializing_if = "SerdeableHeaderHashMap::is_empty")]
#[serde(default)]
pub tracing_headers: SerdeableHeaderHashMap,
}

Expand Down
8 changes: 7 additions & 1 deletion crates/types/src/config/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub struct WorkerOptions {
///
/// Snapshots provide a mechanism for safely trimming the log and efficient bootstrapping of new
/// worker nodes.
#[serde(skip_serializing_if = "is_default_snapshots_options")]
#[serde(default)]
pub snapshots: SnapshotsOptions,
}

Expand Down Expand Up @@ -366,7 +368,7 @@ impl Default for StorageOptions {
///
/// Partition store snapshotting settings.
#[serde_as]
#[derive(Default, Debug, Clone, Serialize, Deserialize, derive_builder::Builder)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, derive_builder::Builder)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schemars", schemars(rename = "SnapshotsOptions", default))]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -402,6 +404,10 @@ pub struct SnapshotsOptions {
pub snapshot_interval_num_records: Option<NonZeroU64>,
}

fn is_default_snapshots_options(opts: &SnapshotsOptions) -> bool {
opts == &SnapshotsOptions::default()
}

impl SnapshotsOptions {
pub fn snapshots_base_dir(&self) -> PathBuf {
super::data_dir("db-snapshots")
Expand Down

0 comments on commit c3b2cac

Please sign in to comment.