1
0
Fork 0
forked from mirror/grapevine

Move observability config to separate config section

This renames:

allow_prometheus -> observability.metrics.enable
allow_jaeger -> observability.traces.enable
tracing_flame -> observability.flame.enable
log -> observability.logs.filter
log_colors -> observability.logs.colors
log_format -> observability.logs.format

New config values in these sections will follow.
This commit is contained in:
Lambda 2024-06-07 10:03:06 +00:00 committed by Charles Hall
parent 8a30817930
commit 98d49554ce
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
3 changed files with 68 additions and 22 deletions

View file

@ -58,23 +58,13 @@ pub(crate) struct Config {
pub(crate) allow_unstable_room_versions: bool,
#[serde(default = "default_default_room_version")]
pub(crate) default_room_version: RoomVersionId,
#[serde(default = "false_fn")]
pub(crate) allow_jaeger: bool,
#[serde(default = "false_fn")]
pub(crate) allow_prometheus: bool,
#[serde(default = "false_fn")]
pub(crate) tracing_flame: bool,
#[serde(default)]
pub(crate) proxy: ProxyConfig,
pub(crate) jwt_secret: Option<String>,
#[serde(default = "default_trusted_servers")]
pub(crate) trusted_servers: Vec<OwnedServerName>,
#[serde(default = "default_log")]
pub(crate) log: EnvFilterClone,
#[serde(default = "true_fn")]
pub(crate) log_colors: bool,
#[serde(default)]
pub(crate) log_format: LogFormat,
pub(crate) observability: ObservabilityConfig,
#[serde(default)]
pub(crate) turn: TurnConfig,
@ -184,6 +174,55 @@ pub(crate) struct DatabaseConfig {
pub(crate) rocksdb_max_open_files: i32,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(default)]
pub(crate) struct MetricsConfig {
pub(crate) enable: bool,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(default)]
pub(crate) struct OtelTraceConfig {
pub(crate) enable: bool,
}
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(default)]
pub(crate) struct FlameConfig {
pub(crate) enable: bool,
}
#[derive(Debug, Deserialize)]
#[serde(default)]
pub(crate) struct LogConfig {
pub(crate) filter: EnvFilterClone,
pub(crate) colors: bool,
pub(crate) format: LogFormat,
}
impl Default for LogConfig {
fn default() -> Self {
Self {
filter: default_log(),
colors: true,
format: LogFormat::default(),
}
}
}
#[derive(Debug, Default, Deserialize)]
#[serde(default)]
pub(crate) struct ObservabilityConfig {
/// Prometheus metrics
pub(crate) metrics: MetricsConfig,
/// OpenTelemetry traces
pub(crate) traces: OtelTraceConfig,
/// Folded inferno stack traces
pub(crate) flame: FlameConfig,
/// Logging to stdout
pub(crate) logs: LogConfig,
}
fn false_fn() -> bool {
false
}

View file

@ -442,7 +442,7 @@ fn routes(config: &Config) -> Router {
.put(c2s::send_state_event_for_empty_key_route),
);
let router = if config.allow_prometheus {
let router = if config.observability.metrics.enable {
router.route(
"/metrics",
get(|| async { observability::METRICS.export() }),

View file

@ -87,7 +87,9 @@ pub(crate) enum FoundIn {
/// Initialize observability
pub(crate) fn init(config: &Config) -> Result<Guard, error::Observability> {
let jaeger_layer = config
.allow_jaeger
.observability
.traces
.enable
.then(|| {
opentelemetry::global::set_text_map_propagator(
opentelemetry_jaeger_propagator::Propagator::new(),
@ -102,36 +104,41 @@ pub(crate) fn init(config: &Config) -> Result<Guard, error::Observability> {
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
Ok::<_, error::Observability>(
telemetry.with_filter(EnvFilter::from(&config.log)),
)
Ok::<_, error::Observability>(telemetry.with_filter(
EnvFilter::from(&config.observability.logs.filter),
))
})
.transpose()?;
let (flame_layer, flame_guard) = config
.tracing_flame
.observability
.flame
.enable
.then(|| {
let (flame_layer, guard) =
FlameLayer::with_file("./tracing.folded")?;
let flame_layer = flame_layer.with_empty_samples(false);
Ok::<_, error::Observability>((
flame_layer.with_filter(EnvFilter::from(&config.log)),
flame_layer.with_filter(EnvFilter::from(
&config.observability.logs.filter,
)),
guard,
))
})
.transpose()?
.unzip();
let fmt_layer =
tracing_subscriber::fmt::Layer::new().with_ansi(config.log_colors);
let fmt_layer = match config.log_format {
let fmt_layer = tracing_subscriber::fmt::Layer::new()
.with_ansi(config.observability.logs.colors);
let fmt_layer = match config.observability.logs.format {
LogFormat::Pretty => fmt_layer.pretty().boxed(),
LogFormat::Full => fmt_layer.boxed(),
LogFormat::Compact => fmt_layer.compact().boxed(),
LogFormat::Json => fmt_layer.json().boxed(),
};
let fmt_layer = fmt_layer.with_filter(EnvFilter::from(&config.log));
let fmt_layer = fmt_layer
.with_filter(EnvFilter::from(&config.observability.logs.filter));
let subscriber = Registry::default()
.with(jaeger_layer)