Skip to content

Commit

Permalink
fix: Health check config is missing a custom field (#246)
Browse files Browse the repository at this point in the history
Similar to the middleware and initializer configs, we want to allow the
consumer to access custom config options for their custom health checks.

This PR adds the `custom` field to the health check config.

Closes #245
  • Loading branch information
spencewenski authored Jun 23, 2024
1 parent d4014a5 commit 580cf30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/config/health_check/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::app::context::AppContext;
use crate::config::app_config::CustomConfig;
use crate::util::serde_util::default_true;
use config::{FileFormat, FileSourceString};
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
use validator::Validate;

pub fn default_config() -> config::File<FileSourceString, FileFormat> {
Expand All @@ -18,6 +20,33 @@ pub struct HealthCheck {
pub database: HealthCheckConfig<()>,
#[cfg(feature = "sidekiq")]
pub sidekiq: HealthCheckConfig<()>,
/// Allows providing configs for custom health checks. Any configs that aren't pre-defined above
/// will be collected here.
///
/// # Examples
///
/// ```toml
/// [health-check.foo]
/// enable = true
/// x = "y"
/// ```
///
/// This will be parsed as:
/// ```raw
/// HealthCheck#custom: {
/// "foo": {
/// HealthCheckConfig#common: {
/// enable: true,
/// priority: 10
/// },
/// HealthCheckConfig<CustomConfig>#custom: {
/// "x": "y"
/// }
/// }
/// }
/// ```
#[serde(flatten)]
pub custom: BTreeMap<String, HealthCheckConfig<CustomConfig>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
4 changes: 1 addition & 3 deletions src/config/service/http/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ pub struct Initializer {
/// priority: 10
/// },
/// InitializerConfig<CustomConfig>#custom: {
/// config: {
/// "x": "y"
/// }
/// "x": "y"
/// }
/// }
/// }
Expand Down
4 changes: 1 addition & 3 deletions src/config/service/http/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ pub struct Middleware {
/// priority: 10
/// },
/// MiddlewareConfig<CustomConfig>#custom: {
/// config: {
/// "x": "y"
/// }
/// "x": "y"
/// }
/// }
/// }
Expand Down

0 comments on commit 580cf30

Please sign in to comment.