use super::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MonitoringConfig {
#[serde(default)]
pub metrics: MetricsConfig,
#[serde(default)]
pub tracing: TracingConfig,
#[serde(default)]
pub health: HealthConfig,
}
#[allow(dead_code)]
impl MonitoringConfig {
pub fn merge(mut self, other: Self) -> Self {
self.metrics = self.metrics.merge(other.metrics);
self.tracing = self.tracing.merge(other.tracing);
self.health = self.health.merge(other.health);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricsConfig {
#[serde(default = "default_true")]
pub enabled: bool,
#[serde(default = "default_metrics_port")]
pub port: u16,
#[serde(default = "default_metrics_path")]
pub path: String,
}
impl Default for MetricsConfig {
fn default() -> Self {
Self {
enabled: true,
port: default_metrics_port(),
path: default_metrics_path(),
}
}
}
#[allow(dead_code)]
impl MetricsConfig {
pub fn merge(mut self, other: Self) -> Self {
if !other.enabled {
self.enabled = other.enabled;
}
if other.port != default_metrics_port() {
self.port = other.port;
}
if other.path != default_metrics_path() {
self.path = other.path;
}
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TracingConfig {
#[serde(default)]
pub enabled: bool,
pub endpoint: Option<String>,
#[serde(default = "default_service_name")]
pub service_name: String,
}
impl Default for TracingConfig {
fn default() -> Self {
Self {
enabled: false,
endpoint: None,
service_name: default_service_name(),
}
}
}
#[allow(dead_code)]
impl TracingConfig {
pub fn merge(mut self, other: Self) -> Self {
if other.enabled {
self.enabled = other.enabled;
}
if other.endpoint.is_some() {
self.endpoint = other.endpoint;
}
if other.service_name != default_service_name() {
self.service_name = other.service_name;
}
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthConfig {
#[serde(default = "default_health_path")]
pub path: String,
#[serde(default = "default_true")]
pub detailed: bool,
}
impl Default for HealthConfig {
fn default() -> Self {
Self {
path: default_health_path(),
detailed: true,
}
}
}
#[allow(dead_code)]
impl HealthConfig {
pub fn merge(mut self, other: Self) -> Self {
if other.path != default_health_path() {
self.path = other.path;
}
if !other.detailed {
self.detailed = other.detailed;
}
self
}
}
fn default_true() -> bool {
true
}