Skip to content

Commit

Permalink
feat: add Metrics and Tracing to Config (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi committed May 16, 2023
1 parent 8a3dc7f commit 8edbbf7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/config/dfdaemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::config::{
};
use serde::Deserialize;
use std::fs;
use std::net::{Ipv4Addr, SocketAddr};
use std::path::PathBuf;
use tracing::info;
use validator::Validate;
Expand Down Expand Up @@ -67,6 +68,11 @@ pub fn default_dfdaemon_lock_path() -> PathBuf {
default_lock_dir().join("dfdaemon.lock")
}

// default_dfdaemon_tracing_addr is the default address to report tracing log.
pub fn default_dfdaemon_tracing_addr() -> SocketAddr {
SocketAddr::from((Ipv4Addr::LOCALHOST, 14268))
}

// Error is the error for Config.
#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand All @@ -77,6 +83,35 @@ pub enum Error {
YAML(#[from] serde_yaml::Error),
}

// Tracing is the tracing configuration for dfdaemon.
#[derive(Debug, Clone, Validate, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Tracing {
// enable indicates whether enable tracing.
pub enable: bool,

// addr is the address to report tracing log.
pub addr: SocketAddr,
}

// Tracing implements default value for Tracing.
impl Default for Tracing {
fn default() -> Self {
Tracing {
enable: false,
addr: default_dfdaemon_tracing_addr(),
}
}
}

// Metrics is the metrics configuration for dfdaemon.
#[derive(Debug, Clone, Default, Validate, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct Metrics {
// enable indicates whether enable metrics.
pub enable: bool,
}

// Config is the configuration for dfdaemon.
#[derive(Debug, Clone, Validate, Deserialize)]
#[serde(default, rename_all = "camelCase")]
Expand All @@ -95,6 +130,12 @@ pub struct Config {

// lock_path is the file lock path for dfdaemon service.
pub lock_dir: PathBuf,

// metrics is the metrics configuration for dfdaemon.
pub metrics: Metrics,

// tracing is the tracing configuration for dfdaemon.
pub tracing: Tracing,
}

// Default implements default value for Config.
Expand All @@ -106,6 +147,8 @@ impl Default for Config {
cache_dir: default_dfdaemon_cache_dir(),
root_dir: default_root_dir(),
lock_dir: default_lock_dir(),
metrics: Metrics::default(),
tracing: Tracing::default(),
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/tracing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2023 The Dragonfly Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

0 comments on commit 8edbbf7

Please sign in to comment.