Skip to content

Commit

Permalink
maybe hit filters less for task tracking
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Jul 24, 2020
1 parent 32051a4 commit 3f404bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions linkerd/app/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ serde_json = "1"

[dependencies.tracing-subscriber]
version = "0.2.8"
# we don't need `chrono` time formatting
# we don't need `chrono` time formatting or ANSI colored output
default-features = false
features = ["env-filter", "fmt", "smallvec", "tracing-log", "ansi", "json", "parking_lot"]
features = ["env-filter", "fmt", "smallvec", "tracing-log", "json", "parking_lot"]

[dependencies.tower]
version = "0.3"
Expand Down
42 changes: 29 additions & 13 deletions linkerd/app/core/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use tokio_timer::clock;
use tokio_trace::tasks::{TaskList, TasksLayer};
use tracing::Dispatch;
use tracing_subscriber::{
fmt::{format, Formatter},
fmt::{format, Layer as FmtLayer},
layer::Layered,
prelude::*,
reload, EnvFilter, FmtSubscriber,
reload, EnvFilter,
};

const ENV_LOG_LEVEL: &str = "LINKERD2_PROXY_LOG";
Expand All @@ -15,8 +16,12 @@ const ENV_LOG_FORMAT: &str = "LINKERD2_PROXY_LOG_FORMAT";
const DEFAULT_LOG_LEVEL: &str = "warn,linkerd2_proxy=info";
const DEFAULT_LOG_FORMAT: &str = "PLAIN";

type JsonFormatter = Formatter<format::JsonFields, format::Format<format::Json, Uptime>>;
type PlainFormatter = Formatter<format::DefaultFields, format::Format<format::Full, Uptime>>;
type JsonFormatter = Formatter<format::JsonFields, format::Json>;
type PlainFormatter = Formatter<format::DefaultFields, format::Full>;
type Formatter<F, E> = Layered<
FmtLayer<Layered<TasksLayer<F>, tracing_subscriber::Registry>, F, format::Format<E, Uptime>>,
Layered<TasksLayer<F>, tracing_subscriber::Registry>,
>;

#[derive(Clone)]
pub struct Handle {
Expand Down Expand Up @@ -57,23 +62,34 @@ pub fn with_filter_and_format(

// Set up the subscriber
let start_time = clock::now();
let builder = FmtSubscriber::builder()
.with_timer(Uptime { start_time })
.with_env_filter(filter);
let filter = tracing_subscriber::EnvFilter::new(filter);

let (dispatch, level, tasks) = match format.as_ref().to_uppercase().as_ref() {
"JSON" => {
let (tasks, tasks_layer) = TasksLayer::<format::JsonFields>::new();
let builder = builder.json().with_span_list(true).with_filter_reloading();
let handle = LevelHandle::Json(builder.reload_handle());
let dispatch = Dispatch::new(builder.finish().with(tasks_layer));
let (filter, level) = tracing_subscriber::reload::Layer::new(filter);
let dispatch = tracing_subscriber::registry()
.with(tasks_layer)
.with(
tracing_subscriber::fmt::layer()
.with_timer(Uptime { start_time })
.json()
.with_span_list(true),
)
.with(filter)
.into();
let handle = LevelHandle::Json(level);
(dispatch, handle, tasks)
}
"PLAIN" | _ => {
let (tasks, tasks_layer) = TasksLayer::<format::DefaultFields>::new();
let builder = builder.with_ansi(cfg!(test)).with_filter_reloading();
let handle = LevelHandle::Plain(builder.reload_handle());
let dispatch = Dispatch::new(builder.finish().with(tasks_layer));
let (filter, level) = tracing_subscriber::reload::Layer::new(filter);
let dispatch = tracing_subscriber::registry()
.with(tasks_layer)
.with(tracing_subscriber::fmt::layer().with_timer(Uptime { start_time }))
.with(filter)
.into();
let handle = LevelHandle::Plain(level);
(dispatch, handle, tasks)
}
};
Expand Down

0 comments on commit 3f404bb

Please sign in to comment.