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

feat(subscriber): resource instrumentation #77

Merged
merged 17 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ members = [
"console-subscriber",
"console-api"
]
resolver = "2"
resolver = "2"

[patch.crates-io]
tokio = { git = 'https://github.com/zaharidichev/tokio', branch = 'zd/instrument-sleep' }
4 changes: 4 additions & 0 deletions console-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ fn main() -> Result<(), Box<dyn Error>> {
"../proto/trace.proto",
"../proto/common.proto",
"../proto/tasks.proto",
"../proto/instrument.proto",
"../proto/resources.proto",
"../proto/resource_ops.proto",
"../proto/async_ops.proto",
];
let dirs = &["../proto"];

Expand Down
1 change: 1 addition & 0 deletions console-api/src/async_ops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tonic::include_proto!("rs.tokio.console.async_ops");
21 changes: 12 additions & 9 deletions console-api/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,11 @@ impl<'a> From<&'a tracing_core::Metadata<'a>> for Metadata {
metadata::Kind::Event
};

let location = Location {
file: meta.file().map(String::from),
module_path: meta.module_path().map(String::from),
line: meta.line(),
column: None, // tracing doesn't support columns yet
};

let field_names = meta.fields().iter().map(|f| f.name().to_string()).collect();

Metadata {
name: meta.name().to_string(),
target: meta.target().to_string(),
location: Some(location),
location: Some(meta.into()),
kind: kind as i32,
level: metadata::Level::from(*meta.level()) as i32,
field_names,
Expand All @@ -53,6 +45,17 @@ impl<'a> From<&'a tracing_core::Metadata<'a>> for Metadata {
}
}

impl<'a> From<&'a tracing_core::Metadata<'a>> for Location {
fn from(meta: &'a tracing_core::Metadata<'a>) -> Self {
Location {
file: meta.file().map(String::from),
module_path: meta.module_path().map(String::from),
line: meta.line(),
column: None, // tracing doesn't support columns yet
}
}
}

impl<'a> From<&'a std::panic::Location<'a>> for Location {
fn from(loc: &'a std::panic::Location<'a>) -> Self {
Location {
Expand Down
1 change: 1 addition & 0 deletions console-api/src/instrument.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tonic::include_proto!("rs.tokio.console.instrument");
4 changes: 4 additions & 0 deletions console-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
pub mod async_ops;
mod common;
pub mod instrument;
pub mod resource_ops;
pub mod resources;
pub mod tasks;
pub mod trace;
pub use common::*;
1 change: 1 addition & 0 deletions console-api/src/resource_ops.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tonic::include_proto!("rs.tokio.console.resource_ops");
1 change: 1 addition & 0 deletions console-api/src/resources.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tonic::include_proto!("rs.tokio.console.resources");
1 change: 1 addition & 0 deletions console-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2018"
tokio = { version = "^1.7", features = ["sync", "time", "macros", "tracing"]}
tokio-stream = "0.1"
tonic = { version = "0.4", features = ["transport"] }
thread_local = "1.1.3"
console-api = { path = "../console-api", features = ["transport"]}
tracing-core = "0.1.18"
tracing = "0.1.26"
Expand Down
10 changes: 5 additions & 5 deletions console-subscriber/examples/dump.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use console_api::tasks::{tasks_client::TasksClient, TasksRequest};
use console_api::instrument::{instrument_client::InstrumentClient, InstrumentRequest};
use futures::stream::StreamExt;

#[tokio::main]
Expand All @@ -11,16 +11,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
});

eprintln!("CONNECTING: {}", target);
let mut client = TasksClient::connect(target).await?;
let mut client = InstrumentClient::connect(target).await?;

let request = tonic::Request::new(TasksRequest {});
let mut stream = client.watch_tasks(request).await?.into_inner();
let request = tonic::Request::new(InstrumentRequest {});
let mut stream = client.watch_updates(request).await?.into_inner();

let mut i: usize = 0;
while let Some(update) = stream.next().await {
match update {
Ok(update) => {
eprintln!("UPDATE {}: {:#?}\n", i, update);
println!("UPDATE {}: {:#?}\n", i, update);
hawkw marked this conversation as resolved.
Show resolved Hide resolved
i += 1;
}
Err(e) => {
Expand Down
Loading