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

Add support for configuring Restate in benchmarks via env variables #597

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ cargo bench --bench throughput_parallel -- --profile-time=30
```

This will profile the *throughput_parallel* benchmark for *30 s*.
The profiler will generate a flamegraph under `target/criterion/<name_of_benchmark>/profile/flamegraph.svg`.
The profiler will generate a flamegraph under `target/criterion/<name_of_benchmark>/profile/flamegraph.svg`.

## Changing Restate's configuration

The benchmarks spawn Restate with a default configuration.
You can [overwrite this configuration by specifying environment variables](http://restate.dev/docs/deployment-operations/configuration) of the form `RESTATE_WORKER__PARTITIONS=1337`.
5 changes: 3 additions & 2 deletions src/benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ pub fn restate_configuration() -> Configuration {
.build()
.expect("building worker options should work");

let config = ConfigurationBuilder::default()
let default_config = ConfigurationBuilder::default()
.worker(worker_options)
.meta(meta_options)
.build()
.expect("building the configuration should work");

config
Configuration::load_with_default(default_config, None)
.expect("configuration loading should not fail")
}
63 changes: 39 additions & 24 deletions src/restate/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,45 @@ impl Configuration {
Duration::from_secs(60).into()
}

/// Load [`Configuration`] from yaml with overrides from environment variables.
#[allow(dead_code)]
/// Load [`Configuration`] from yaml with overwrites from environment variables.
pub fn load<P: AsRef<Path>>(config_file: P) -> Result<Self, Error> {
Ok(
Figment::from(Serialized::defaults(Configuration::default()))
.merge(Yaml::file(config_file))
.merge(Env::prefixed("RESTATE_").split("__"))
// Override tracing.log with RUST_LOG, if present
.merge(
Env::raw()
.only(&["RUST_LOG"])
.map(|_| "observability.log.filter".into()),
)
.merge(
Env::raw()
.only(&["HTTP_PROXY"])
.map(|_| "worker.invoker.proxy_uri".into()),
)
.merge(
Env::raw()
.only(&["HTTP_PROXY"])
.map(|_| "meta.proxy_uri".into()),
)
.extract()?,
)
Self::load_with_default(Configuration::default(), Some(config_file.as_ref()))
}

/// Load [`Configuration`] from an optional yaml with overwrites from environment
/// variables based on a default configuration.
pub fn load_with_default(
default_configuration: Configuration,
config_file: Option<&Path>,
) -> Result<Self, Error> {
let figment = Figment::from(Serialized::defaults(default_configuration));

let figment = if let Some(config_file) = config_file {
figment.merge(Yaml::file(config_file))
} else {
figment
};

let figment = figment
.merge(Env::prefixed("RESTATE_").split("__"))
// Override tracing.log with RUST_LOG, if present
.merge(
Env::raw()
.only(&["RUST_LOG"])
.map(|_| "observability.log.filter".into()),
)
.merge(
Env::raw()
.only(&["HTTP_PROXY"])
.map(|_| "worker.invoker.proxy_uri".into()),
)
.merge(
Env::raw()
.only(&["HTTP_PROXY"])
.map(|_| "meta.proxy_uri".into()),
)
.extract()?;

Ok(figment)
}
}