Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JackTan25 committed Nov 26, 2023
2 parents acf8e69 + a0cb2f6 commit 55bf6c4
Show file tree
Hide file tree
Showing 45 changed files with 1,039 additions and 221 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/binaries/meta/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::BTreeMap;
use std::env;
use std::ops::Deref;
use std::sync::Arc;
Expand Down Expand Up @@ -78,7 +79,12 @@ pub async fn entry(conf: Config) -> anyhow::Result<()> {
"databend-meta-{}@{}",
conf.raft_config.id, conf.raft_config.cluster_name
);
let _guards = init_logging(&app_name_shuffle, &conf.log);
let mut log_labels = BTreeMap::new();
log_labels.insert(
"cluster_name".to_string(),
conf.raft_config.cluster_name.clone(),
);
let _guards = init_logging(&app_name_shuffle, &conf.log, log_labels);

info!("Databend Meta version: {}", METASRV_COMMIT_VERSION.as_str());
info!(
Expand Down Expand Up @@ -139,6 +145,7 @@ pub async fn entry(conf: Config) -> anyhow::Result<()> {
println!("Log:");
println!(" File: {}", conf.log.file);
println!(" Stderr: {}", conf.log.stderr);
println!(" OTLP: {}", conf.log.otlp);
println!(" Tracing: {}", conf.log.tracing);
println!("Id: {}", conf.raft_config.id);
println!("Raft Cluster Name: {}", conf.raft_config.cluster_name);
Expand Down
16 changes: 6 additions & 10 deletions src/binaries/metabench/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![allow(clippy::uninlined_format_args)]

use std::collections::BTreeMap;
use std::fmt::Debug;
use std::fmt::Display;
use std::sync::Arc;
Expand Down Expand Up @@ -44,6 +45,7 @@ use common_meta_types::Operation;
use common_meta_types::TxnRequest;
use common_tracing::init_logging;
use common_tracing::FileConfig;
use common_tracing::OTLPConfig;
use common_tracing::QueryLogConfig;
use common_tracing::StderrConfig;
use common_tracing::TracingConfig;
Expand Down Expand Up @@ -96,18 +98,12 @@ async fn main() {
level: "WARN".to_string(),
format: "text".to_string(),
},
query: QueryLogConfig {
on: false,
dir: "./.databend/logs/query-details".to_string(),
},
tracing: TracingConfig {
on: false,
capture_log_level: "TRACE".to_string(),
otlp_endpoint: "http://127.0.0.1:4317".to_string(),
},
otlp: OTLPConfig::default(),
query: QueryLogConfig::default(),
tracing: TracingConfig::default(),
};

let _guards = init_logging("databend-metabench", &log_config);
let _guards = init_logging("databend-metabench", &log_config, BTreeMap::new());

println!("config: {:?}", config);
if config.grpc_api_address.is_empty() {
Expand Down
5 changes: 4 additions & 1 deletion src/binaries/metactl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#![allow(clippy::uninlined_format_args)]

mod grpc;
use common_tracing::OTLPConfig;
use common_tracing::QueryLogConfig;
use common_tracing::TracingConfig;
use grpc::export_meta;

mod snapshot;

use std::collections::BTreeMap;
use std::time::Duration;

use clap::Parser;
Expand Down Expand Up @@ -122,11 +124,12 @@ async fn main() -> anyhow::Result<()> {
format: "text".to_string(),
},
stderr: StderrConfig::default(),
otlp: OTLPConfig::default(),
query: QueryLogConfig::default(),
tracing: TracingConfig::default(),
};

let _guards = init_logging("metactl", &log_config);
let _guards = init_logging("metactl", &log_config, BTreeMap::new());

if config.status {
return show_status(&config).await;
Expand Down
1 change: 1 addition & 0 deletions src/binaries/query/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ pub async fn start_services(conf: &InnerConfig) -> Result<()> {
println!("Logging:");
println!(" file: {}", conf.log.file);
println!(" stderr: {}", conf.log.stderr);
println!(" otlp: {}", conf.log.otlp);
println!(" query: {}", conf.log.query);
println!(" tracing: {}", conf.log.tracing);
println!(
Expand Down
5 changes: 3 additions & 2 deletions src/common/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ humantime = "2.1.0"
log = { workspace = true }
minitrace = { workspace = true }
minitrace-opentelemetry = "0.6"
opentelemetry = { version = "0.20", features = ["trace"] }
opentelemetry-otlp = { version = "0.13", features = ["trace"] }
opentelemetry = { version = "0.20", features = ["trace", "logs"] }
opentelemetry-otlp = { version = "0.13", features = ["trace", "logs"] }
opentelemetry_sdk = { version = "0.20", features = ["trace", "logs", "rt-tokio"] }
serde = { workspace = true }
serde_json = "1"
tonic = { workspace = true }
Expand Down
52 changes: 46 additions & 6 deletions src/common/tracing/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::fmt::Formatter;
pub struct Config {
pub file: FileConfig,
pub stderr: StderrConfig,
pub otlp: OTLPConfig,
pub query: QueryLogConfig,
pub tracing: TracingConfig,
}
Expand All @@ -39,9 +40,15 @@ impl Config {
level: "WARN".to_string(),
format: "text".to_string(),
},
otlp: OTLPConfig {
on: false,
level: "INFO".to_string(),
endpoint: "http://127.0.0.1:4317".to_string(),
},
query: QueryLogConfig {
on: true,
dir: "./.databend/logs/query-details".to_string(),
on: false,
dir: "".to_string(),
otlp_endpoint: "".to_string(),
},
tracing: TracingConfig {
on: false,
Expand Down Expand Up @@ -115,23 +122,56 @@ impl Default for StderrConfig {
}
}

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
pub struct OTLPConfig {
pub on: bool,
pub level: String,
pub endpoint: String,
}

impl Display for OTLPConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"enabled={}, level={}, endpoint={}",
self.on, self.level, self.endpoint
)
}
}

impl Default for OTLPConfig {
fn default() -> Self {
Self {
on: false,
level: "INFO".to_string(),
endpoint: "http://127.0.0.1:4317".to_string(),
}
}
}

#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
pub struct QueryLogConfig {
pub on: bool,
pub dir: String,
pub otlp_endpoint: String,
}

impl Display for QueryLogConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "enabled={}, dir={}", self.on, self.dir)
write!(
f,
"enabled={}, dir={}, otlp_endpoint={}",
self.on, self.dir, self.otlp_endpoint
)
}
}

impl Default for QueryLogConfig {
fn default() -> Self {
Self {
on: true,
dir: "./.databend/logs/query-details".to_string(),
on: false,
dir: "".to_string(),
otlp_endpoint: "".to_string(),
}
}
}
Expand All @@ -158,7 +198,7 @@ impl Default for TracingConfig {
Self {
on: false,
capture_log_level: "INFO".to_string(),
otlp_endpoint: "http://localhost:4317".to_string(),
otlp_endpoint: "http://127.0.0.1:4317".to_string(),
}
}
}
Loading

0 comments on commit 55bf6c4

Please sign in to comment.