Skip to content

Commit

Permalink
Use IggyDuration and Byte structs for all available configs (#379)
Browse files Browse the repository at this point in the history
Close #273, close #277
  • Loading branch information
spetz authored Dec 4, 2023
1 parent 7cb8432 commit 66bc878
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions configs/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"valid_audiences": [
"iggy.rs"
],
"access_token_expiry": 3600,
"refresh_token_expiry": 86400,
"clock_skew": 5,
"not_before": 0,
"access_token_expiry": "1h",
"refresh_token_expiry": "1d",
"clock_skew": "5s",
"not_before": "0s",
"encoding_secret": "top_secret$iggy.rs$_jwt_HS256_key#!",
"decoding_secret": "top_secret$iggy.rs$_jwt_HS256_key#!",
"use_base64_secret": false
Expand Down Expand Up @@ -61,12 +61,12 @@
"enabled": true,
"address": "0.0.0.0:8080",
"max_concurrent_bidi_streams": 10000,
"datagram_send_buffer_size": 100000,
"initial_mtu": 8000,
"send_window": 100000,
"receive_window": 100000,
"keep_alive_interval": 5000,
"max_idle_timeout": 10000,
"datagram_send_buffer_size": "100KB",
"initial_mtu": "8KB",
"send_window": "100KB",
"receive_window": "100KB",
"keep_alive_interval": "5s",
"max_idle_timeout": "10s",
"certificate": {
"self_signed": true,
"cert_file": "certs/iggy_cert.pem",
Expand All @@ -75,18 +75,18 @@
},
"message_cleaner": {
"enabled": true,
"interval": 60
"interval": "1m"
},
"message_saver": {
"enabled": true,
"enforce_fsync": true,
"interval": 30
"interval": "30s"
},
"personal_access_token": {
"max_tokens_per_user": 100,
"cleaner": {
"enabled": true,
"interval": 60
"interval": "1m"
}
},
"system": {
Expand All @@ -100,8 +100,8 @@
"logging": {
"path": "logs",
"level": "info",
"max_size_megabytes": 512,
"retention_days": 7
"max_size": "512MB",
"retention": "7 days"
},
"cache": {
"enabled": true,
Expand Down Expand Up @@ -132,7 +132,7 @@
"messages_required_to_save": 10000
},
"segment": {
"size_bytes": 1000000000,
"size": "1GB",
"cache_indexes": true,
"cache_time_indexes": true
},
Expand Down
62 changes: 31 additions & 31 deletions configs/server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ valid_issuers = ["iggy.rs"]
# Lists valid audiences for JWT validation to confirm tokens are for the intended recipient.
valid_audiences = ["iggy.rs"]

# Expiry time for access tokens, in seconds.
access_token_expiry = 3600
# Expiry time for access tokens.
access_token_expiry = "1h"

# Expiry time for refresh tokens, in seconds.
refresh_token_expiry = 86400
# Expiry time for refresh tokens.
refresh_token_expiry = "1d"

# Tolerance for timing discrepancies in seconds during token validation.
clock_skew = 5
# Tolerance for timing discrepancies during token validation.
clock_skew = "5s"

# Time in seconds before which the token should not be considered valid.
not_before = 0
# Time before which the token should not be considered valid.
not_before = "0s"

# Secret key for encoding JWTs.
encoding_secret = "top_secret$iggy.rs$_jwt_HS256_key#!"
Expand Down Expand Up @@ -145,22 +145,22 @@ address = "0.0.0.0:8080"
max_concurrent_bidi_streams = 10_000

# Size of the buffer for sending datagrams in QUIC.
datagram_send_buffer_size = 100_000
datagram_send_buffer_size = "100KB"

# Initial Maximum Transmission Unit (MTU) for QUIC connections.
initial_mtu = 8_000
initial_mtu = "8KB"

# Size of the sending window in QUIC, controlling data flow.
send_window = 100_000
send_window = "100KB"

# Size of the receiving window in QUIC, controlling data flow.
receive_window = 100_000
receive_window = "100KB"

# Interval in milliseconds for sending keep-alive messages in QUIC.
keep_alive_interval = 5_000
# Interval for sending keep-alive messages in QUIC.
keep_alive_interval = "5s"

# Maximum idle time in milliseconds before a QUIC connection is closed.
max_idle_timeout = 10_000
# Maximum idle time before a QUIC connection is closed.
max_idle_timeout = "10s"

# QUIC certificate configuration.
[quic.certificate]
Expand All @@ -182,8 +182,8 @@ key_file = "certs/iggy_key.pem"
# `false` turns it off, messages will not be auto-deleted based on expiry.
enabled = true

# Interval in seconds for running the message cleaner.
interval = 60
# Interval for running the message cleaner.
interval = "1m"

# Message saver configuration.
[message_saver]
Expand All @@ -197,8 +197,8 @@ enabled = true
# `false` for asynchronous saving, improving performance but with delayed data writing.
enforce_fsync = true

# Interval in seconds for running the message saver.
interval = 30
# Interval for running the message saver.
interval = "30s"

# Personal access token configuration.
[personal_access_token]
Expand All @@ -212,8 +212,8 @@ max_tokens_per_user = 100
# `false` disables it, tokens remain active until manually revoked or expired.
enabled = true

# Interval in seconds for running the token cleaner.
interval = 60
# Interval for running the token cleaner.
interval = "1m"

# System configuration.
[system]
Expand All @@ -240,11 +240,11 @@ path = "logs"
# Level of logging detail. Options: "debug", "info", "warn", "error".
level = "info"

# Maximum size of log files in megabytes before rotation.
max_size_megabytes = 512
# Maximum size of the log files before rotation.
max_size = "512 MB"

# Number of days to retain log files before deletion.
retention_days = 7
# Time to retain log files before deletion.
retention = "7 days"

# Cache configuration.
[system.cache]
Expand All @@ -253,7 +253,7 @@ retention_days = 7
# `false` disables caching, data is always read from the source.
enabled = true

# Maximum size of the cache, e.g., "4GB".
# Maximum size of the cache, e.g. "4GB".
size = "4GB"

# Data retention policy configuration.
Expand All @@ -275,7 +275,7 @@ max_topic_size = "10 GB"
enabled = false

# The encryption key used when encryption is enabled (string).
# Should be a 32-byte length key, provided as a base64 encoded string.
# Should be a 32 bytes length key, provided as a base64 encoded string.
# This key is required and used only if encryption is enabled.
key = ""

Expand Down Expand Up @@ -325,10 +325,10 @@ messages_required_to_save = 10_000

# Segment configuration
[system.segment]
# Defines the soft limit for the size of a storage segment in bytes (integer).
# Defines the soft limit for the size of a storage segment.
# When a segment reaches this size, a new segment is created for subsequent data.
# Example: if `size_bytes` is set to 1,000,000,000 (approx. 1GB), the actual segment size may be 1GB + the size of one additional message.
size_bytes = 1_000_000_000
# Example: if `size` is set "1GB", the actual segment size may be 1GB + the size of remaining messages in received batch.
size = "1GB"

# Controls whether to cache indexes for segment access (boolean).
# `true` keeps indexes in memory, speeding up data retrieval.
Expand Down
7 changes: 5 additions & 2 deletions integration/tests/config_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn validate_server_config_json_from_repository() {
#[tokio::test]
async fn validate_custom_env_provider() {
env::set_var("IGGY_SYSTEM_DATABASE_PATH", "awesome_database_path");
env::set_var("IGGY_QUIC_DATAGRAM_SEND_BUFFER_SIZE", "1337");
env::set_var("IGGY_QUIC_DATAGRAM_SEND_BUFFER_SIZE", "1KB");
env::set_var("IGGY_QUIC_CERTIFICATE_SELF_SIGNED", "false");
env::set_var("IGGY_HTTP_ENABLED", "false");
env::set_var("IGGY_SYSTEM_PARTITION_MESSAGES_REQUIRED_TO_SAVE", "42");
Expand All @@ -50,7 +50,10 @@ async fn validate_custom_env_provider() {
.expect("Failed to load default server.toml config");

assert_eq!(config.system.database.path, "awesome_database_path");
assert_eq!(config.quic.datagram_send_buffer_size, 1337);
assert_eq!(
config.quic.datagram_send_buffer_size,
"1KB".parse().unwrap()
);
assert!(!config.quic.certificate.self_signed);
assert!(!config.http.enabled);
assert_eq!(config.system.partition.messages_required_to_save, 42);
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "server"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
build = "src/build.rs"

Expand Down
8 changes: 4 additions & 4 deletions server/src/channels/commands/clean_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{channels::server_command::ServerCommand, configs::server::MessageCle
use async_trait::async_trait;
use flume::Sender;
use iggy::error::Error;
use iggy::utils::duration::IggyDuration;
use iggy::utils::timestamp::TimeStamp;
use std::time::Duration;
use tokio::time;
use tracing::{error, info};

Expand All @@ -16,7 +16,7 @@ struct DeletedSegments {

pub struct MessagesCleaner {
enabled: bool,
interval: Duration,
interval: IggyDuration,
sender: Sender<CleanMessagesCommand>,
}

Expand All @@ -30,7 +30,7 @@ impl MessagesCleaner {
pub fn new(config: &MessageCleanerConfig, sender: Sender<CleanMessagesCommand>) -> Self {
Self {
enabled: config.enabled,
interval: Duration::from_secs(config.interval),
interval: config.interval,
sender,
}
}
Expand All @@ -49,7 +49,7 @@ impl MessagesCleaner {
);

tokio::spawn(async move {
let mut interval_timer = time::interval(interval);
let mut interval_timer = time::interval(interval.get_duration());
loop {
interval_timer.tick().await;
sender.send(CleanMessagesCommand).unwrap_or_else(|err| {
Expand Down
8 changes: 4 additions & 4 deletions server/src/channels/commands/clean_personal_access_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::configs::server::PersonalAccessTokenCleanerConfig;
use crate::streaming::systems::system::SharedSystem;
use async_trait::async_trait;
use flume::Sender;
use iggy::utils::duration::IggyDuration;
use iggy::utils::timestamp::TimeStamp;
use std::time::Duration;
use tokio::time;
use tracing::{debug, error, info};

pub struct PersonalAccessTokenCleaner {
enabled: bool,
interval: Duration,
interval: IggyDuration,
sender: Sender<CleanPersonalAccessTokensCommand>,
}

Expand All @@ -27,7 +27,7 @@ impl PersonalAccessTokenCleaner {
) -> Self {
Self {
enabled: config.enabled,
interval: Duration::from_secs(config.interval),
interval: config.interval,
sender,
}
}
Expand All @@ -46,7 +46,7 @@ impl PersonalAccessTokenCleaner {
);

tokio::spawn(async move {
let mut interval_timer = time::interval(interval);
let mut interval_timer = time::interval(interval.get_duration());
loop {
interval_timer.tick().await;
sender
Expand Down
9 changes: 5 additions & 4 deletions server/src/channels/commands/save_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use crate::streaming::segments::storage::FileSegmentStorage;
use crate::streaming::systems::system::SharedSystem;
use async_trait::async_trait;
use flume::{Receiver, Sender};
use std::{sync::Arc, time::Duration};
use iggy::utils::duration::IggyDuration;
use std::sync::Arc;
use tokio::time;
use tracing::{error, info, warn};

pub struct MessagesSaver {
enforce_fsync: bool,
interval: Duration,
interval: IggyDuration,
sender: Sender<SaveMessagesCommand>,
}

Expand All @@ -28,7 +29,7 @@ impl MessagesSaver {
pub fn new(config: &MessageSaverConfig, sender: Sender<SaveMessagesCommand>) -> Self {
Self {
enforce_fsync: config.enforce_fsync,
interval: Duration::from_secs(config.interval),
interval: config.interval,
sender,
}
}
Expand All @@ -48,7 +49,7 @@ impl MessagesSaver {
);

tokio::spawn(async move {
let mut interval_timer = time::interval(interval);
let mut interval_timer = time::interval(interval.get_duration());
loop {
interval_timer.tick().await;
let command = SaveMessagesCommand { enforce_fsync };
Expand Down
Loading

0 comments on commit 66bc878

Please sign in to comment.