Skip to content

Commit

Permalink
Update docs and modify default files
Browse files Browse the repository at this point in the history
  • Loading branch information
devkelley committed Jan 3, 2024
1 parent 09563a7 commit 9881694
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ cargo test
## Configuration Setup
The service configuration is defined in [.agemo/config](.agemo/config/). The default configuration
The service configuration is defined in [config](config/). The default configuration
files will allow a user to run the service without any modification. Please read
[config_overrides](./docs/config-overrides.md) for more information on how to modify the service's
configuration.
Expand Down
6 changes: 3 additions & 3 deletions common/src/config_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use serde::Deserialize;
pub const YAML_EXT: &str = "yaml";

const CONFIG_DIR: &str = "config";
const DEFAULT_FILE_STEM: &str = "default";
const DEFAULT: &str = "default";
const DOT_AGEMO_DIR: &str = ".agemo";
const AGEMO_HOME: &str = "AGEMO_HOME";

const DEFAULT_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/config");
const DEFAULT_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/../config");

/// Read config from layered configuration files.
/// Searches for `{config_file_name}.default.{config_file_ext}` as the base configuration in `$AGEMO_HOME`,
Expand All @@ -36,7 +36,7 @@ where
A: Source + Send + Sync + 'static + Clone,
{
// Get default config.
let default_config_filename = format!("{DEFAULT_FILE_STEM}.{config_file_ext}");
let default_config_filename = format!("{config_file_name}.{DEFAULT}.{config_file_ext}");
let default_config_file = DEFAULT_DIR.get_file(default_config_filename).unwrap();
let default_config_contents_str = default_config_file.contents_utf8().unwrap();

Expand Down
18 changes: 0 additions & 18 deletions common/config/default.yaml → config/constants.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,3 @@ pub_sub_reference: "pubsub.v1.pubsub.proto"

# Retry interval for connections.
retry_interval_secs: 5

###

#
# Pub Sub Service Settings
#

### Standalone Settings

# The IP address and port number that the Pub Sub Service listens on for requests.
# Example: "0.0.0.0:50051"
pub_sub_authority: "0.0.0.0:50051"

# The URI of the messaging service used to facilitate publish and subscribe functionality.
# Example: "mqtt://0.0.0.0:1883"
messaging_uri: "mqtt://0.0.0.0:1883"

###
17 changes: 17 additions & 0 deletions config/pub_sub_service_settings.default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
###

#
# Pub Sub Service Settings
#

### Standalone Settings

# The IP address and port number that the Pub Sub Service listens on for requests.
# Example: "0.0.0.0:50051"
pub_sub_authority: "0.0.0.0:50051"

# The URI of the messaging service used to facilitate publish and subscribe functionality.
# Example: "mqtt://0.0.0.0:1883"
messaging_uri: "mqtt://0.0.0.0:1883"

###
28 changes: 19 additions & 9 deletions docs/config-overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@

The pub sub service supports configuration overrides that enable users to override the default
settings and provide custom configuration. This is achieved with configuration layering. Default
configuration files are defined in `.agemo/config` at the root of the project, and this is often
suitable for basic scenarios or getting started quickly. The service relies on the environment
variable `$AGEMO_HOME` to find the default configuration files. This variable is set by default to
point to `{path_to_project_root}/.agemo` when running the service with `cargo run`. The default
configuration files are defined in `config` at the root of the project, and this is often
suitable for basic scenarios or getting started quickly. The service includes the default
configuration files at build time. The service relies on the environment variable `$AGEMO_HOME` to
find any override configuration files. This variable is set by default to point to
`{path_to_project_root}/.agemo` when running the service with `cargo run`. Template configuration
files to use to override can be found under [config\template](../config/template/). The default
configuration files can be overridden at runtime using custom values. When loading configuration,
the service will probe for and unify config in the following order, with values near the end of the
list taking higher precedence:

- The default config
- A config file in the working directory of the executable (for example, the directory you were in
when you ran the `cargo run` command)
- `$AGEMO_HOME/config/{config_name}.yaml`. If you have not set a `$AGEMO_HOME` directory or are
not running the service with `cargo run`, this defaults to:
- Unix: `$HOME/.agemo/config/{config_name}.yaml`
- Windows: `%USERPROFILE%\.agemo\config\{config_name}.yaml` (note that Windows support is not
guaranteed by Agemo)
- Command line arguments.

Because the config is layered, the overrides can be partially defined and only specify the
top-level configuration fields that should be overridden. Anything not specified in an override
file will use the default value.

Samples handles configuration in the same way, except it utilizes the `.agemo-samples` directory
and the `$AGEMO_SAMPLES_HOME` env variable to point to that directory.
Samples handles configuration in the same way, except it utilizes the `$AGEMO_SAMPLES_HOME` env
variable to point to the `.agemo-samples` directory at the project root.

## Command Line Arguments

The service leverages [clap (command line argument parser)](https://github.com/clap-rs/clap) to
override individual configuration values through command line arguments when starting the service.
To see the list of possible parameters, run:

```shell
cargo run -p pub-sub-service -- --help
```
2 changes: 1 addition & 1 deletion pub-sub-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ service and directly communicate.
file does not already exist. From the enlistment root, run:

```shell
cp ./.agemo/config/template/pub_sub_service_settings.yaml ./.agemo/config/
cp ./config/template/pub_sub_service_settings.yaml ./.agemo/config/
```

2. Uncomment and set the following values:
Expand Down

0 comments on commit 9881694

Please sign in to comment.