Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add json formatting support #745

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

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

24 changes: 17 additions & 7 deletions control-plane/agents/src/bin/core/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{net::SocketAddr, num::ParseIntError};
use utils::{version_info_str, DEFAULT_GRPC_SERVER_ADDR, ETCD_MAX_PAGE_LIMIT};

use stor_port::HostAccessControl;
use utils::tracing_telemetry::{trace::TracerProvider, KeyValue};
use utils::tracing_telemetry::{trace::TracerProvider, FmtLayer, FmtStyle, KeyValue};

/// The Cli arguments for this binary.
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -114,6 +114,14 @@ pub(crate) struct CliArgs {
/// Etcd Pagination Limit.
#[clap(long, default_value = ETCD_MAX_PAGE_LIMIT)]
pub(crate) etcd_page_limit: u32,

/// Formatting style to be used while logging.
#[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)]
fmt_style: FmtStyle,

/// Use ANSI colors for the logs.
#[clap(long)]
ansi_colors: bool,
}
impl CliArgs {
fn args() -> Self {
Expand Down Expand Up @@ -156,12 +164,14 @@ async fn main() -> anyhow::Result<()> {
let cli_args = CliArgs::args();
utils::print_package_info!();
println!("Using options: {cli_args:?}");
utils::tracing_telemetry::init_tracing_with_eventing(
"agent-core",
cli_args.tracing_tags.clone(),
cli_args.jaeger.clone(),
cli_args.events_url.clone(),
);
utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(FmtLayer::Stdout)
.with_style(cli_args.fmt_style)
.with_colours(cli_args.ansi_colors)
.with_jaeger(cli_args.jaeger.clone())
.with_events_url(cli_args.events_url.clone())
.with_tracing_tags(cli_args.tracing_tags.clone())
.init("agent-core");
server(cli_args).await
}

Expand Down
28 changes: 20 additions & 8 deletions control-plane/agents/src/bin/ha/cluster/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use once_cell::sync::OnceCell;
use std::net::SocketAddr;
use tracing::info;
use utils::{
package_description, tracing_telemetry::KeyValue, version_info_str,
DEFAULT_CLUSTER_AGENT_SERVER_ADDR, DEFAULT_GRPC_CLIENT_ADDR,
package_description,
tracing_telemetry::{FmtLayer, FmtStyle, KeyValue},
version_info_str, DEFAULT_CLUSTER_AGENT_SERVER_ADDR, DEFAULT_GRPC_CLIENT_ADDR,
};

mod etcd;
mod nodes;
mod server;
Expand Down Expand Up @@ -48,6 +50,14 @@ struct Cli {
/// Events message-bus endpoint url.
#[clap(long, short)]
events_url: Option<url::Url>,

/// Formatting style to be used while logging.
#[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)]
fmt_style: FmtStyle,

/// If set, configures the output to be in ansi color format.
#[clap(long)]
ansi_colors: bool,
}

impl Cli {
Expand All @@ -67,12 +77,14 @@ pub(crate) fn core_grpc<'a>() -> &'a CoreClient {
}

fn initialize_tracing(args: &Cli) {
utils::tracing_telemetry::init_tracing_with_eventing(
"agent-ha-cluster",
args.tracing_tags.clone(),
args.jaeger.clone(),
args.events_url.clone(),
)
utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(FmtLayer::Stdout)
.with_style(args.fmt_style)
.with_colours(args.ansi_colors)
.with_jaeger(args.jaeger.clone())
.with_events_url(args.events_url.clone())
.with_tracing_tags(args.tracing_tags.clone())
.init("agent-ha-cluster");
}

#[tokio::main]
Expand Down
23 changes: 17 additions & 6 deletions control-plane/agents/src/bin/ha/node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod server;

use detector::PathFailureDetector;
use server::NodeAgentApiServer;
use utils::tracing_telemetry::{FmtLayer, FmtStyle};

/// TODO
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -77,6 +78,14 @@ struct Cli {
/// Events message-bus endpoint url.
#[clap(long, short)]
events_url: Option<url::Url>,

/// Formatting style to be used while logging.
#[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)]
fmt_style: FmtStyle,

/// Enable ansi colors for logs.
#[clap(long)]
ansi_colors: bool,
}

static CLUSTER_AGENT_CLIENT: OnceCell<ClusterAgentClient> = OnceCell::new();
Expand Down Expand Up @@ -107,12 +116,14 @@ async fn main() -> anyhow::Result<()> {

utils::print_package_info!();

utils::tracing_telemetry::init_tracing_with_eventing(
"agent-ha-node",
cli_args.tracing_tags.clone(),
cli_args.jaeger.clone(),
cli_args.events_url.clone(),
);
utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(FmtLayer::Stdout)
.with_style(cli_args.fmt_style)
.with_colours(cli_args.ansi_colors)
.with_jaeger(cli_args.jaeger.clone())
.with_events_url(cli_args.events_url.clone())
.with_tracing_tags(cli_args.tracing_tags.clone())
.init("agent-ha-node");

CLUSTER_AGENT_CLIENT
.set(ClusterAgentClient::new(cli_args.cluster_agent.clone(), None).await)
Expand Down
38 changes: 30 additions & 8 deletions control-plane/csi-driver/src/bin/controller/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use client::{ApiClientError, RestApiClient};
use config::CsiControllerConfig;

mod client;
mod config;
mod controller;
Expand All @@ -9,7 +6,10 @@ mod pvwatcher;
mod server;

use clap::{Arg, ArgMatches};
use client::{ApiClientError, RestApiClient};
use config::CsiControllerConfig;
use tracing::info;
use utils::tracing_telemetry::{FmtLayer, FmtStyle};

const CSI_SOCKET: &str = "/var/tmp/csi.sock";
const CONCURRENCY_LIMIT: usize = 10;
Expand Down Expand Up @@ -103,6 +103,18 @@ async fn main() -> anyhow::Result<()> {
An orphan volume is a volume with no corresponding PV",
)
)
.arg(
Arg::new("fmt-style")
.long("fmt-style")
.default_value(FmtStyle::Pretty.as_ref())
.help("Formatting style to be used while logging")
)
.arg(
Arg::new("ansi-colors")
.long("ansi-colors")
.action(clap::ArgAction::SetTrue)
.help("Enable ansi color for logs")
)
.get_matches();
abhilashshetty04 marked this conversation as resolved.
Show resolved Hide resolved

utils::print_package_info!();
Expand All @@ -111,11 +123,21 @@ async fn main() -> anyhow::Result<()> {
utils::raw_version_str(),
env!("CARGO_PKG_VERSION"),
);
utils::tracing_telemetry::init_tracing(
"csi-controller",
tags,
args.get_one::<String>("jaeger").cloned(),
);
let fmt_style = args.get_one::<String>("fmt-style").unwrap().as_ref();
let fmt_style = match fmt_style {
"json" => FmtStyle::Json,
"compact" => FmtStyle::Compact,
_ => FmtStyle::Pretty,
};
let ansi_colors = args.get_flag("ansi-colors");
utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(FmtLayer::Stdout)
.with_style(fmt_style)
.with_colours(ansi_colors)
.with_jaeger(args.get_one::<String>("jaeger").cloned())
.with_tracing_tags(tags)
.init("csi-controller");

let orphan_period = args
.get_one::<String>("orphan-vol-gc-period")
.map(|p| p.parse::<humantime::Duration>())
Expand Down
37 changes: 34 additions & 3 deletions control-plane/csi-driver/src/bin/node/main_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,20 @@ pub(super) async fn main() -> anyhow::Result<()> {
.help(
"The node selector label which this plugin will report as part of its topology.\n\
Example:\n --node-selector key=value --node-selector key2=value2",
),
)
,
)
.arg(
Arg::new("fmt-style")
.long("fmt-style")
.default_value(FmtStyle::Pretty.as_ref())
.help("Formatting style to be used while logging")
)
.arg(
Arg::new("ansi-colors")
.long("ansi-colors")
.action(clap::ArgAction::SetTrue)
.help("Enable ANSI color for logs")
)
.subcommand(
clap::Command::new("fs-freeze")
Expand All @@ -211,14 +224,19 @@ pub(super) async fn main() -> anyhow::Result<()> {
)
)
.get_matches();
let tags = utils::tracing_telemetry::default_tracing_tags(
utils::raw_version_str(),
env!("CARGO_PKG_VERSION"),
);

// Handle fs-freeze and fs-unfreeze commands.
if let Some(cmd) = matches.subcommand() {
utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(FmtLayer::Stderr)
.with_style(FmtStyle::Compact)
.with_colours(false)
.init();
.with_tracing_tags(tags)
.init("csi-node");
match cmd {
("fs-freeze", arg_matches) => {
let volume_id = arg_matches.get_one::<String>("volume-id").unwrap();
Expand All @@ -242,7 +260,20 @@ pub(super) async fn main() -> anyhow::Result<()> {
utils::raw_version_str(),
env!("CARGO_PKG_VERSION"),
);
utils::tracing_telemetry::init_tracing("csi-node", tags, None);

let fmt_style = matches.get_one::<String>("fmt-style").unwrap().as_ref();
let fmt_style = match fmt_style {
"json" => FmtStyle::Json,
"compact" => FmtStyle::Compact,
_ => FmtStyle::Pretty,
};
let colors = matches.get_flag("ansi-colors");
utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(FmtLayer::Stdout)
.with_style(fmt_style)
.with_colours(colors)
.with_tracing_tags(tags.clone())
.init("csi-node");

// Validate presence of nvme_tcp kernel module and set nvme_core parameters.
if let Err(error) = crate::dev::nvmf::check_nvme_tcp_module() {
Expand Down
20 changes: 11 additions & 9 deletions control-plane/plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern crate lazy_static;

use operations::Label;
use resources::LabelResources;
use std::fmt::Debug;
use utils::tracing_telemetry::{FmtLayer, FmtStyle};

use crate::{
operations::{
Expand Down Expand Up @@ -60,17 +62,17 @@ impl CliArgs {
utils::tracing_telemetry::default_tracing_tags(git_version, env!("CARGO_PKG_VERSION"));

let fmt_layer = match std::env::var("RUST_LOG") {
Ok(_) => utils::tracing_telemetry::FmtLayer::Stderr,
Err(_) => utils::tracing_telemetry::FmtLayer::None,
Ok(_) => FmtLayer::Stderr,
Err(_) => FmtLayer::None,
};

utils::tracing_telemetry::init_tracing_ext(
env!("CARGO_PKG_NAME"),
tags,
self.jaeger.as_ref(),
fmt_layer,
None,
);
utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(fmt_layer)
.with_style(FmtStyle::Pretty)
.with_colours(false)
.with_jaeger(self.jaeger.clone())
.with_tracing_tags(tags)
.init(env!("CARGO_PKG_NAME"));

TracingFlusher {}
}
Expand Down
23 changes: 17 additions & 6 deletions control-plane/rest/service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ pub(crate) struct CliArgs {
/// The value 0 means the number of available physical CPUs is used.
#[clap(long, short, default_value = utils::DEFAULT_REST_MAX_WORKER_THREADS)]
max_workers: usize,

/// Formatting style to be used while logging.
#[clap(default_value = FmtStyle::Pretty.as_ref(), short, long)]
fmt_style: FmtStyle,

/// Use ANSI colors for logs.
#[clap(long)]
ansi_colors: bool,
}
impl CliArgs {
fn args() -> Self {
Expand Down Expand Up @@ -105,7 +113,7 @@ use clap::Parser;
use grpc::{client::CoreClient, operations::jsongrpc::client::JsonGrpcClient};
use http::Uri;
use stor_port::transport_api::{RequestMinTimeout, TimeoutOptions};
use utils::tracing_telemetry::KeyValue;
use utils::tracing_telemetry::{FmtLayer, FmtStyle, KeyValue};

/// Extension trait for actix-web applications.
pub trait OpenApiExt<T> {
Expand Down Expand Up @@ -205,11 +213,14 @@ async fn main() -> anyhow::Result<()> {
utils::print_package_info!();
let cli_args = CliArgs::args();
println!("Using options: {:?}", &cli_args);
utils::tracing_telemetry::init_tracing(
"rest-server",
cli_args.tracing_tags.clone(),
cli_args.jaeger.clone(),
);

utils::tracing_telemetry::TracingTelemetry::builder()
.with_writer(FmtLayer::Stdout)
.with_style(cli_args.fmt_style)
.with_colours(cli_args.ansi_colors)
.with_jaeger(cli_args.jaeger.clone())
.with_tracing_tags(cli_args.tracing_tags.clone())
.init("rest-server");

let app = move || {
App::new()
Expand Down
Loading
Loading